-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlow_level_controller.py
72 lines (49 loc) · 1.38 KB
/
low_level_controller.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
60
61
62
63
64
65
66
#! /usr/bin/env python3
import rospy
from geometry_msgs.msg import Twist
import RPi.GPIO as gpio
import time
gpio.setmode(gpio.BCM)
gpio.setwarnings(False)
gpio.setup(16,gpio.OUT)
gpio.setup(12,gpio.OUT)
gpio.setup(20,gpio.OUT)
#gpio.output(25,gpio.HIGH)
gpio.setup(21,gpio.OUT)
#gpio.output(21,gpio.HIGH)
gpio.setwarnings(False)
p1 = gpio.PWM(20,1000)
p2 = gpio.PWM(21,1000)
p1.start(0)
p2.start(0)
def callback(msg):
x_sped = msg.linear.x
print(x_sped)
pwm_val = x_sped * 60/0.7
inc = msg.angular.z * 30/0.4
print("inc ",inc)
# p_1 = False
# p_2 = False
if pwm_val > 0 :
gpio.output(16,gpio.HIGH)
gpio.output(12,gpio.HIGH)
# p_1 = False
# p_2 = False
else:
gpio.output(16,gpio.LOW)
gpio.output(12,gpio.LOW)
# p_1 = True
# p_2 = True
rpwm = abs(pwm_val)
lpwm = abs(pwm_val)
# pwm_val = pwm_val if pwm_val>0 else -1*pwm_val
rpwm = rpwm - inc
lpwm = lpwm + incrpwm = rpwm if rpwm >=0 else 0
lpwm = lpwm if lpwm >= 0 else 0
print('rpwm ',rpwm)
print('lpwm ',lpwm)
p1.ChangeDutyCycle(rpwm)
p2.ChangeDutyCycle(lpwm)
rospy.init_node("topic_subscriber")
sub = rospy.Subscriber('cmd_vel',Twist,callback)
rospy.spin()