Initial commit
This commit is contained in:
5
Divers/odrive/README.md
Normal file
5
Divers/odrive/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Parlons actuator, odrive, moteur ...
|
||||
## Exemple de code avec la carte odrive robotics
|
||||
|
||||
La vidéo de ce tutoriel est disponible à l'adresse suivante: https://www.youtube.com/watch?v=Mg-KiG3Rq2Q
|
||||
|
||||
49
Divers/odrive/test0.py
Normal file
49
Divers/odrive/test0.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import time
|
||||
import odrive
|
||||
from odrive.enums import *
|
||||
|
||||
accel=30.
|
||||
vel=4.
|
||||
calibration=False
|
||||
|
||||
odrv0=odrive.find_any(serial_number='205C3690424D')
|
||||
|
||||
if calibration:
|
||||
print("Calibration...", end='', flush=True)
|
||||
odrv0.axis0.requested_state=4
|
||||
odrv0.axis1.requested_state=4
|
||||
|
||||
while odrv0.axis0.current_state != AXIS_STATE_IDLE:
|
||||
time.sleep(0.1)
|
||||
while odrv0.axis1.current_state != AXIS_STATE_IDLE:
|
||||
time.sleep(0.1)
|
||||
print("OK")
|
||||
|
||||
odrv0.axis0.controller.config.input_mode=INPUT_MODE_TRAP_TRAJ
|
||||
odrv0.axis0.trap_traj.config.vel_limit=vel
|
||||
odrv0.axis0.trap_traj.config.accel_limit=accel
|
||||
odrv0.axis0.trap_traj.config.decel_limit=accel
|
||||
odrv0.axis0.controller.config.inertia=0
|
||||
|
||||
odrv0.axis1.controller.config.input_mode=INPUT_MODE_TRAP_TRAJ
|
||||
odrv0.axis1.trap_traj.config.vel_limit=vel
|
||||
odrv0.axis1.trap_traj.config.accel_limit=accel
|
||||
odrv0.axis1.trap_traj.config.decel_limit=accel
|
||||
odrv0.axis1.controller.config.inertia=0
|
||||
|
||||
odrv0.axis0.requested_state=AXIS_STATE_CLOSED_LOOP_CONTROL
|
||||
odrv0.axis1.requested_state=AXIS_STATE_CLOSED_LOOP_CONTROL
|
||||
|
||||
pos0=odrv0.axis0.encoder.pos_estimate
|
||||
pos1=odrv0.axis1.encoder.pos_estimate
|
||||
shift=1/5
|
||||
|
||||
while True:
|
||||
pos0_finale=pos0+shift
|
||||
pos1_finale=pos1+shift
|
||||
odrv0.axis0.controller.input_pos=pos0_finale
|
||||
odrv0.axis1.controller.input_pos=pos1_finale
|
||||
while abs(odrv0.axis0.encoder.pos_estimate-pos0_finale)>0.02 or \
|
||||
abs(odrv0.axis1.encoder.pos_estimate-pos1_finale)>0.02:
|
||||
time.sleep(0.1)
|
||||
shift=-shift
|
||||
55
Divers/odrive/test1.py
Normal file
55
Divers/odrive/test1.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import time
|
||||
import odrive
|
||||
from odrive.enums import *
|
||||
|
||||
accel=10.
|
||||
vel=3.
|
||||
calibration=False
|
||||
|
||||
odrv0=odrive.find_any(serial_number='205C3690424D')
|
||||
|
||||
if calibration:
|
||||
print("Calibration...", end='', flush=True)
|
||||
odrv0.axis0.requested_state=4
|
||||
odrv0.axis1.requested_state=4
|
||||
|
||||
while odrv0.axis0.current_state != AXIS_STATE_IDLE:
|
||||
time.sleep(0.1)
|
||||
while odrv0.axis1.current_state != AXIS_STATE_IDLE:
|
||||
time.sleep(0.1)
|
||||
|
||||
print("OK")
|
||||
|
||||
odrv0.axis0.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
|
||||
odrv0.axis0.controller.config.input_mode = INPUT_MODE_VEL_RAMP
|
||||
odrv0.axis1.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
|
||||
odrv0.axis1.controller.config.input_mode = INPUT_MODE_VEL_RAMP
|
||||
|
||||
odrv0.axis0.controller.config.vel_ramp_rate=accel
|
||||
odrv0.axis1.controller.config.vel_ramp_rate=accel
|
||||
|
||||
odrv0.axis0.requested_state=AXIS_STATE_CLOSED_LOOP_CONTROL
|
||||
odrv0.axis1.requested_state=AXIS_STATE_CLOSED_LOOP_CONTROL
|
||||
|
||||
odrv0.axis0.controller.input_vel=vel
|
||||
odrv0.axis1.controller.input_vel=0
|
||||
|
||||
evenement=time.time()
|
||||
id=0
|
||||
while True:
|
||||
if id==0:
|
||||
torque=odrv0.axis0.motor.current_control.Iq_setpoint*odrv0.axis0.motor.config.torque_constant
|
||||
else:
|
||||
torque=odrv0.axis1.motor.current_control.Iq_setpoint*odrv0.axis1.motor.config.torque_constant
|
||||
if abs(torque)>0.2 and (time.time()-evenement)>1:
|
||||
if id==0:
|
||||
odrv0.axis0.controller.input_vel=0
|
||||
odrv0.axis1.controller.input_vel=vel
|
||||
id=1
|
||||
else:
|
||||
odrv0.axis1.controller.input_vel=0
|
||||
odrv0.axis0.controller.input_vel=vel
|
||||
id=0
|
||||
evenement0=time.time()
|
||||
|
||||
|
||||
40
Divers/odrive/test2.py
Normal file
40
Divers/odrive/test2.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import time
|
||||
import odrive
|
||||
from odrive.enums import *
|
||||
|
||||
accel=20.
|
||||
vel=5.
|
||||
ratio=2
|
||||
calibration=False
|
||||
|
||||
odrv0=odrive.find_any(serial_number='205C3690424D')
|
||||
|
||||
if calibration:
|
||||
print("Calibration...", end='', flush=True)
|
||||
odrv0.axis0.requested_state=4
|
||||
odrv0.axis1.requested_state=4
|
||||
|
||||
while odrv0.axis0.current_state != AXIS_STATE_IDLE:
|
||||
time.sleep(0.1)
|
||||
while odrv0.axis1.current_state != AXIS_STATE_IDLE:
|
||||
time.sleep(0.1)
|
||||
|
||||
print("OK")
|
||||
|
||||
odrv0.axis0.requested_state=AXIS_STATE_CLOSED_LOOP_CONTROL
|
||||
odrv0.axis1.requested_state=AXIS_STATE_CLOSED_LOOP_CONTROL
|
||||
|
||||
odrv0.axis0.controller.config.input_mode = INPUT_MODE_TRAP_TRAJ
|
||||
odrv0.axis0.trap_traj.config.vel_limit=vel
|
||||
odrv0.axis0.trap_traj.config.accel_limit=accel
|
||||
odrv0.axis0.trap_traj.config.decel_limit=accel
|
||||
odrv0.axis0.controller.config.inertia=0
|
||||
|
||||
pos0=odrv0.axis0.encoder.pos_estimate
|
||||
pos1=odrv0.axis1.encoder.pos_estimate
|
||||
|
||||
odrv0.axis1.requested_state=AXIS_STATE_IDLE
|
||||
|
||||
while True:
|
||||
delta1=odrv0.axis1.encoder.pos_estimate-pos1
|
||||
odrv0.axis0.controller.input_pos=pos0+ratio*delta1
|
||||
Reference in New Issue
Block a user