Skip to content

Commit ef0f61c

Browse files
authored
Got Camera Feed Working With Republisher (#93)
* Changed compressed img format to jpeg to align with web video server * Shfited camera feed to compressed image topic * Added a sample image with food on fork * Disaggregated MoveFromMouth text * Formatting
1 parent 1c58979 commit ef0f61c

File tree

7 files changed

+26
-54
lines changed

7 files changed

+26
-54
lines changed
Loading
Loading

feeding_web_app_ros2_test/feeding_web_app_ros2_test/DummyRealSense.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,26 +146,33 @@ def publish_frames(self):
146146
self.num_frames = 0
147147
self.video.set(cv2.CAP_PROP_POS_FRAMES, self.num_frames)
148148

149-
# Publish the RGB Image message
149+
# Configure the RGB Image message
150150
frame_msg = self.bridge.cv2_to_imgmsg(frame, "bgr8")
151151
frame_msg.header.frame_id = "camera_color_optical_frame"
152152
frame_msg.header.stamp = self.get_clock().now().to_msg()
153-
self.image_publisher.publish(frame_msg)
154153

155-
# Publish the RGB CompressedImage message
154+
# Configure the RGB CompressedImage message
156155
compressed_frame_msg = self.bridge.cv2_to_compressed_imgmsg(frame)
157156
compressed_frame_msg.header.frame_id = "camera_color_optical_frame"
158157
compressed_frame_msg.header.stamp = self.get_clock().now().to_msg()
159-
self.compressed_image_publisher.publish(compressed_frame_msg)
158+
compressed_frame_msg.format = (
159+
"jpeg" # web_video_server requires "jpeg" not "jpg"
160+
)
160161

161-
# Publish the depth Image message
162+
# Configure the depth Image message
162163
depth_frame_msg = self.bridge.cv2_to_imgmsg(self.depth_frame, "passthrough")
163164
depth_frame_msg.header.frame_id = "camera_color_optical_frame"
164-
depth_frame_msg.header.stamp = self.get_clock().now().to_msg()
165-
self.aligned_depth_publisher.publish(depth_frame_msg)
165+
depth_frame_msg.header.stamp = (
166+
self.get_clock().now() - rclpy.duration.Duration(seconds=0.15)
167+
).to_msg()
168+
169+
# Configure the Camera Info
170+
self.camera_info_msg.header.stamp = depth_frame_msg.header.stamp
166171

167-
# Publish the Camera Info
168-
self.camera_info_msg.header.stamp = compressed_frame_msg.header.stamp
172+
# Publish all topics
173+
self.image_publisher.publish(frame_msg)
174+
self.compressed_image_publisher.publish(compressed_frame_msg)
175+
self.aligned_depth_publisher.publish(depth_frame_msg)
169176
self.camera_info_publisher.publish(self.camera_info_msg)
170177

171178
rate.sleep()

feedingwebapp/src/Pages/Constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ NON_MOVING_STATES.add(MEAL_STATE.U_PostMeal)
4242
export { NON_MOVING_STATES }
4343

4444
// The names of the ROS topic(s)
45-
export const CAMERA_FEED_TOPIC = '/camera/color/image_raw'
45+
export const CAMERA_FEED_TOPIC = '/local/camera/color/image_raw'
4646
export const FACE_DETECTION_TOPIC = '/face_detection'
4747
export const FACE_DETECTION_TOPIC_MSG = 'ada_feeding_msgs/FaceDetection'
4848
export const FACE_DETECTION_IMG_TOPIC = '/face_detection_img'

feedingwebapp/src/Pages/Home/Home.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function Home(props) {
152152
*/
153153
let currentMealState = MEAL_STATE.R_MovingFromMouthToAbovePlate
154154
let nextMealState = MEAL_STATE.U_BiteSelection
155-
let waitingText = 'Waiting to move above the plate...'
155+
let waitingText = 'Waiting to move from your mouth to above the plate...'
156156
return (
157157
<RobotMotion
158158
debug={props.debug}
@@ -166,7 +166,7 @@ function Home(props) {
166166
case MEAL_STATE.R_MovingFromMouthToRestingPosition: {
167167
let currentMealState = MEAL_STATE.R_MovingFromMouthToRestingPosition
168168
let nextMealState = MEAL_STATE.U_BiteAcquisitionCheck
169-
let waitingText = 'Waiting to move to the resting position...'
169+
let waitingText = 'Waiting to move from your mouth to the resting position...'
170170
return (
171171
<RobotMotion
172172
debug={props.debug}

feedingwebapp/src/Pages/Home/MealStates/BiteSelection.jsx

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@ const BiteSelection = (props) => {
8686
let { actionName, messageType } = ROS_ACTIONS_NAMES[MEAL_STATE.U_BiteSelection]
8787
let segmentFromPointAction = useRef(createROSActionClient(ros.current, actionName, messageType))
8888

89-
/**
90-
* Callback function for when the user indicates that they want to move the
91-
* robot to locate the plate.
92-
*/
93-
const locatePlateClicked = useCallback(() => {
94-
console.log('locatePlateClicked')
95-
setMealState(MEAL_STATE.U_PlateLocator)
96-
}, [setMealState])
97-
9889
/**
9990
* Callback function for when the user indicates that they are done with their
10091
* meal.
@@ -163,6 +154,7 @@ const BiteSelection = (props) => {
163154
setActionStatus({
164155
actionStatus: ROS_ACTION_STATUS_SUCCEED
165156
})
157+
console.log('Got result', response.values)
166158
setActionResult(response.values)
167159
} else {
168160
if (
@@ -336,7 +328,7 @@ const BiteSelection = (props) => {
336328
width: Math.round(REALSENSE_WIDTH * maskScaleFactor),
337329
height: Math.round(REALSENSE_HEIGHT * maskScaleFactor)
338330
}
339-
let imgSrc = `${props.webVideoServerURL}/stream?topic=${CAMERA_FEED_TOPIC}&width=${imgSize.width}&height=${imgSize.height}&quality=20`
331+
let imgSrc = `${props.webVideoServerURL}/stream?topic=${CAMERA_FEED_TOPIC}&width=${imgSize.width}&height=${imgSize.height}&type=ros_compressed`
340332
return (
341333
<View style={{ flexDirection: 'row', justifyContent: 'center', alignItems: 'center', width: '100%', height: '100%' }}>
342334
{actionResult.detected_items.map((detected_item, i) => (
@@ -434,40 +426,14 @@ const BiteSelection = (props) => {
434426
style={{
435427
flex: 3,
436428
flexDirection: 'row',
429+
justifyContent: 'center',
437430
alignItems: 'center',
438431
width: '100%'
439432
}}
440433
>
441-
<View
442-
style={{
443-
flex: 1,
444-
alignItems: 'center',
445-
justifyContent: 'right'
446-
}}
447-
>
448-
<Button
449-
className='doneButton'
450-
style={{ fontSize: textFontSize, marginTop: '0', marginBottom: '0' }}
451-
onClick={locatePlateClicked}
452-
>
453-
🍽️ Locate Plate
454-
</Button>
455-
</View>
456-
<View
457-
style={{
458-
flex: 1,
459-
alignItems: 'center',
460-
justifyContent: 'left'
461-
}}
462-
>
463-
<Button
464-
className='doneButton'
465-
style={{ fontSize: textFontSize, marginTop: '0', marginBottom: '0' }}
466-
onClick={doneEatingClicked}
467-
>
468-
✅ Done Eating
469-
</Button>
470-
</View>
434+
<Button className='doneButton' style={{ fontSize: textFontSize, marginTop: '0', marginBottom: '0' }} onClick={doneEatingClicked}>
435+
✅ Done Eating
436+
</Button>
471437
</View>
472438
{/**
473439
* Below the buttons, one half of the screen will present the video feed.
@@ -598,7 +564,6 @@ const BiteSelection = (props) => {
598564
</>
599565
)
600566
}, [
601-
locatePlateClicked,
602567
doneEatingClicked,
603568
dimension,
604569
margin,

feedingwebapp/src/Pages/Home/VideoFeed.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const VideoFeed = (props) => {
145145
// Render the component
146146
return (
147147
<img
148-
src={`${props.webVideoServerURL}/stream?topic=${CAMERA_FEED_TOPIC}&width=${imgWidth}&height=${imgHeight}&quality=20`}
148+
src={`${props.webVideoServerURL}/stream?topic=${CAMERA_FEED_TOPIC}&width=${imgWidth}&height=${imgHeight}&type=ros_compressed`}
149149
alt='Live video feed from the robot'
150150
style={{
151151
width: imgWidth,

0 commit comments

Comments
 (0)