-
Notifications
You must be signed in to change notification settings - Fork 87
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
How to display the robot location on top of the Viewer? #39
Comments
Ok, so I tried to use OccupancyGridClientNav, but it doesn't seem to be able to add 2 nav objects to the same viewer scene? I have 2 robots on the same map and I want to display both of them. I tried this but it didn't work
|
Hey. Right now i m trying the same... did you it working? |
@ngunhaSO @timdori were either of you able to get this feature working? I'm stuck with the same issue. I finally got the map to display and fit to the size of the canvas, but I can't figure out how to show the arrow for my bot's position. NAV2D.OccupancyGridClientNav() displays the map and if I double click, it will display the purple arrow telling the bot where to go, but it never shows the yellow arrow showing where the bot is currently located. |
Finally got it using the NAV2D to work. User error as per the norm. For any future users, make sure you are running the robot_pose_publisher as mentioned in the nav2djs documentation. The robot_pose_publisher needs to be running in order for this widget to work. |
@corey-mitchell I did a workaround to use a for loop and a dynamic function to add multiple robot on the map |
@ngunhaSO Can you provide any snippets by chance? I already know that I will want this feature in the future and it would be nice to have a usable reference. |
I too would be interest to see how you add a robot to a OccupancyGridClient. I've got it working OccupancyGridClientNav but I'd like more control over it and I don't need to interact with it. Thanks Mark |
@corey-mitchell @CycleMark
|
Hi @ngunhaSO - This is great, many thanks. Really good jump off point. Pointer sometimes throws a rotation wobble - I shall investigate. Thanks again Mark |
@CycleMark I experienced that too but my time was limited back there so i used circle image for displaying. But yeah, i believe with this approach you can control the subscription in 'createFunc()' by checking the type of handler to call |
I'm coming back for future users who may be wanting to make a more custom map with click handlers and such. I would first like to note, that this approach is not for everyone and may not even be what most people are looking for. But I wanted to share because it was a bit of a pain for me to make so I figured I might be able to help someone else down the road. I wanted to handle custom click events on my map so that we could develop features such as desired travel lanes and setting up "No-Go" zones on-the-fly. So, I made a custom map that allows me to do just that as well as monitor multiple bot's position in real time. Here's a sample of said map with a single bot:
Hope this helps someone. |
To fix that rotation equation, replace
with
don't forget to import THREE which can be imported by |
Is it possible to use tf instead of this node? robot_pose_publisher is not available in ros melodic |
Modifying @ngunhaSO solution and using @5730289021-NN rotation fix I was able to show the marker using tf.
However, I would still like to know if there is a more elegant way of doing this. |
This could be an alternative. This uses the following javascript class . Hope that helps! Do remember to run the robot pose publisher package on your robot in order to get the /robot_pose topic
|
Hello, I'm using ROS melodic and I can't run the example on ros wiki. Could you help me? |
@OmarKassas What is the reason you can't run the example? Is your computer turned off? 😉 Please provide more information... |
Thank you for your response.
I need to navigate my robot through the web. I followed the tutorial on the
ROS wiki but the robot pose publisher is not working with melodic version.
http://wiki.ros.org/nav2djs/Tutorials/CreatingABasicNav2DWidget
I found your code and put it in html file but still not working could you
help.
I launch the navigation of my robot (gazebo - rviz - amcl - move base) and
map server and ros bridge
and attached is my file. Help me to run it
…On Thu, Jan 26, 2023 at 6:36 PM Matthijs van der Burgh < ***@***.***> wrote:
@OmarKassas <https://github.com/OmarKassas> What is the reason you can't
run the example? Is your computer turned off? 😉
Please provide more information...
—
Reply to this email directly, view it on GitHub
<#39 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASJIXR6TEQWPVA2NSOW46GDWUKRXBANCNFSM4GK6STOQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Omar Alkassas
Mechatronics and Robotics Engineering | EJUST
Egypt-Japan University of Science and Technology (EJUST)
P.O. Box 179, New Borg El-Arab City, Postal Code 21934, Alexandria, Egypt
Mobile: +201014287473
https://ejust.edu.eg
|
Thank you for your response. I need to navigate my robot through the web. I followed the tutorial on the ROS wiki but the robot pose publisher is not working with melodic version. I found your code and put it in html file but still not working could you help.
|
So what happens when you run? |
I suggest you to use a fixed width of the viewer. So replace width : document.getElementById("map").clientWidth - 16, By width: 680, // or any fixed width you like |
Your div id is set to nav in your html code, but when you create your viewer you set it to map. |
@tran00n Good catch on the div ID. |
@tran00n the |
hello i have a problem with arrow [Vue warn]: Error in mounted hook: "ReferenceError: must call super constructor before using 'this' in derived class constructor"
(found in <Root>) vue.js:5129:23
ReferenceError: must call super constructor before using 'this' in derived class constructor
NavigationArrow http://127.0.0.1:5500/ros_webpage/build/ros2d.js:2147
createRobotMarker http://127.0.0.1:5500/ros_webpage/js/main.js:81
mounted http://127.0.0.1:5500/ros_webpage/js/main.js:18
VueJS 7
<anonymous> http://127.0.0.1:5500/ros_webpage/js/main.js:2 my scripts // Khởi tạo ứng dụng Vue
var app = new Vue({
el: '#app',
data: {
connected: false,
ros: null,
ws_address: 'ws://192.168.177.128:9090',
logs: [],
loading: false,
topic: null,
message: null,
viewer: null,
gridClient: null,
robotMarker: null
},
mounted() {
this.init();
this.createRobotMarker();
window.addEventListener('keydown', this.handleKeyDown);
window.addEventListener('keyup', this.handleKeyUp);
},
methods: {
handleKeyDown(event) {
switch (event.key) {
case 'a':
this.turnLeft();
break;
case 'w':
this.forward();
break;
case 's':
this.stop();
break;
case 'd':
this.turnRight();
break;
case 'x':
this.backWard();
break;
}
},
handleKeyUp(event) {
switch (event.key) {
case 'a':
case 'w':
case 's':
case 'd':
case 'x':
this.stop();
break;
}
},
init() {
// Connect to ROS.
this.ros = new ROSLIB.Ros({
url: this.ws_address
});
// Create the main viewer.
this.viewer = new ROS2D.Viewer({
divID: 'map',
width: 640,
height: 480
});
// Setup the map client.
this.gridClient = new ROS2D.OccupancyGridClient({
ros: this.ros,
rootObject: this.viewer.scene,
continuous: true
});
// Scale the canvas to fit to the map
this.gridClient.on('change', () => {
this.viewer.scaleToDimensions(this.gridClient.currentGrid.width, this.gridClient.currentGrid.height);
this.viewer.shift(this.gridClient.currentGrid.pose.position.x, this.gridClient.currentGrid.pose.position.y);
});
},
createRobotMarker() {
// Tạo một ROS2D.NavigationArrow cho robot
this.robotMarker = new ROS2D.NavigationArrow({
size: 0.25,
strokeSize: 0.05,
pulse: true,
fillColor: createjs.Graphics.getRGB(0, 0, 0, 0.65)
});
// Khai báo topic để nhận các tin nhắn về vị trí của robot
const poseTopic = new ROSLIB.Topic({
ros: this.ros,
name: '/amcl_pose',
messageType: 'geometry_msgs/PoseWithCovarianceStamped'
});
// Thêm marker vào rootObject của viewer
this.viewer.scene.addChild(this.robotMarker);
// Kiểm tra và xử lý lỗi
if (poseTopic) {
// Tạo hàm createFunc để cập nhật vị trí của robot
const createFunc = (handlerToCall, discriminator, robotMarker) => {
return discriminator.subscribe(pose => {
robotMarker.x = pose.pose.pose.position.x;
robotMarker.y = -pose.pose.pose.position.y;
const quaZ = pose.pose.pose.orientation.z;
let degreeZ = 0;
if (quaZ >= 0) {
degreeZ = quaZ / 1 * 180;
} else {
degreeZ = (-quaZ) / 1 * 180 + 180;
}
robotMarker.rotation = -degreeZ + 35;
});
};
// Gọi hàm createFunc để cập nhật vị trí của robot
createFunc('subscribe', poseTopic, this.robotMarker);
} else {
console.error("Pose topic is not defined or initialized correctly.");
}
},
connect() {
this.logs.unshift('Connecting to ROSBridge server...');
this.ros = new ROSLIB.Ros({
url: this.ws_address
});
this.ros.on('connection', () => {
this.logs.unshift('Connected to ROSBridge server');
this.connected = true;
});
this.ros.on('error', (error) => {
this.logs.unshift('Error connecting to ROSBridge server: ' + error);
});
this.ros.on('close', () => {
this.logs.unshift('Connection to ROSBridge server closed');
this.connected = false;
});
},
disconnect() {
this.ros.close();
},
setTopic() {
this.topic = new ROSLIB.Topic({
ros: this.ros,
name: '/cmd_vel',
messageType: 'geometry_msgs/Twist'
});
},
forward() {
this.message = new ROSLIB.Message({
linear: { x: 0.22, y: 0, z: 0 },
angular: { x: 0, y: 0, z: 0 }
});
this.topic.publish(this.message);
},
turnLeft() {
this.message = new ROSLIB.Message({
linear: { x: 0.22, y: 0, z: 0 },
angular: { x: 0, y: 0, z: 0.3 }
});
this.topic.publish(this.message);
},
turnRight() {
this.message = new ROSLIB.Message({
linear: { x: 0.22, y: 0, z: 0 },
angular: { x: 0, y: 0, z: -0.3 }
});
this.topic.publish(this.message);
},
backWard() {
this.message = new ROSLIB.Message({
linear: { x: -0.3, y: 0, z: 0 },
angular: { x: 0, y: 0, z: 0 }
});
this.topic.publish(this.message);
},
stop() {
this.message = new ROSLIB.Message({
linear: { x: 0, y: 0, z: 0 },
angular: { x: 0, y: 0, z: 0 }
});
this.topic.publish(this.message);
}
}
}); |
Can someone point me to an example to display the current robot position on top of the viewer?
I used the example/continuous.html and add the listener to listen to /cmd_vel, but i am not sure how to draw the robot position on top of the viewer.
The text was updated successfully, but these errors were encountered: