How to get robot position by slam_out_pose?
hi please help, i made my own robot to evaluate position of the robot. i'm using Lidar hector_slam that release topic slam_out_pose. so i call the variable in position and orientation. but i'm not sure if i'm doing this correctly. i'm not using IMU or TICK i just want Lidar that can evaluate the position. if the robot pointing to the goal, the robot will go forward else rotate until the goal founded. the problem is when i try to rotate until exactly X position, it's not moving forward (print'forward')
robot specs;
- ydlidar x4
- Raspberry pi 3b+
- 2 DC Motor
- Motor Driver H Bridge
view_frames; https://drive.google.com/file/d/10ESa...
here's the screenshot of slam_out_pose; https://ibb.co/ZMdWRyx
#! /usr/bin/env python import rospy import RPi.GPIO as GPIO import time from geometry_msgs.msg import PoseStamped from geometry_msgs.msg import Point from math import atan2 x = 0.0 y = 0.0 theta = 0.0 def newOdom (msg): global x global y global theta x = msg.pose.position.x y = msg.pose.position.y rot_q = msg.pose.orientation (roll, pitch, theta) = euler_from_quaternion ([rot_q.x, rot_q.y, rot_q.z, rot_q.w]) sub = rospy.Subscriber("/slam_out_pose", PoseStamped, newOdom) GPIO.setmode(GPIO.BCM) GPIO.setup(7,GPIO.OUT) GPIO.setup(8,GPIO.OUT) GPIO.setup(9,GPIO.OUT) GPIO.setup(10,GPIO.OUT) fright = GPIO.output(9,True) bright = GPIO.output(10,True) fright = GPIO.output(7,True) bright = GPIO.output(8,True) goal = Point () goal.x = 2 goal.y = 2 while not rospy.is_shutdown(): inc_x = goal.x - x inc_y = goal.y - y angle_to_goal = atan2 (inc_y, inc_x) if abs(angle_to_goal - theta) > 0.1: print("ROTATE RIGHT") fright else: print("FORWARD") fright bright
i hope someone can explain to me thank you.
my reference code https://www.youtube.com/watch?v=eJ4QP...
I dont see you initialising your node:
rospy.init_node("track_my_awesome_robot", log_level=rospy.INFO)
hi thank you for replying me, i initiate the code by directly "python my_controller.py" is this ok? so sorry i bit lost here
from Tutorials
Since you didnt initialise your node, I think you cant subscribe to a topic. This means you wont receive any messages.
The fact that you started the script using
python my_controller.py
doesnt change anything. It is however not the typical ROS way I prefer, which would be:rosrun <my_awesome_pkg> my_controller.py
.