Skip to content

Commit 7fcfadc

Browse files
committed
working on servo testing and values
1 parent 869b9aa commit 7fcfadc

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

coderbot.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
PIN_SERVO_3 = 9
1212
PIN_SERVO_4 = 10
1313

14-
PWM_FREQUENCY = 50 #Hz
14+
PWM_FREQUENCY = 500 #Hz
1515
PWM_RANGE = 100 #0-100
1616

1717
def coderbot_callback(gpio, level, tick):
@@ -112,15 +112,15 @@ def _servo_motor(self, speed_left=100, speed_right=100, elapse=-1):
112112

113113
def _servo_motor_control(self, pin, speed):
114114
self._is_moving = True
115-
speed = ((speed + 100) * 50 / 200) + 52
116-
115+
#speed = ((speed + 100) * 50 / 200) + 52
116+
speed = 50 + speed/2
117+
print "duty cycle: ", speed
117118
self.pi.set_PWM_range(pin, PWM_RANGE)
118119
self.pi.set_PWM_frequency(pin, PWM_FREQUENCY)
119120
self.pi.set_PWM_dutycycle(pin, speed)
120121

121122
def _servo_control(self, pin, angle):
122123
duty = ((angle + 90) * 100 / 180) + 25
123-
124124
self.pi.set_PWM_range(pin, PWM_RANGE)
125125
self.pi.set_PWM_frequency(pin, PWM_FREQUENCY)
126126
self.pi.set_PWM_dutycycle(pin, duty)
@@ -130,6 +130,7 @@ def stop(self):
130130
self.pi.write(pin, 0)
131131
self._is_moving = False
132132

133+
133134
def is_moving(self):
134135
return self._is_moving
135136

pigpio_test.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@
44
import pigpio
55

66

7-
PIN_SERVO = 4
7+
PIN = 4 # RIGHT=4 LEFT=25 ARM=9
88

9-
PWM_FREQ = 50
9+
PWM_FREQ = 500
1010
PWM_RANGE = 100
1111

1212
pi = pigpio.pi('localhost')
1313

14-
pi.set_PWM_frequency(PIN_SERVO,PWM_FREQ)
15-
pi.set_PWM_range(PIN_SERVO,PWM_RANGE)
14+
pi.set_PWM_frequency(PIN,PWM_FREQ)
15+
pi.set_PWM_range(PIN,PWM_RANGE)
1616

17-
pi.set_PWM_dutycycle(PIN_SERVO,0)
18-
time.sleep(1)
19-
pi.set_PWM_dutycycle(PIN_SERVO,25)
20-
time.sleep(1)
21-
pi.set_PWM_dutycycle(PIN_SERVO,60)
22-
time.sleep(1)
23-
pi.set_PWM_dutycycle(PIN_SERVO,100)
17+
# duty cycle values for range 100, frequency 400
18+
# 0-
19+
20+
for x in range (50,100):
21+
pi.set_PWM_dutycycle(PIN,x)
22+
time.sleep(0.2)
23+
print x
24+
25+
pi.set_PWM_dutycycle(PIN,0)
2426

2527

0 commit comments

Comments
 (0)