Categories
Hardware Locomotion Vision

Robot prep 2: GPIO and Camera

So I’ve got the RPi camera images sending to my laptop now, after installing OpenCV4, and running the test code from https://github.com/jeffbass/imagezmq

Next, we need to try move the servos with code.

https://learn.adafruit.com/16-channel-pwm-servo-driver/python-circuitpython

ok so i installed these

First, if no pip3,

sudo apt-get update

sudo apt-get install python-pip3

Then,

sudo pip3 install adafruit-circuitpython-pca9685

sudo pip3 install adafruit-circuitpython-servokit

Adafruit make you copy paste line by line from here…

https://github.com/adafruit/Adafruit_CircuitPython_Motor

Ok looking in the example folder of that,..

from board import SCL, SDA
import busio
from adafruit_pca9685 import PCA9685
from adafruit_motor import servo
i2c = busio.I2C(SCL, SDA)

pca = PCA9685(i2c)
pca.frequency = 50

servo2 = servo.Servo(pca.channels[2])

for i in range(90):
servo2.angle = i
for i in range(90):
servo2.angle = 90 - i
pca.deinit()

i changed it to 90 degrees and got rid of the comments. It suggests a min and max for the servo.

I ran it and the servo got angry with me and wouldn’t stop. I had to unplug everything because it was eating up the cables in its madness.

Ok so datasheet of MG996R: https://www.electronicoscaldas.com/datasheet/MG996R_Tower-Pro.pdf

It keeps going if I plug just the power back in. It seems to rotate continuously. So something is f***ed. Rebooting RPi. It’s supposed to be 180 degree rotation. Will need to read up on servo GPIO forums.

I also tried the ‘fraction’ style code: https://github.com/adafruit/Adafruit_CircuitPython_Motor/blob/master/examples/motor_pca9685_servo_sweep.py

and it rotated and rotated.

So, I think it must be a continuous servo. Now that I look at the product https://mantech.co.za/ProductInfo.aspx?Item=15M8959 i see it was a continuous servo. Derp.

Ok so let’s see… continuous servo: https://github.com/adafruit/Adafruit_CircuitPython_Motor/blob/master/examples/motor_pca9685_continuous_servo.py

We need to set some limits, apparently these are the defaults.

servo7 = servo.ContinuousServo(pca.channels[7], min_pulse=750, max_pulse=2250)

and possibly set this using a calibrated servo, using the calibrate.py program

pca = PCA9685(i2c, reference_clock_speed=25630710)

https://github.com/adafruit/Adafruit_CircuitPython_PCA9685/tree/master/examples

ok. cool.


At a later date, testing the MG996R servo,

I needed to initialise the min_pulse value at 550, or it continuously rotated.

servo7 = servo.ContinuousServo(pca.channels[1], min_pulse=550, max_pulse=2250)