ros2djs icon indicating copy to clipboard operation
ros2djs copied to clipboard

ROS2D.PathShape usage

Open rvipin17 opened this issue 6 years ago • 6 comments

Can anyone help me with how to use this function considering I am able to pass proper parameters but I'm not able to see anything happening to my 2d viewer?

path = new ROSLIB.Topic({
        ros: ros,
        name: '/move_base/NavfnROS/plan',
        messageType: 'nav_msgs/Path'
    });
    path.subscribe(function (message) {
        //alert('Received message on ' + path.name + ': ' + JSON.stringify(message));
        targetPath = new ROS2D.PathShape({
            ros: ros,
            path: message
        });
        targetPath.setPath(message);
        //path.unsubscribe();
    });

please correct me if I'm doing anything wrong and also do share some working code for PathShape func.

Thanks.

rvipin17 avatar Nov 02 '18 10:11 rvipin17

you have to use addChild function for targetPath with rootObject to get the line to display in the browser

richuzzz avatar Jan 31 '19 11:01 richuzzz

Hi - did you ever manage to get this to work. I've hacked some code together but it's not playing ball

Cheers

Mark

CycleMark avatar Feb 18 '19 06:02 CycleMark

Can you solve this problem? @CycleMark

alliansmover avatar May 10 '19 11:05 alliansmover

@alliansmover @CycleMark Yes I did solve this particular problem.

rvipin17 avatar May 14 '19 03:05 rvipin17

I subscribed the topic '/move_base/NavfnROS/plan' and plotted the received points on top of canvas using addChild to rootObject.

rvipin17 avatar May 14 '19 03:05 rvipin17

Hi, thanks for explaining. I'm trying to do that, but I'm still not seeing the path. Could you help me understand where I'm going wrong? My code is :

` var pathShape = new window.ROS2D.PathShape({ strokeSize : 3, });

var listenerforPath = new ROSLIB.Topic ({
  ros : this.ros,
  name : '/move_base/NavfnROS/plan',
  messageType : 'nav_msgs/Path'
  });

viewer2D.scene.addChild(pathShape);

listenerforPath.subscribe((message)=> {
  console.log(message)
  pathShape.setPath(message);

//listener.unsubscribe(); });`

alokforros avatar Dec 04 '19 20:12 alokforros

Could someone please provide a code snippet for this issue. I too am unable to plot the path though I am receiving the points through the subscriber.

PranavShevkar avatar Feb 08 '23 00:02 PranavShevkar

Thanks @rvipin17 @richuzzz for the solution.

For everyone who requested a snippet, and for everyone else who might need it in future, following code worked for me.

pathView = new ROS2D.PathShape({
    ros: ros,
    strokeSize: 0.02,
    strokeColor: "green",
});

gridClient.rootObject.addChild(pathView);

pathTopic = new ROSLIB.Topic({
    ros: ros,
    name: '/plan',
    messageType: 'nav_msgs/Path'
});

pathTopic.subscribe(function(message) {
    pathView.setPath(message);
});`

PranavShevkar avatar Feb 08 '23 15:02 PranavShevkar

Solution can be found in https://github.com/RobotWebTools/ros2djs/issues/38#issuecomment-1422759813

MatthijsBurgh avatar Feb 08 '23 16:02 MatthijsBurgh