@@ -190,15 +190,15 @@ def lswing_to_estance(osl: OpenSourceLeg) -> bool:
190190 actuators = {
191191 "knee" : DephyActuator (
192192 tag = "knee" ,
193- port = "/dev/ttyACM1 " ,
193+ port = "/dev/ttyACM0 " ,
194194 gear_ratio = GEAR_RATIO ,
195195 frequency = FREQUENCY ,
196196 debug_level = 0 ,
197197 dephy_log = False ,
198198 ),
199199 "ankle" : DephyActuator (
200200 tag = "ankle" ,
201- port = "/dev/ttyACM0 " ,
201+ port = "/dev/ttyACM1 " ,
202202 gear_ratio = GEAR_RATIO ,
203203 frequency = FREQUENCY ,
204204 debug_level = 0 ,
@@ -211,21 +211,25 @@ def lswing_to_estance(osl: OpenSourceLeg) -> bool:
211211 # calibration_matrix=LOADCELL_CALIBRATION_MATRIX,
212212 # ),
213213 "loadcell" : NBLoadcellDAQ (
214- LOADCELL_CALIBRATION_MATRIX , tag = "loadcell" , excitation_voltage = 5.0 , amp_gain = [34 ] * 3 + [151 ] * 3
214+ LOADCELL_CALIBRATION_MATRIX ,
215+ tag = "loadcell" ,
216+ excitation_voltage = 5.0 ,
217+ amp_gain = [34 ] * 3 + [151 ] * 3 ,
218+ spi_bus = 1 ,
215219 ),
216220 "joint_encoder_knee" : AS5048B (
217221 tag = "joint_encoder_knee" ,
218- bus = 3 ,
219- A1_adr_pin = True ,
222+ bus = "/dev/i2c-2" ,
223+ A1_adr_pin = False ,
220224 A2_adr_pin = False ,
221225 zero_position = 0 ,
222226 enable_diagnostics = False ,
223227 ),
224228 "joint_encoder_ankle" : AS5048B (
225229 tag = "joint_encoder_ankle" ,
226- bus = 2 ,
230+ bus = "/dev/i2c-3" ,
227231 A1_adr_pin = False ,
228- A2_adr_pin = True ,
232+ A2_adr_pin = False ,
229233 zero_position = 0 ,
230234 enable_diagnostics = False ,
231235 ),
@@ -245,10 +249,25 @@ def lswing_to_estance(osl: OpenSourceLeg) -> bool:
245249
246250 osl_fsm = create_simple_walking_fsm (osl )
247251
252+ # Zeroing the joint encoders
253+ def knee_homing_complete ():
254+ osl .joint_encoder_knee .update ()
255+ osl .joint_encoder_knee .zero_position = osl .joint_encoder_knee .counts
256+ print ("Knee homing complete!" )
257+
258+ def ankle_homing_complete ():
259+ osl .joint_encoder_ankle .update ()
260+ # The hard stop for ankle is at 30 deg from the zero position
261+ osl .joint_encoder_ankle .zero_position = osl .joint_encoder_ankle .counts - osl .joint_encoder_ankle .deg_to_counts (
262+ 30
263+ )
264+ print ("Ankle homing complete!" )
265+
266+ callbacks = {"knee" : knee_homing_complete , "ankle" : ankle_homing_complete }
267+
248268 with osl , osl_fsm :
249269 osl .update ()
250- osl .home ()
251-
270+ osl .home (callbacks = callbacks )
252271 input ("Press Enter to start walking..." )
253272
254273 # knee
@@ -261,20 +280,25 @@ def lswing_to_estance(osl: OpenSourceLeg) -> bool:
261280 osl .ankle .set_impedance_cc_pidf_gains ()
262281 osl .ankle .set_output_impedance ()
263282
283+ osl .loadcell .reset ()
284+ osl .loadcell .calibrate ()
285+
264286 for t in clock :
265287 osl .update ()
288+ print ("Ankle position" , np .rad2deg (osl .sensors ["joint_encoder_ankle" ].position ))
289+ print ("Knee position" , np .rad2deg (osl .sensors ["joint_encoder_knee" ].position ))
266290 osl_fsm .update (osl = osl )
267- osl .knee .set_output_impedance (
268- k = osl_fsm .current_state .knee_stiffness ,
269- b = osl_fsm .current_state .knee_damping ,
270- )
271- osl .ankle .set_output_impedance (
272- k = osl_fsm .current_state .ankle_stiffness ,
273- b = osl_fsm .current_state .ankle_damping ,
274- )
275-
276- osl .knee .set_output_position (np .deg2rad (osl_fsm .current_state .knee_theta ))
277- osl .ankle .set_output_position (np .deg2rad (osl_fsm .current_state .ankle_theta ))
291+ # osl.knee.set_output_impedance(
292+ # k=osl_fsm.current_state.knee_stiffness,
293+ # b=osl_fsm.current_state.knee_damping,
294+ # )
295+ # osl.ankle.set_output_impedance(
296+ # k=osl_fsm.current_state.ankle_stiffness,
297+ # b=osl_fsm.current_state.ankle_damping,
298+ # )
299+
300+ # osl.knee.set_output_position(np.deg2rad(osl_fsm.current_state.knee_theta))
301+ # osl.ankle.set_output_position(np.deg2rad(osl_fsm.current_state.ankle_theta))
278302
279303 fsm_logger .info (
280304 f"T: { t :.3f} s, "
0 commit comments