I think that I got the basic of my ros project!
I have it such that it will tell me what the distance is at 180 degrees, will convert that to a string (a if >0.3, b if <0.2, c if in between) - figure a- and then a script to convert the string output published in the cmd_vel topic - figure b. rviz shows my data points appropriately. My rqt graph is what I was hoping it be -figure c. However I either get no movement on my robot, or a counterclockwise angular movement without linear movement. I think the problem must something with my callback script in figure b but I cant figure it out. I think its a simple syntatical error but I need some help
figure a:
figure b:
figure c:
Thank you so much for any help. I feel that I am close!
Hi @r.franklinismail ,
I see that you are defining the Twist message, but it seems you are not publishing it after defining its values in your callback
1 Like
Thank you!!! @marco.nc.arruda
This is very helpful
I still dont have any connection to the /cmd_vel after I use the following code. I double checked by using rostopic echo /cmd_vel and saw that nothing was being published into this.
The code I used to publish was
Blockquote
def my_callback(request):
print (request)
if request == “a”:
Twistobj.linear.x == 20 , Twistobj.angular.x == 2
pub.publish(geometry_msgs.msg.Twist(Twistobj.linear.x, Twistobj.angular.x))
elif request == “b”:
Twistobj.linear.x == 2 , Twistobj.angular.x == -2
pub.publish(geometry_msgs.msg.Twist(Twistobj.linear.x, Twistobj.angular.x))
elif request == “c”:
Twistobj.linear.x == 2 , Twistobj.angular.x == 0
pub.publish(geometry_msgs.msg.Twist(Twistobj.linear.x, Twistobj.angular.x))
print (“request completed”)
I also tried using
Blockquote
pub.publish(Twistobj.linear.x, Twistobj.angular.x)
and got smae result
when I defined pub earlier in my code I defined it as
pub = rospy.Publisher(‘/cmd_vel’, Twist, queue_size=1)
and I also made an instance of Twist so I feel like it should dump any data from pub.publisher() into the /cmd_vel topic? no?
Thanks!
No, the object is not published automatically.
You should put after your if / elif / elif
logic something like
pub.publish(Twistobj)