Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating camera images with ros3D #89

Open
C-Boucher opened this issue Sep 27, 2021 · 0 comments
Open

Integrating camera images with ros3D #89

C-Boucher opened this issue Sep 27, 2021 · 0 comments

Comments

@C-Boucher
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant