How to use publisher and send from multiple nodes

I took this course last year. I am using the simple publisher example to control a robot in Gazebo Sim. It works. What I would like to create is a package that would utilize two methods, one for straight moves, the other for turns, such that the robot moves in a continuous sequence of moves. I cannot find any references on how to this. I have read that the callback module can call induvial methods. I created two methods, but cannot find any way of utilizing them Can you provide me with a reference or code strategy that will work



This is more of a programming problem. Here are my thoughts:

  • There should be some logic for determining whether the robot should move forward or turn. This is typically based on LaserScan data (but I see you are not using it in your program).
  • Put this logic in the timer callback, then call the respective method.
  • This logic would be evaluated periodically so the robot adjusts autonomously.
  • For this case, you do not need the last two lines dist_1...turn_ before def main.
  • Find below a recommended structure.
class WheelControls(Node):
  def __int__(self):
    # init your vars

  def timer_callback(self):
    # Determine in which direction the robot should move 
    # and then call one of the methods

  def move_straight_time(self, motion, speed, time):
    #

  def turn_rate_speed_control(self, clockwise, rate, time):
    #

def main(args=None):
  #

Thank you for your recommendations. I will work on it, but will be back for another review. I really appreciate the recommendations

I hope I have followed your recommendations, but I need some direction on how to call data into the method that has the logic for controlling the robot moves. If you could provide that I would appreciate it.
Tom

(Attachment basics_understanding.txt is missing)

I can’t see your attachment - it’s missing. Anyways…

For a node that only has a Publisher, I can’t think of a ROS way to bring data into the system. Enter subscribers.

Subscribers are a standard way to call data into the system. Subscribers subscribe to a given topic (such as /scan), and you’ll then put the robot control logic in the subscriber’s callback. It’s difficult to think of any intelligent ROS node without a subscriber!

Reviewing the unit on subscribers (if not already done) should get you started.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.