From 96617a3e29880bd5f19abad22a4861d5c266f69c Mon Sep 17 00:00:00 2001 From: Zhengyu Peng Date: Mon, 15 Nov 2021 13:28:20 -0500 Subject: [PATCH] Create hexapod.py --- software/rpi/hexapod.py | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 software/rpi/hexapod.py diff --git a/software/rpi/hexapod.py b/software/rpi/hexapod.py new file mode 100644 index 0000000..4dda7a7 --- /dev/null +++ b/software/rpi/hexapod.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Libraries +# https://circuitpython.readthedocs.io/projects/servokit/en/latest/ +from adafruit_servokit import ServoKit + +import time + +# Constants +nbPCAServo = 16 + + +# Objects +pca1 = ServoKit(channels=16, address=0x40, frequency=120) +pca2 = ServoKit(channels=16, address=0x41, frequency=120) + +# function init + + +def init(): + print('Init') + + # for i in range(nbPCAServo): + # pca1.servo[i].set_pulse_width_range(MIN_IMP[i] , MAX_IMP[i]) + # pca2.servo[i].set_pulse_width_range(MIN_IMP[i] , MAX_IMP[i]) + +# function main + + +def main(): + + pcaScenario() + + +# function pcaScenario +def pcaScenario(): + """Scenario to test servo""" + for i in range(nbPCAServo): + pca1.servo[i].angle = 90 + pca2.servo[i].angle = 90 + # for j in range(MIN_ANG[i], MAX_ANG[i], 1): + # print("Send angle {} to Servo {}".format(j, i)) + # pca.servo[i].angle = j + # time.sleep(0.01) + # for j in range(MAX_ANG[i], MIN_ANG[i], -1): + # print("Send angle {} to Servo {}".format(j, i)) + # pca.servo[i].angle = j + # time.sleep(0.01) + # pca.servo[i].angle = None # disable channel + time.sleep(0.5) + + +if __name__ == '__main__': + init() + main()