Skip to content

Integrating camera images with ros3D #89

Description

@C-Boucher

Is there a way to include images from the robot's camera in the ros3D visualisation? Is it a feature that is planned? The only way I found to do it is to use a threading to update the images from the camera inside a grid, but the results make the video feed delayed by a couple seconds (not delayed without the ros3D object). Here is the code I am using to create a user interface :

from ipywidgets import HBox, Box, Layout, GridspecLayout
from jupyros import ros3d
import ipywidgets as widgets
import threading
import time

v = ros3d.Viewer()
rc = ros3d.ROSConnection(url="ws://localhost:9090")
tf_client = ros3d.TFClient(ros=rc, fixed_frame='/map')
g = ros3d.GridModel()
laser_view = ros3d.LaserScan(topic="/scan", ros=rc, tf_client=tf_client)
map_view = ros3d.OccupancyGrid(topic="/map", ros=rc, tf_client=tf_client)
pose_view = ros3d.Pose(topic="/mobile_manip/pose", ros=rc, tf_client=tf_client)
v.objects = [laser_view, map_view, pose_view]
v.layout = Layout(border="3px solid black", width="700px", height="600px")

image = widgets.Image(
        value=cam_msg.data,
        format="png",
        height="120%",
        width="200%")

btn_up = widgets.Button(icon='arrow-up')
btn_left = widgets.Button(icon='arrow-left')
btn_down = widgets.Button(icon='arrow-down')
btn_right = widgets.Button(icon='arrow-right')
btn_stop = widgets.Button(description='Stop')

def update_plot():
    while True:
        image.value=cam_msg.data
        time.sleep(0.1)

def on_btn_up_clicked(b):
    move_robot(0.5,0)
        
def on_btn_left_clicked(b):
    move_robot(0,0.5)
        
def on_btn_down_clicked(b):
    move_robot(-0.5,0)
        
def on_btn_right_clicked(b):
    move_robot(0,-0.5)
    
def on_btn_stop_clicked(b):
    move_robot(0,0)

btn_up.on_click(on_btn_up_clicked)
btn_left.on_click(on_btn_left_clicked)
btn_down.on_click(on_btn_down_clicked)
btn_right.on_click(on_btn_right_clicked)
btn_stop.on_click(on_btn_stop_clicked)

grid = GridspecLayout(8, 8,height='600px')

grid[0:4,0:3] = image
grid[5,1] = btn_up
grid[6,0] = btn_left
grid[6,1] = btn_stop
grid[6,2] = btn_right
grid[7,1] = btn_down
grid[:,4:7] = v
thread = threading.Thread(target=update_plot)
thread.start()
grid

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions