I'm currently doing the ROS topic Quiz (Also know as Mini projects on topics). I'm pretty new to the entire programming stuff. The Mini project makes me implement a simple Wall avoidance. Basically I have to move the robot shown in the simulator straight. when it comes closer to the wall I need to move it away from the wall, and once its away from the wall, I need to stop the robot.

alt text

I have developed a preliminary code in-which I subscribe to the robots Laserscanner and publish movement command. Is it a good idea to have Subscriber and Publisher in the same node? Also I don't know how to go back to the main program after say 1 second so that I make decision based on updated Laserscan data. Could someone tell me what I'm missing in order to make the robot do what its meant to do? I also don't know how to run the entire program based on a timer alt text

asked 06 May, 13:09

eashwar.erahan's gravatar image

accept rate: 0%

Hi @eashwar.erahan,

Here are some hints for you (since this is a quiz, I can't tell you the answer directly :D):

  • Yes, it's okay to have the publisher and subscriber in the same node
  • You can just create a global pub variable at the top of your code, before the functions
  • You can also create a global move at the top of your code.
  • Remove the rate variable; you don't need it.
  • In your go_straight() function, set move.linear.x (to whatever value you decide) and move.angular.z=0 and then do pub.publish(move). You need to do pub.publish() to move the robot.
  • Similarly, set move.angular.z (to whatever value you decide) and move.linear.x=0 in turn_left() and then publish.
  • In your decision(), check the value of y so that you can finetune your program. The values don't necessarily correspond to real meters. Also, when the wall if very far away, that value is inf (infinity), so you should modify your code to cater for this.
  • Once you are able to make the robot avoid the wall, you can just stop the program manually with Ctrl + C. Then when you are happy, you can refine the code to stop the robot after some time, after it has avoided the wall.

Hope this helps!

permanent link

answered 07 May, 10:29

bayodesegun%40bayodesegun.com's gravatar image

accept rate: 37%

edited 07 May, 10:29

Yes this helped a lot, thank you so much for your valuable feedback

(07 May, 16:02) eashwar.erahan

@eashwar.erahan if it helped you, could you please mark as accepted?

(09 May, 09:19) bayodesegun@...
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 06 May, 13:09

question was seen: 166 times

last updated: 09 May, 09:19

powered by OSQA