Creating pan and tilt code
We build our pan and tilt code in layers. We create a Servos
class and put the previous calculations into it. We set up our robot class to have an instance of the Servos
class, and ways to access the servo to pan and the servo to tilt.
Making the servo object
In this class, we encapsulate (internally manage the details of) converting an angle into a servo movement, and the quirks, such as channel numbers, of our servo board. We make a Servos
class in a servos.py
file for this:
- The
servos.py
file starts with an import and then goes straight into the constructor (the__init__
function):from Raspi_MotorHAT.Raspi_PWM_Servo_Driver import PWM class Servos: Â Â def __init__(self, addr=0x6f, deflect_90_in_ms=0.6):
Here we have an address for the PWM device. There's a deflection/calibration parameter called
deflect_90_in_ms
so that it can be overridden with the value obtained while calibrating your servos. - Next, we will add a comment...