-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #276 from neurobionics/integration
Final dephy debugging
- Loading branch information
Showing
4 changed files
with
116 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,102 @@ | ||
import time | ||
# import time | ||
# import sys | ||
# from opensourceleg.actuators.base import CONTROL_MODES | ||
# import opensourceleg.actuators.dephy as Dephy | ||
# from opensourceleg.logging.logger import LOGGER | ||
|
||
# actpack = Dephy.DephyActuator( | ||
# port="/dev/ttyACM0", | ||
# gear_ratio=1.0, | ||
# ) | ||
|
||
# with actpack: | ||
|
||
# actpack.set_control_mode(mode=CONTROL_MODES.VOLTAGE) | ||
|
||
# while True: | ||
# actpack.set_motor_voltage(value=3000) # in mV | ||
# actpack.update() | ||
# LOGGER.info( | ||
# "".join( | ||
# f"Motor Position: {actpack.motor_position}\t" | ||
# + f"Case Temperature: {actpack.case_temperature}" | ||
# + f"Winding Temperature: {actpack.winding_temperature}" | ||
# ) | ||
# ) | ||
# time.sleep(0.005) | ||
|
||
|
||
|
||
import time | ||
|
||
import pandas as pd | ||
|
||
from opensourceleg.actuators.base import CONTROL_MODES | ||
import opensourceleg.actuators.dephy as Dephy | ||
from opensourceleg.logging.logger import LOGGER | ||
from opensourceleg.time import SoftRealtimeLoop | ||
|
||
TIME_TO_STEP = 1.0 | ||
FREQUENCY = 200 | ||
DT = 1 / FREQUENCY | ||
|
||
|
||
actpack = Dephy.DephyActuator( | ||
port="/dev/ttyACM0", | ||
gear_ratio=1.0, | ||
) | ||
with actpack: | ||
try: | ||
actpack.set_control_mode(mode=actpack.CONTROL_MODES.VOLTAGE) | ||
while True: | ||
actpack.set_motor_voltage(value=3000) # in mV | ||
actpack.update() | ||
LOGGER.info( | ||
"".join( | ||
f"Motor Position: {actpack.motor_position}\t" | ||
+ f"Motor Voltage: {actpack.motor_voltage}\t" | ||
+ f"Motor Current: {actpack.motor_current}\t" | ||
def main(): | ||
actpack = Dephy.DephyActuator( | ||
port="/dev/ttyACM0", | ||
gear_ratio=1.0, | ||
) | ||
voltage_data = pd.DataFrame( | ||
{ | ||
"Time": [], | ||
"Output_Voltage": [], | ||
"Command_Voltage": [], | ||
} | ||
) | ||
clock = SoftRealtimeLoop(dt=DT) | ||
with actpack: | ||
|
||
try: | ||
actpack.set_control_mode(mode=CONTROL_MODES.VOLTAGE) | ||
|
||
for t in clock: | ||
|
||
if t > TIME_TO_STEP: | ||
command_voltage = 3000 | ||
actpack.set_motor_voltage(value=command_voltage) # in mV | ||
|
||
else: | ||
command_voltage = 0 | ||
|
||
actpack.update() | ||
|
||
LOGGER.info( | ||
"".join( | ||
f"Motor Position: {actpack.motor_position}\t" | ||
+ f"Motor Voltage: {actpack.motor_voltage}\t" | ||
+ f"Motor Current: {actpack.motor_current}\t" | ||
) | ||
) | ||
voltage_data = pd.concat( | ||
[ | ||
voltage_data, | ||
pd.DataFrame( | ||
{ | ||
"Time": [t], | ||
"Output_Voltage": [actpack.motor_voltage], | ||
"Command_Voltage": [command_voltage], | ||
} | ||
), | ||
], | ||
ignore_index=True, | ||
) | ||
) | ||
time.sleep(0.005) | ||
|
||
except KeyboardInterrupt: | ||
exit() | ||
time.sleep(DT) | ||
|
||
finally: | ||
voltage_data.to_csv("voltage_data_dephy.csv", index=False) | ||
exit() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |