Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
9ef67cb37d | |||
|
ce5fc4c445 |
7 changed files with 71 additions and 41 deletions
89
PWMDriver.py
89
PWMDriver.py
|
@ -1,38 +1,51 @@
|
||||||
from Adafruit_PCA9685 import PCA9685
|
from Adafruit_PCA9685 import PCA9685
|
||||||
|
|
||||||
class PWMDriver:
|
class PWMDriver:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.driver = PCA9685()
|
self.driver = PCA9685()
|
||||||
self.driver.set_pwm_freq(50)
|
self.driver.set_pwm_freq(50)
|
||||||
self.servoProfiles = {
|
self.servoProfiles = {
|
||||||
'default': {'range': 180, 'min': 65, 'max': 530},
|
'default': {'range': 180, 'min': 65, 'max': 530},
|
||||||
'lidar': {'range': 180, 'min': 75, 'max': 510},
|
'lidar': {'range': 180, 'min': 75, 'max': 510},
|
||||||
'china': {'range': 180, 'min': 75, 'max': 510},
|
'china': {'range': 180, 'min': 75, 'max': 510},
|
||||||
'flag': {'range': 180, 'min': 100, 'max': 480},
|
'flag': {'range': 180, 'min': 100, 'max': 480},
|
||||||
'rev': {'range': 270, 'min': 95, 'max': 600}, # 552
|
'rev': {'range': 270, 'min': 95, 'max': 600}, # 552
|
||||||
}
|
}
|
||||||
|
|
||||||
def setAngle(self, slot, angle, profileName = 'default'):
|
|
||||||
profile = None
|
#définir la fréquence du signal de sortie à 50hz
|
||||||
if type(profileName) is dict:
|
def ini_esc(slot):
|
||||||
profile = profileName
|
slef.driver.set_pwm(slot,0,307) #307 est le signal neutre sous 50 Hz (1.5 / 20 x 4096 = 307)
|
||||||
if profile == None:
|
time.sleep(1)
|
||||||
if profileName not in self.servoProfiles:
|
|
||||||
profileName = 'default'
|
def initialiser_esc():
|
||||||
profile = self.servoProfiles[profileName]
|
HZ = 50 #fréquence du signal vers les ESC
|
||||||
if 'range' not in profile:
|
self.driver.set_pwm_freq(HZ)
|
||||||
profile['range'] = 180
|
LESC = (1, 13, 8, 9) #liste des ESC (avant gauche, avant droit, arrière gauche, arrière droit)
|
||||||
if angle < 0 or angle > profile['range']:
|
ini_esc(LESC[0])
|
||||||
print('PWMDriver: Invalid range passed ' + angle + ' but range is ' + profile['range'])
|
ini_esc(LESC[1])
|
||||||
if slot > 15 or slot < 0:
|
ini_esc(LESC[2])
|
||||||
print('> ERR!!! Invalid slot passed to setAngle!')
|
ini_esc(LESC[3])
|
||||||
return
|
def setAngle(self, slot, angle, profileName = 'default'):
|
||||||
pulse = int(self.mappyt(angle, 0, profile['range'], profile['min'], profile['max']))
|
profile = None
|
||||||
#print('setting slot', slot, 'to angle', angle, 'with profile', profileName, profile, pulse)
|
if type(profileName) is dict:
|
||||||
self.driver.set_pwm(slot, 0, pulse)
|
profile = profileName
|
||||||
|
if profile == None:
|
||||||
def setPwm(self, slot, off, on):
|
if profileName not in self.servoProfiles:
|
||||||
self.driver.set_pwm(slot, off, on)
|
profileName = 'default'
|
||||||
|
profile = self.servoProfiles[profileName]
|
||||||
def mappyt(self, x, inMin, inMax, outMin, outMax):
|
if 'range' not in profile:
|
||||||
return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin
|
profile['range'] = 180
|
||||||
|
if angle < 0 or angle > profile['range']:
|
||||||
|
print('PWMDriver: Invalid range passed ' + angle + ' but range is ' + profile['range'])
|
||||||
|
if slot > 15 or slot < 0:
|
||||||
|
print('> ERR!!! Invalid slot passed to setAngle!')
|
||||||
|
return
|
||||||
|
pulse = int(self.mappyt(angle, 0, profile['range'], profile['min'], profile['max']))
|
||||||
|
#print('setting slot', slot, 'to angle', angle, 'with profile', profileName, profile, pulse)
|
||||||
|
self.driver.set_pwm(slot, 0, pulse)
|
||||||
|
def setPwm(self, slot, off, on):
|
||||||
|
#self.driver.set_pwm(slot, off, on)
|
||||||
|
self.driver.set_pwm(slot, off,on)
|
||||||
|
def mappyt(self, x, inMin, inMax, outMin, outMax):
|
||||||
|
return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin
|
||||||
|
|
|
@ -16,7 +16,7 @@ class MotorizedPlatform:
|
||||||
}
|
}
|
||||||
escMapping = {
|
escMapping = {
|
||||||
'frontLeft': {
|
'frontLeft': {
|
||||||
'slot': 12, # 7
|
'slot': 1, # 7
|
||||||
'range': [307, 410]
|
'range': [307, 410]
|
||||||
},
|
},
|
||||||
'frontRight': {
|
'frontRight': {
|
||||||
|
@ -43,9 +43,9 @@ class MotorizedPlatform:
|
||||||
def init(self):
|
def init(self):
|
||||||
print("drive init start")
|
print("drive init start")
|
||||||
v = self.escMapping['turbine']
|
v = self.escMapping['turbine']
|
||||||
for i in range(220, 250, 1):
|
for i in range(240, 250, 1):
|
||||||
drive.setPwm(v['slot'], 0, i)
|
drive.setPwm(v['slot'], 0, i)
|
||||||
sleep(0.04)
|
sleep(0.02)
|
||||||
drive.setPwm(v['slot'], 0, 0)
|
drive.setPwm(v['slot'], 0, 0)
|
||||||
print("drive init stop")
|
print("drive init stop")
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
BIN
__pycache__/test_by_motor.cpython-39.pyc
Normal file
BIN
__pycache__/test_by_motor.cpython-39.pyc
Normal file
Binary file not shown.
4
robot_manual.py
Normal file
4
robot_manual.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import RobotCompleteCOde
|
||||||
|
r = RobotCompletCode.MotorizedPlatform()
|
||||||
|
s = r.setSpeed
|
||||||
|
|
13
test_by_motor.py
Normal file
13
test_by_motor.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
from RobotCompletCode import MotorizedPlatform
|
||||||
|
m = MotorizedPlatform()
|
||||||
|
def frontLeft(speed):
|
||||||
|
m.setSpeed({"frontLeft":speed})
|
||||||
|
|
||||||
|
def frontRight(speed):
|
||||||
|
m.setSpeed({"frontRight":speed})
|
||||||
|
|
||||||
|
def backLeft(speed):
|
||||||
|
m.setSpeed({"backLeft":speed})
|
||||||
|
|
||||||
|
def backRight(speed):
|
||||||
|
m.setSpeed({"backRight":speed})
|
Loading…
Reference in a new issue