a
This commit is contained in:
9
old_stuff/reset.py
Normal file
9
old_stuff/reset.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import time
|
||||
from adafruit_servokit import ServoKit
|
||||
|
||||
|
||||
kit = ServoKit(channels=16)
|
||||
|
||||
|
||||
for x in range(11):
|
||||
kit.servo[x].angle = 55
|
||||
55
old_stuff/simpletest.py
Normal file
55
old_stuff/simpletest.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# Simple demo of of the PCA9685 PWM servo/LED controller library.
|
||||
# This will move channel 0 from min to max position repeatedly.
|
||||
# Author: Tony DiCola
|
||||
# License: Public Domain
|
||||
from __future__ import division
|
||||
import time
|
||||
|
||||
# Import the PCA9685 module.
|
||||
import Adafruit_PCA9685
|
||||
|
||||
|
||||
# Uncomment to enable debug output.
|
||||
#import logging
|
||||
#logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
# Initialise the PCA9685 using the default address (0x40).
|
||||
pwm = Adafruit_PCA9685.PCA9685()
|
||||
|
||||
# Alternatively specify a different address and/or bus:
|
||||
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)
|
||||
|
||||
# Configure min and max servo pulse lengths
|
||||
servo_min = 150 # Min pulse length out of 4096
|
||||
servo_max = 400 # Max pulse length out of 4096
|
||||
|
||||
# Helper function to make setting a servo pulse width simpler.
|
||||
def set_servo_pulse(channel, pulse):
|
||||
pulse_length = 1000000 # 1,000,000 us per second
|
||||
pulse_length //= 60 # 60 Hz
|
||||
print('{0}us per period'.format(pulse_length))
|
||||
pulse_length //= 4096 # 12 bits of resolution
|
||||
print('{0}us per bit'.format(pulse_length))
|
||||
pulse *= 1000
|
||||
pulse //= pulse_length
|
||||
pwm.set_pwm(channel, 0, pulse)
|
||||
|
||||
# Set frequency to 60hz, good for servos.
|
||||
pwm.set_pwm_freq(60)
|
||||
|
||||
print('Moving servo on channel 0, press Ctrl-C to quit...')
|
||||
while True:
|
||||
# Move servo on channel O between extremes.
|
||||
pwm.set_pwm(0, 0, servo_min)
|
||||
pwm.set_pwm(1, 0, servo_min)
|
||||
pwm.set_pwm(2, 0, servo_min)
|
||||
pwm.set_pwm(3, 0, servo_min)
|
||||
pwm.set_pwm(4, 0, servo_min)
|
||||
time.sleep(1)
|
||||
pwm.set_pwm(0, 0, servo_max)
|
||||
pwm.set_pwm(1, 0, servo_max)
|
||||
pwm.set_pwm(2, 0, servo_max)
|
||||
pwm.set_pwm(3, 0, servo_max)
|
||||
pwm.set_pwm(4, 0, servo_max)
|
||||
time.sleep(1)
|
||||
|
||||
53
old_stuff/simpletest2.py
Normal file
53
old_stuff/simpletest2.py
Normal file
@@ -0,0 +1,53 @@
|
||||
# Simple demo of of the PCA9685 PWM servo/LED controller library.
|
||||
# This will move channel 0 from min to max position repeatedly.
|
||||
# Author: Tony DiCola
|
||||
# License: Public Domain
|
||||
from __future__ import division
|
||||
import time
|
||||
|
||||
# Import the PCA9685 module.
|
||||
import Adafruit_PCA9685
|
||||
|
||||
|
||||
# Uncomment to enable debug output.
|
||||
#import logging
|
||||
#logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
# Initialise the PCA9685 using the default address (0x40).
|
||||
pwm = Adafruit_PCA9685.PCA9685()
|
||||
|
||||
# Alternatively specify a different address and/or bus:
|
||||
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)
|
||||
|
||||
# Configure min and max servo pulse lengths
|
||||
servo_min = 150 # Min pulse length out of 4096
|
||||
servo_max = 400 # Max pulse length out of 4096
|
||||
|
||||
# Helper function to make setting a servo pulse width simpler.
|
||||
def set_servo_pulse(channel, pulse):
|
||||
pulse_length = 1000000 # 1,000,000 us per second
|
||||
pulse_length //= 60 # 60 Hz
|
||||
print('{0}us per period'.format(pulse_length))
|
||||
pulse_length //= 4096 # 12 bits of resolution
|
||||
print('{0}us per bit'.format(pulse_length))
|
||||
pulse *= 1000
|
||||
pulse //= pulse_length
|
||||
pwm.set_pwm(channel, 0, pulse)
|
||||
|
||||
# Set frequency to 60hz, good for servos.
|
||||
pwm.set_pwm_freq(60)
|
||||
|
||||
print('Moving servo on channel 4, press Ctrl-C to quit...')
|
||||
while True:
|
||||
|
||||
for x in range(6):
|
||||
pwm.set_pwm(x, 0,150)
|
||||
|
||||
print('200')
|
||||
time.sleep(1)
|
||||
for y in range(6):
|
||||
pwm.set_pwm(y, 0, 400)
|
||||
|
||||
print('350')
|
||||
time.sleep(1)
|
||||
|
||||
46
old_stuff/simpletest3.py
Normal file
46
old_stuff/simpletest3.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# Simple demo of of the PCA9685 PWM servo/LED controller library.
|
||||
# This will move channel 0 from min to max position repeatedly.
|
||||
# Author: Tony DiCola
|
||||
# License: Public Domain
|
||||
from __future__ import division
|
||||
import time
|
||||
|
||||
# Import the PCA9685 module.
|
||||
import Adafruit_PCA9685
|
||||
|
||||
|
||||
# Uncomment to enable debug output.
|
||||
#import logging
|
||||
#logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
# Initialise the PCA9685 using the default address (0x40).
|
||||
pwm = Adafruit_PCA9685.PCA9685()
|
||||
|
||||
# Alternatively specify a different address and/or bus:
|
||||
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)
|
||||
|
||||
# Configure min and max servo pulse lengths
|
||||
servo_min = 150 # Min pulse length out of 4096
|
||||
servo_max = 600 # Max pulse length out of 4096
|
||||
|
||||
# Helper function to make setting a servo pulse width simpler.
|
||||
def set_servo_pulse(channel, pulse):
|
||||
pulse_length = 1000000 # 1,000,000 us per second
|
||||
pulse_length //= 60 # 60 Hz
|
||||
print('{0}us per period'.format(pulse_length))
|
||||
pulse_length //= 4096 # 12 bits of resolution
|
||||
print('{0}us per bit'.format(pulse_length))
|
||||
pulse *= 1000
|
||||
pulse //= pulse_length
|
||||
pwm.set_pwm(channel, 0, pulse)
|
||||
|
||||
# Set frequency to 60hz, good for servos.
|
||||
pwm.set_pwm_freq(60)
|
||||
|
||||
print('Moving servo on channel 4, press Ctrl-C to quit...')
|
||||
while True:
|
||||
|
||||
channel = int(input("Channel:\n"))
|
||||
pos = int(input("Position: \n"))
|
||||
num = int(input("num \n"))
|
||||
pwm.set_pwm(channel, 0,pos)
|
||||
49
old_stuff/testwalk.py
Normal file
49
old_stuff/testwalk.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# Simple demo of of the PCA9685 PWM servo/LED controller library.
|
||||
# This will move channel 0 from min to max position repeatedly.
|
||||
# Author: Tony DiCola
|
||||
# License: Public Domain
|
||||
from __future__ import division
|
||||
import time
|
||||
|
||||
# Import the PCA9685 module.
|
||||
import Adafruit_PCA9685
|
||||
|
||||
|
||||
# Uncomment to enable debug output.
|
||||
#import logging
|
||||
#logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
# Initialise the PCA9685 using the default address (0x40).
|
||||
pwm = Adafruit_PCA9685.PCA9685()
|
||||
|
||||
# Alternatively specify a different address and/or bus:
|
||||
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)
|
||||
|
||||
# Configure min and max servo pulse lengths
|
||||
servo_min = 150 # Min pulse length out of 4096
|
||||
servo_max = 400 # Max pulse length out of 4096
|
||||
|
||||
# Helper function to make setting a servo pulse width simpler.
|
||||
def set_servo_pulse(channel, pulse):
|
||||
pulse_length = 1000000 # 1,000,000 us per second
|
||||
pulse_length //= 60 # 60 Hz
|
||||
print('{0}us per period'.format(pulse_length))
|
||||
pulse_length //= 4096 # 12 bits of resolution
|
||||
print('{0}us per bit'.format(pulse_length))
|
||||
pulse *= 1000
|
||||
pulse //= pulse_length
|
||||
pwm.set_pwm(channel, 0, pulse)
|
||||
|
||||
# Set frequency to 60hz, good for servos.
|
||||
pwm.set_pwm_freq(60)
|
||||
|
||||
print('Moving servo on channel 0, press Ctrl-C to quit...')
|
||||
while True:
|
||||
pwm.set_pwm(6,0,150)
|
||||
for x in range(150,400):
|
||||
print (x)
|
||||
pwm.set_pwm(6, 0, x)
|
||||
math = round(0.026*pow((x-275),2))
|
||||
print (math)
|
||||
pwm.set_pwm(0, 0, math)
|
||||
|
||||
20
old_stuff/testwalk2.py
Normal file
20
old_stuff/testwalk2.py
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
"""Simple test for a standard servo on channel 0 and a continuous rotation servo on channel 1."""
|
||||
import time
|
||||
from adafruit_servokit import ServoKit
|
||||
|
||||
# Set channels to the number of servo channels on your kit.
|
||||
# 8 for FeatherWing, 16 for Shield/HAT/Bonnet.
|
||||
kit = ServoKit(channels=16)
|
||||
kit.servo[12].set_pulse_width_range(1000, 2000)
|
||||
#kit.servo[12].angle = 180
|
||||
#time.sleep(1)
|
||||
kit.continuous_servo[12].throttle = 1
|
||||
time.sleep(3)
|
||||
kit.continuous_servo[12].throttle = -1
|
||||
time.sleep(3)
|
||||
kit.servo[0].angle = 0
|
||||
kit.continuous_servo[12].throttle = 0
|
||||
11
old_stuff/testwalk3.py
Normal file
11
old_stuff/testwalk3.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import time
|
||||
from adafruit_servokit import ServoKit
|
||||
|
||||
kit = ServoKit(channels=16)
|
||||
kit.servo[12].set_pulse_width_range(1000, 2000)
|
||||
|
||||
kit.servo[12].actuation_range = 200
|
||||
while True:
|
||||
channel = int(input("Channel:\n"))
|
||||
pos = int(input("Position: \n"))
|
||||
kit.servo[channel].angle = pos
|
||||
14
old_stuff/testwalk4.py
Normal file
14
old_stuff/testwalk4.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import time
|
||||
from adafruit_servokit import ServoKit
|
||||
|
||||
kit = ServoKit(channels=16)
|
||||
|
||||
leg = int(input("leg"))
|
||||
|
||||
kit.servo[leg].angle = 0
|
||||
kit.servo[leg+6].angle = 0
|
||||
time.sleep(1)
|
||||
kit.servo[leg].angle = 180
|
||||
kit.servo[leg+6].angle = 180
|
||||
time.sleep(1)
|
||||
kit.servo[leg].angle = 0
|
||||
7
old_stuff/testwalk4.py.save
Normal file
7
old_stuff/testwalk4.py.save
Normal file
@@ -0,0 +1,7 @@
|
||||
import time
|
||||
from adafruit_servokit import ServoKit
|
||||
|
||||
kit = ServoKit(channels=16)
|
||||
# smallest 0 biggest 110
|
||||
while True:
|
||||
kit.servo[].angle =
|
||||
77
old_stuff/thr.py
Normal file
77
old_stuff/thr.py
Normal file
@@ -0,0 +1,77 @@
|
||||
import threading
|
||||
import time
|
||||
from adafruit_servokit import ServoKit
|
||||
|
||||
kit = ServoKit(channels=16)
|
||||
|
||||
#leg = int(input("leg"))
|
||||
def left2():
|
||||
kit.servo[2].angle = 0
|
||||
kit.servo[8].angle = 0
|
||||
time.sleep(1)
|
||||
kit.servo[2].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[8].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[2].angle = 0
|
||||
def left1():
|
||||
kit.servo[1].angle = 0
|
||||
kit.servo[7].angle = 0
|
||||
time.sleep(1)
|
||||
kit.servo[1].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[7].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[1].angle = 0
|
||||
def left0():
|
||||
kit.servo[0].angle = 0
|
||||
kit.servo[6].angle = 0
|
||||
time.sleep(1)
|
||||
kit.servo[0].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[6].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[0].angle = 0
|
||||
def right5():
|
||||
kit.servo[5].angle = 0
|
||||
kit.servo[11].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[5].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[11].angle = 0
|
||||
time.sleep(1)
|
||||
kit.servo[5].angle = 0
|
||||
def right4():
|
||||
kit.servo[4].angle = 0
|
||||
kit.servo[10].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[4].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[10].angle = 0
|
||||
time.sleep(1)
|
||||
kit.servo[4].angle = 0
|
||||
def right3():
|
||||
kit.servo[3].angle = 0
|
||||
kit.servo[9].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[3].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[9].angle = 0
|
||||
time.sleep(1)
|
||||
kit.servo[leg].angle = 0
|
||||
|
||||
|
||||
leg0 = threading.Thread(target=left0, args=())
|
||||
leg1 = threading.Thread(target=left1, args=())
|
||||
leg2 = threading.Thread(target=left2, args=())
|
||||
leg3 = threading.Thread(target=right3, args=())
|
||||
leg4 = threading.Thread(target=right4, args=())
|
||||
leg5 = threading.Thread(target=right5, args=())
|
||||
leg0.start()
|
||||
leg2.start()
|
||||
leg4.start()
|
||||
time.sleep(3)
|
||||
leg1.start()
|
||||
leg3.start()
|
||||
leg5.start()
|
||||
|
||||
90
old_stuff/thr2.py
Normal file
90
old_stuff/thr2.py
Normal file
@@ -0,0 +1,90 @@
|
||||
import threading
|
||||
import time
|
||||
from adafruit_servokit import ServoKit
|
||||
|
||||
kit = ServoKit(channels=16)
|
||||
|
||||
#leg = int(input("leg"))
|
||||
def left2():
|
||||
kit.servo[2].angle = 0
|
||||
kit.servo[8].angle = 0
|
||||
time.sleep(1)
|
||||
kit.servo[2].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[8].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[2].angle = 0
|
||||
def left1():
|
||||
kit.servo[1].angle = 0
|
||||
kit.servo[7].angle = 0
|
||||
time.sleep(1)
|
||||
kit.servo[1].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[7].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[1].angle = 0
|
||||
def left0():
|
||||
kit.servo[0].angle = 0
|
||||
kit.servo[6].angle = 0
|
||||
time.sleep(1)
|
||||
kit.servo[0].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[6].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[0].angle = 0
|
||||
def right5():
|
||||
kit.servo[5].angle = 0
|
||||
kit.servo[11].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[5].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[11].angle = 0
|
||||
time.sleep(1)
|
||||
kit.servo[5].angle = 0
|
||||
def right4():
|
||||
kit.servo[4].angle = 0
|
||||
kit.servo[10].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[4].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[10].angle = 0
|
||||
time.sleep(1)
|
||||
kit.servo[4].angle = 0
|
||||
def right3():
|
||||
kit.servo[3].angle = 0
|
||||
kit.servo[9].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[3].angle = 110
|
||||
time.sleep(1)
|
||||
kit.servo[9].angle = 0
|
||||
time.sleep(1)
|
||||
kit.servo[3].angle = 0
|
||||
|
||||
|
||||
#leg0 = threading.Thread(target=left0, args=())
|
||||
#leg1 = threading.Thread(target=left1, args=())
|
||||
#leg2 = threading.Thread(target=left2, args=())
|
||||
#leg3 = threading.Thread(target=right3, args=())
|
||||
#leg4 = threading.Thread(target=right4, args=())
|
||||
#leg5 = threading.Thread(target=right5, args=())
|
||||
while True:
|
||||
leg0 = threading.Thread(target=left0, args=())
|
||||
leg1 = threading.Thread(target=left1, args=())
|
||||
leg2 = threading.Thread(target=left2, args=())
|
||||
leg3 = threading.Thread(target=right3, args=())
|
||||
leg4 = threading.Thread(target=right4, args=())
|
||||
leg5 = threading.Thread(target=right5, args=())
|
||||
leg0.start()
|
||||
leg2.start()
|
||||
leg4.start()
|
||||
leg0.join()
|
||||
leg2.join()
|
||||
leg4.join()
|
||||
time.sleep(1)
|
||||
leg1.start()
|
||||
leg3.start()
|
||||
leg5.start()
|
||||
leg1.join()
|
||||
leg3.join()
|
||||
leg5.join()
|
||||
|
||||
88
old_stuff/thr3.py
Normal file
88
old_stuff/thr3.py
Normal file
@@ -0,0 +1,88 @@
|
||||
import threading
|
||||
import time
|
||||
from adafruit_servokit import ServoKit
|
||||
|
||||
# Initialize ServoKit
|
||||
kit = ServoKit(channels=16)
|
||||
|
||||
# Constants for angles
|
||||
ANGLE_START = 0
|
||||
ANGLE_MIDDLE = 110
|
||||
ANGLE_NEUTRAL = 55
|
||||
|
||||
# Constants for delay
|
||||
DELAY = 1
|
||||
|
||||
# Movement functions
|
||||
def move_leg(servo1, servo2):
|
||||
"""Moves a pair of servos synchronously and prints their positions."""
|
||||
kit.servo[servo1].angle = ANGLE_START
|
||||
kit.servo[servo2].angle = ANGLE_START
|
||||
print(f"Servos {servo1} and {servo2} set to ANGLE_START: {ANGLE_START}")
|
||||
time.sleep(DELAY)
|
||||
|
||||
kit.servo[servo1].angle = ANGLE_MIDDLE
|
||||
print(f"Servo {servo1} set to ANGLE_MIDDLE: {ANGLE_MIDDLE}")
|
||||
time.sleep(DELAY)
|
||||
|
||||
kit.servo[servo2].angle = ANGLE_MIDDLE
|
||||
print(f"Servo {servo2} set to ANGLE_MIDDLE: {ANGLE_MIDDLE}")
|
||||
time.sleep(DELAY)
|
||||
|
||||
kit.servo[servo1].angle = ANGLE_NEUTRAL
|
||||
print(f"Servo {servo1} set to ANGLE_NEUTRAL: {ANGLE_NEUTRAL}")
|
||||
|
||||
kit.servo[servo2].angle = ANGLE_NEUTRAL
|
||||
print(f"Servo {servo2} set to ANGLE_NEUTRAL: {ANGLE_NEUTRAL}")
|
||||
|
||||
def left_leg_0():
|
||||
move_leg(0, 6)
|
||||
|
||||
def left_leg_1():
|
||||
move_leg(1, 7)
|
||||
|
||||
def left_leg_2():
|
||||
move_leg(2, 8)
|
||||
|
||||
def right_leg_3():
|
||||
move_leg(3, 9)
|
||||
|
||||
def right_leg_4():
|
||||
move_leg(4, 10)
|
||||
|
||||
def right_leg_5():
|
||||
move_leg(5, 11)
|
||||
|
||||
# List of leg movements
|
||||
def group_1():
|
||||
threads = [
|
||||
threading.Thread(target=left_leg_0),
|
||||
threading.Thread(target=left_leg_2),
|
||||
threading.Thread(target=right_leg_4),
|
||||
]
|
||||
for thread in threads:
|
||||
thread.start()
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
|
||||
def group_2():
|
||||
threads = [
|
||||
threading.Thread(target=left_leg_1),
|
||||
threading.Thread(target=right_leg_3),
|
||||
threading.Thread(target=right_leg_5),
|
||||
]
|
||||
for thread in threads:
|
||||
thread.start()
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
|
||||
# Main loop
|
||||
if __name__ == "__main__":
|
||||
while True:
|
||||
print("Executing Group 1 movements...")
|
||||
group_1()
|
||||
time.sleep(DELAY)
|
||||
|
||||
print("Executing Group 2 movements...")
|
||||
group_2()
|
||||
time.sleep(DELAY)
|
||||
Reference in New Issue
Block a user