-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlf_motor.py
59 lines (47 loc) · 1.38 KB
/
lf_motor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
#license removed for brevity
import rospy
from std_msgs.msg import String #use Int as a publisher
import RPi.GPIO as GPIO #import GPIO fun
from time import sleep
#set the pinModes for SENSOR
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.OUT)
GPIO.setup(18,GPIO.OUT)
GPIO.setup(27,GPIO.OUT)
GPIO.setup(22,GPIO.OUT)
#movement of robot for LINE follwer
def callback(data):
rospy.loginfo("I heard %s", data.data)
#enter the MOVEMENT conditions
#left turn
if (data.data=='R'):
#motor RIGHT
print ("RIGHT")
GPIO.output(17,GPIO.HIGH)
GPIO.output(18,GPIO.LOW)
GPIO.output(27,GPIO.LOW)
GPIO.output(22,GPIO.LOW)
#sleep (0.5)
elif(data.data=='L'):
#motor_b
print ("LEFT")
GPIO.output(18, GPIO.LOW)
GPIO.output(17, GPIO.LOW)
GPIO.output(27,GPIO.HIGH)
GPIO.output(22,GPIO.LOW)
else:
print ("FORWARD")
GPIO.output(18, GPIO.HIGH)
GPIO.output(17, GPIO.LOW)
GPIO.output(27,GPIO.HIGH)
GPIO.output(22,GPIO.LOW)
#sleep (0.5)
def motor():
rospy.init_node('motor', anonymous=True)
rospy.Subscriber("chatter", String , callback)
# spin() simply keeps python from exiting until this node is stopped
rospy.spin()
if __name__ == '__main__':
motor()