Python Controls

Below, you’ll find instructional videos that show how to control the Dephy actuators on the knee and ankle.  In general, commands are sent via a digital bus from a single board computer (e.g. Raspberry Pi) to the actuators, which can enable development of state machines, or other high level control architectures. To begin, you will first need a functioning Raspberry Pi, which if you do not have this yet, click here to be transferred to a page that walks through setting up the Raspberry Pi for control of the OSL.   Otherwise, see the control examples below, which can be thought of as the basic building blocks for most control strategies, and can be used as example code when developing your own control strategy.

  1. Read the safety warnings on the Dephy Wiki.
  2. Power the Raspberry Pi via the micro-USB port on the Pi using a computer, a simple wall outlet, or another power source. Wirelessly connect (i.e. SSH) to the Pi from your computer.  If you have not connected wirelessly to the Pi before, see instructions here.
  3. For safety precautions, connect Dephy actuators to a power supply and not batteries for preliminary tests. If a power supply is unavailable and batteries must be used, be sure to use low gain values for current and position controls in future tests. It is also recommended the OSL be used with the E-Stop, an emergency stop button that can quickly stop electrical power to the OSL. 
  4. Connect the actuators to the Raspberry Pi via the USB port on the Raspberry Pi and the micro-USB port on the actuators–use a USB isolator whenever possible which will help protect the Raspberry Pi and Dephy actuators, in the case of any mishaps.
  5. In the command line of Terminal or PuTTY, type “cd code/Actuator-Package/Python_deprecated” and press Enter. You are now in the directory with all of the base-line functions.

When using a USB cable to control the actuator, THE USB CONNECTION TO THE BOARD MUST BE STRESS RELIEVED.  Ideally, use a 90 degree connector to minimize the bending moment on the board’s micro-USB connector.  If it’s not properly stress relieved, the connector can break off the board, and the entire board becomes useless.  Then no one is happy.

Note: We have recently rolled back to an earlier version of the control libraries, due to some challenges with the latest versions.  The ‘deprecated’ Python libraries only allow for control of one actuator per script. If multiple actuators are needed to be controlled, multiple scripts must be run simultaneously with UDP communication from one script to another.  This communication permits sharing of data, and higher level state information.  Stay tuned for updated Dephy Python libraries that allow for controlling more than one actuator per script. We will be updating this page soon to describe the latest version of the libraries.

Find Ports Function

The function outputs all the ports that are currently being used on the Raspberry Pi. If there are ever errors in accessing a port, you can run the function and see which ports are in use.

  1. Turn the Dephy actuator on by pressing the center button, and holding for two seconds.
  2. Type “python3” and press Enter.
  3. If your actuator is plugged in and turned on, one of the ports should be “ttyACM0” if you are using a Mac, or “COM5” if you are using a Windows computer. There should be two other ports listed as well. If there are two actuators plugged in and turned on, then there should be four ports shown.

Read Only Outputs Function

The Read Only function outputs the sensor data from the Dephy actuators.  This is an example of the data you can acquire using the actuators.

  1. Type “python3” and press Enter.
  2. Move the actuator around translationally and rotationally and observe the changing parameters.
  3. Press “Control+c” to quit out of the function.

Position Control Function

The position control function provides a reference position command / controller gains to the internal feedback controller within the Dephy actuator.  The reference command can be updated using the Raspberry Pi, and example of which is shown below.  In this example, the controller will hold a single position, and the controller effort can be felt by interacting with the output shaft.

    1. Type “python3” and press Enter.
    2. Rotate the actuator, and observe the resistance and how it returns to its initial position.
    3. Press “Control+c” to quit out of the function.

Two Position Control Function

The Two Position Control function provides an alternating reference signal, between two position targets.

  1. Type “python3”, press Enter, and observe the actuator.
  2. Press “Control+c” to quit out of the function.

Open Speed Function

The Open Speed function will directly control the actuators PWM duty cycle–so no closed loop feedback is occurring on the drive locally when Open-Speed is used.  In this example, the speed (i.e. PWM duty cycle) is a trapezoid, ramping speed up to a constant velocity, then reducing the speed back to zero.

  1. Type “python3”, press Enter, and observe the actuator.
  2. Press “Control+c” to exit out of the function.

Impedance Control Function

The Impedance Control function enables the actuator to prescribe a set of dynamics between the input (position) and output (motor current, as a proxy for torque).   The gains represent the stiffness and damping coefficients that are rendered by the actuator, as well as the set-point or equilibrium position.  High stiffness and damping gains will track a position trajectory similar to a PD controller (if the derivative term is operating on the feedback path, rather than on the error).

  1. Type “python3” and press Enter.
  2. Try to rotate the actuator to a different angle. Notice the change in stiffness when rotating the motor and the change in damping when releasing the motor as the two states are cycled.
  3. Press “Control+c” to quit out of the function.
  4. If you would like to change the stiffness and damping coefficients of the states, type “sudo nano” and press enter.
  5. Near the top of the code, there’s a section labeled Impedance Gains. In this section alter the values for K and B for both states. Press “Control+x”, “y”, and then Enter to save the file. Re-run the code and observe the difference in functionality.

Current Control Function

The Current Control function tracks a reference current–this is analogous to torque control.  Similar to the other closed loop control strategies, the reference is provided by the high-level Raspberry Pi, and the loops are closed on the drive. If there is no external torque placed on the actuator, then the motor will continue to accelerate. Be sure to slow down the motor every once in a while so as not to reach too high of speeds.

  1. Type “python3” and press Enter.
  2. As the actuator accelerates, provide an external torque to slow it down every few seconds.
  3. Press “Control+c” to exit the function.

Knee and Ankle Homing Functions

The homing functions for the knee and ankle initialize the relationship between the motor and joint encoders. After running these functions, the motors can accurately move the knee or ankle to a given position based on the correspondence between motor angle and joint angle. These homing functions must be performed prior to executing the walking functions every time the OSL turns on.

  1. Type “python3” and press Enter
  2. Observe the knee perform its homing routine
  3. Type “python3” and press Enter
  4. Observe the ankle perform its homing routine