Running a node from laptop (master) on Pi

asked 2017-06-18 22:42:39 -0500

russ0 gravatar image

Hi guys,

I'm new to ROS and have started a project with the ultimate goal of navigating an RC autonomously. I have ROS installed on both machines (VM on the laptop, and through Ubuntu Mate on the Pi) and have them connected to the same network. I have tested running the two motors on the car through a python script on the Pi itself. However, I now want to test the same using a node through ROS. I have created a sample talker node as per the tutorial here, which publishes a string saying "The motor is running". I have two questions:

1) Is it possible for me to run the motor continuously using the code below?

2) Is it possible for me to launch this node (assuming it is correct) from my laptop to run on the Pi directly?


import RPi.GPIO as GPIO
from time import sleep
from std_msgs.msg import String


MotorFront1 = 37
MotorFront2 = 35
MotorFront = 33

MotorBack1 = 36
MotorBack2 = 38
MotorBack = 40

GPIO.setup(MotorFront1, GPIO.OUT)
GPIO.setup(MotorFront2, GPIO.OUT)
GPIO.setup(MotorFront, GPIO.OUT)

GPIO.setup(MotorBack1, GPIO.OUT)
GPIO.setup(MotorBack2, GPIO.OUT)
GPIO.setup(MotorBack, GPIO.OUT)

def talker():
    pub = rospy.Publisher('chatter', String, queue_size=10)
    rospy.init_node('talker', anonymous=True)
    rate = rospy.Rate(10)

    GPIO.output(MotorBack1, GPIO.HIGH) # Clockwise
    GPIO.output(MotorBack2, GPIO.LOW)  # Counter Clockwise
    GPIO.output(MotorBack, GPIO.HIGH)

    while not rospy.is_shutdown():
        print_str = "Motor is running"

if __name__ == '__main__':
    except rospy.ROSInterruptException:
edit retag flag offensive close merge delete