I am working on driving motor controllers using a Raspberry Pi. I am using the RPIO library to give me the precise timing I need. I am not using the RPi.GPIO. When I run this code:
from RPIO import PWM
from time import sleep
servo = PWM.Servo()
# https://pythonhosted.org/RPIO/pwm_py.html
# BCM GPIO numbering
# From Arduino Servo library, standards are:
# min is 544, max is 2400
# But for RPIO need to be in multiples of 10us
# Fully left
servo.set_servo(17, 540)
sleep(5)
#Middle
servo.set_servo(17, 1470)
sleep(5)
#Full right
servo.set_servo(17, 2400)
#Give it time to move to last position before turning off
sleep(1)
# Clear servo
servo.stop_servo(17)
The servo pounds into its minimums because the pulses it is giving are off by a factor of 10. The output in the terminal looks like:
PW increments: 10us
Initializing channel 0...
Requesting 139264 bytes
mem_ref 12
bus_addr = 4265472000
virtbase 0x764b6000
after init virtbaseadd_channel_pulse: channel=0, gpio=17, start=0, width=54
init_gpio 17
add_channel_pulse: channel=0, gpio=17, start=0, width=147
add_channel_pulse: channel=0, gpio=17, start=0, width=240
clear_channel_gpio: channel=0, gpio=17
shutting down dma channel 0
clear_channel: channel=0
close mail box handle start
close mail box handle returned---------------
close mail box handle finish---------------
Contrasting the pulse width of 540 I commanded the first time and 1470 the second time
The servo worked as expected once. But I changed nothing and rebooted the machine and now it does this. Other bugs I am facing are that I have to be running the python script as sudo to have RPIO library recognize it is running on a pi. Please help. I'm at my wits ends with this.
p.s. I can't just multiply the arguments by 10 because for pulses over 2ms the library thinks that the value of 20000 us that I send is longer than the entire cycle.