Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/integration' into percep-second-cam
Browse files Browse the repository at this point in the history
  • Loading branch information
qhdwight committed Feb 22, 2024
2 parents 9e1152a + 7b10f30 commit 3be1772
Show file tree
Hide file tree
Showing 17 changed files with 296 additions and 352 deletions.
2 changes: 1 addition & 1 deletion msg/GPSWaypoint.msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
int8 tag_id
float64 latitude_degrees
float64 longitude_degrees
WaypointType type
WaypointType type
8 changes: 5 additions & 3 deletions src/simulator/simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ namespace mrover {
SimulatorNodelet::~SimulatorNodelet() {
mRunThread.join();

ImGui_ImplWGPU_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
if (!mIsHeadless) {
ImGui_ImplWGPU_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
}

for (int i = mDynamicsWorld->getNumConstraints() - 1; i >= 0; --i) {
mDynamicsWorld->removeConstraint(mDynamicsWorld->getConstraint(i));
Expand Down
64 changes: 54 additions & 10 deletions src/teleoperation/backend/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from channels.generic.websocket import JsonWebsocketConsumer
import rospy
import tf2_ros
import cv2
from cv_bridge import CvBridge
from geometry_msgs.msg import Twist
from mrover.msg import (
PDLB,
Expand All @@ -17,12 +19,15 @@
StateMachineStateUpdate,
Throttle,
CalibrationStatus,
Calibrated,
MotorsStatus,
CameraCmd,
Calibrated,
Velocity,
Position,
IK,
)
from mrover.srv import EnableAuton, ChangeCameras, CapturePanorama
from sensor_msgs.msg import NavSatFix, Temperature, RelativeHumidity, Image
from mrover.srv import EnableAuton
from sensor_msgs.msg import NavSatFix, Temperature, RelativeHumidity
from std_msgs.msg import String, Bool
Expand Down Expand Up @@ -88,18 +93,15 @@ def connect(self):
"/sa_humidity_data", RelativeHumidity, self.sa_humidity_data_callback
)

# Services
self.laser_service = rospy.ServiceProxy("enable_mosfet_device", SetBool)
self.calibrate_service = rospy.ServiceProxy("arm_calibrate", Trigger)
self.enable_auton = rospy.ServiceProxy("enable_auton", EnableAuton)

# Services
self.laser_service = rospy.ServiceProxy("enable_arm_laser", SetBool)
self.enable_auton = rospy.ServiceProxy("enable_auton", EnableAuton)
self.change_heater_srv = rospy.ServiceProxy("science_change_heater_auto_shutoff_state", SetBool)
self.calibrate_cache_srv = rospy.ServiceProxy("cache_calibrate", Trigger)
self.cache_enable_limit = rospy.ServiceProxy("cache_enable_limit_switches", SetBool)
self.calibrate_service = rospy.ServiceProxy("arm_calibrate", Trigger)
self.change_cameras_srv = rospy.ServiceProxy("change_cameras", ChangeCameras)
self.capture_panorama_srv: Any = rospy.ServiceProxy("capture_panorama", CapturePanorama)

# ROS Parameters
self.mappings = rospy.get_param("teleop/joystick_mappings")
Expand All @@ -119,6 +121,7 @@ def connect(self):
self.tf_listener = tf2_ros.TransformListener(self.tf_buffer)
self.flight_thread = threading.Thread(target=self.flight_attitude_listener)
self.flight_thread.start()

except rospy.ROSException as e:
rospy.logerr(e)

Expand Down Expand Up @@ -160,6 +163,12 @@ def receive(self, text_data):
self.auton_bearing()
elif message["type"] == "mast_gimbal":
self.mast_gimbal(message)
elif message["type"] == "max_streams":
self.send_res_streams()
elif message["type"] == "sendCameras":
self.change_cameras(msg=message)
elif message["type"] == "center_map":
self.send_center()
elif message["type"] == "enable_limit_switch":
self.limit_switch(message)
elif message["type"] == "center_map":
Expand Down Expand Up @@ -588,10 +597,45 @@ def mast_gimbal(self, msg):
up_down_pwr = msg["throttles"][1] * pwr["up_down_pwr"]
self.mast_gimbal_pub.publish(Throttle(["mast_gimbal_x", "mast_gimbal_y"], [rot_pwr, up_down_pwr]))

def send_center(self):
lat = rospy.get_param("gps_linearization/reference_point_latitude")
long = rospy.get_param("gps_linearization/reference_point_longitude")
self.send(text_data=json.dumps({"type": "center_map", "latitude": lat, "longitude": long}))
def change_cameras(self, msg):
try:
camera_cmd = CameraCmd(msg["device"], msg["resolution"])
rospy.logerr(camera_cmd)
result = self.change_cameras_srv(primary=msg["primary"], camera_cmd=camera_cmd)
rospy.logerr(result)
except rospy.ServiceException as e:
print(f"Service call failed: {e}")

def send_res_streams(self):
res = rospy.get_param("cameras/max_num_resolutions")
streams = rospy.get_param("cameras/max_streams")
self.send(text_data=json.dumps({"type": "max_resolution", "res": res}))
self.send(text_data=json.dumps({"type": "max_streams", "streams": streams}))

def capture_panorama(self) -> None:
try:
response = self.capture_panorama_srv()
image = response.panorama
self.image_callback(image)
except rospy.ServiceException as e:
print(f"Service call failed: {e}")

def image_callback(self, msg):
bridge = CvBridge()
try:
# Convert the image to OpenCV standard format
cv_image = bridge.imgmsg_to_cv2(msg, desired_encoding="passthrough")
except Exception as e:
rospy.logerr("Could not convert image message to OpenCV image: " + str(e))
return

# Save the image to a file (you could change 'png' to 'jpg' or other formats)
image_filename = "panorama.png"
try:
cv2.imwrite(image_filename, cv_image)
rospy.loginfo("Saved image to {}".format(image_filename))
except Exception as e:
rospy.logerr("Could not save image: " + str(e))

def send_center(self):
lat = rospy.get_param("gps_linearization/reference_point_latitude")
Expand Down
3 changes: 3 additions & 0 deletions src/teleoperation/frontend/public/map_marker_drone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 7 additions & 8 deletions src/teleoperation/frontend/src/components/AutonTask.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,12 @@ export default defineComponent({
window.setTimeout(() => {
this.sendMessage({ "type": "center_map" });
}, 250)
},
// interval = setInterval(() => {
// this.sendMessage({ type: 'auton_tfclient' })
// }, 1000)
interval = setInterval(() => {
this.sendMessage({ type: 'auton_tfclient' })
}, 1000)
},
})
</script>

Expand Down Expand Up @@ -212,7 +213,6 @@ export default defineComponent({
}
@keyframes blinkAnimation {
0%,
100% {
background-color: var(--bs-success);
Expand Down Expand Up @@ -282,8 +282,8 @@ h2 {
cursor: pointer;
}
.help:hover~.helpscreen,
.help:hover~.helpimages {
.help:hover ~ .helpscreen,
.help:hover ~ .helpimages {
visibility: visible;
}
Expand Down Expand Up @@ -311,4 +311,3 @@ h2 {
grid-area: data;
}
</style>
>>>>>>> 9720704e91b679513a528bf4bb0e7521bcdaec68
Loading

0 comments on commit 3be1772

Please sign in to comment.