ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Question regarding ROS(turtlesim).Moving one turtle towards another turtle

asked 2020-03-21 07:26:14 -0500

Gun_Kan02 gravatar image

updated 2020-03-22 12:57:59 -0500

I want to write a python node such that it subscribes to relevant topics and publishes to relevant topics to make default 'turtle1' at (5.444,5.444) move towards a newly spawned turtle 'blah' at (X1, Y1) and stops at a 'D' unit distance from 'blah'.(This is in ROS)Can someone please explain or provide a solution?!

I gave new subscriber as rospy.Subscriber('turtle/blah',Pose,update_posenew)and a new object called as posenew=Pose() inside __init__ function. The callback function is:

def update_posenew(self,data)

   self.posenew=data

   self.posenew.x = round(self.pose.x, 4)

   self.posenew.y = round(self.pose.y, 4)

... Uptil now fine.now.. In the move2goal function

 def move2goal(self): 

     goal_pose =Pose()

     goal_pose.x =∆

     goal_pose.y = ∆

What should be given in place of ∆?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2020-03-21 19:09:49 -0500

updated 2020-03-23 04:49:35 -0500

gvdhoorn gravatar image

I think this is exactly what you are looking for. You just need to subscribe your /blah/pose to get the goal pose rather than get it from the user.

As for

stops at a 'D' unit distance from 'blah'

simply set distance_tolerance to your D unit.

I hope this helps!

P.S. This question is not really related to turtlebot. I suggest you change the tag to turtlesim.


Edit:

You should add self to create your instance attribute so that other methods in TurtleBot class are able to access self.posenew too. The topic you have subscribed to is incorrect. What is turtle/blah? It should be spawn_name/poseso in your case, i.e. blah/pose. The callback – update_posenew where you update your self.posenew is also wrong. Notice that you have two turtles so you have two different poses. Therefore, you need to round the pose of your blah turtle not the turtle1's one. So simply make this change to your code.

self.posenew.x = round(self.posenew.x, 4)
self.posenew.y = round(self.posenew.y, 4)

∆.x and ∆.y are thus the updated self.posenew.x and self.posenew.y respectively.

goal_pose.x = self.posenew.x
goal_pose.y = self.posenew.y

Please also be aware that when you assign Pose() to your new instance attribute self.posenew inside __init__, the contents of self.posenew are initially all set to 0.0 which might affect the calculation of distance/velocity in move2goal(). So I advise you to add

rospy.wait_for_message('blah/pose', Pose)

after definition of self.posenew to wait for the message to arrive on the topic blah/pose or simply adding rospy.sleep(0.5) will do the trick.

edit flag offensive delete link more

Comments

I understood that there is a need of /blah/pose subscriber but after that how to change the goal_pose to and how to update and callback and how to differentiate between blah and turtle1 subscriber?!

Gun_Kan02 gravatar image Gun_Kan02  ( 2020-03-22 02:57:54 -0500 )edit

You can create another subscriber that subscribes to /blah/pose and has its own callback function. For more information, please take a look at this post. I am not sure what you want to achieve specifically. If you just want to make your turtle1 move towards blah once instead of continuously chasing it. It's probably better to set the goal_pose once using ros::topic::waitForMessage() than update it repeatedly through callback.

karenchiang gravatar image karenchiang  ( 2020-03-22 06:17:21 -0500 )edit

http://wiki.ros.org/turtlesim/Tutoria.... I referred to this link and now I got stuck at one point. I created another subscriber and callback(update_posenew) for 'blah' turtle with topic /blah/pose.now in the move2goal function what should I equate goal_pose to(i mean what is the syntax) Can you please help?! This has been itching me for 2 days. Please!!

Gun_Kan02 gravatar image Gun_Kan02  ( 2020-03-22 09:09:15 -0500 )edit

Can you please elaborate on that? At what point did you get stuck? I would like to know what you've assigned to your goal_pose.

karenchiang gravatar image karenchiang  ( 2020-03-22 11:47:24 -0500 )edit

I gave new subscriber as rospy.Subscriber('turtle/blah',Pose,update_posenew) And a new object called as posenew=Pose() inside __init__ function. The callback function is: def update_posenew(self,data) self.posenew=data self.posenew.x = round(self.pose.x, 4) self.posenew.y = round(self.pose.y, 4) ... Uptil now fine.now.. In the move2goal function

def move2goal(self): goal_pose =Pose() goal_pose.x =∆ goal_pose.y = ∆ What should be given in place of ∆?!

Gun_Kan02 gravatar image Gun_Kan02  ( 2020-03-22 12:12:59 -0500 )edit

@Gun_Kan02: could you please add these sort of updates (ie: the ones which contain code) to your main question text? Comments are too small.

Please append your current code to your original question. Use the edit button/link for that.

gvdhoorn gravatar image gvdhoorn  ( 2020-03-22 12:22:32 -0500 )edit

someone please explain?!

Gun_Kan02 gravatar image Gun_Kan02  ( 2020-03-22 14:07:30 -0500 )edit
1

Yess this worked thank you so much tcchiang

Gun_Kan02 gravatar image Gun_Kan02  ( 2020-03-22 23:53:34 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-03-21 07:26:14 -0500

Seen: 1,041 times

Last updated: Mar 23 '20