-
Notifications
You must be signed in to change notification settings - Fork 6
v1 Loading Code
This chapter will cover setting of all parameters and programming of the Arduino micro controller for the arm. Coding experience is not necessary.
Please find below an overview of the basic logic and flow of the Arduino code for the El Medallo arm. Please keep reading for more detail on exactly what each parameter controls.
The Arduino code can be found here.
We recommend loading the code on using the official Arduino IDE.
The download link can be found here.
The code when opened in the IDE should look something like this:
In the following section you will find:
- A full list of the parameters in the code that you may or will need to modify
- An explanation of their purposes
- Recommended values for them (or in the case that they will need to be modified, recommended initial values to start your calibration at).
If you follow our recommended component list and circuit diagram than this will not need to be changed.
If you do choose to change the pin layout, then you will need to modify the circuit diagram to correspond to your new layout.
// Define pins
#define servoPin 9
#define servoPin2 11
#define lockSwitchPin 10
#define buttonPin A1
#define sensorPin A0 // EMG sensor 1, corresponds to servo 1 closing first
#define sensorPin2 A2 // EMG sensor 2, corresponds to servo 2 closing first
These parameters can be set to high to enable system debugging messages over the Serial port. When they are set to 1 (high), the debugging messages will print.
The EMGDebugging mode will be used when calibrating the EMG sensors for each patient.
They should both be set to 0 for the arm to be functional.
// Debugging options - 1 to show signals over serial interface (to viewed by Serial Monitor or Serial Plotter)
boolean EMGDebugging = 0;
boolean lockSwitchDebugging = 0;
| Mode | Description |
|---|---|
| EMGDebugging | Enables printing of 4 variables for each sensor. The 4 variables are: |
| . | emg_signal = The filtered analogue sensor data |
| . | state = The processed binary state of the signal |
| . | background = The background sensor level |
| . | transient_signal = The transient component of the signal (emg_signal - background). |
| lockSwitchDebugging | Enables printing of counter used for debouncing of the lock switch. |
// Set constants
const int OPEN_POS = 0;
const int CLOSED_POS_GRIP1 = 180; // Motor angles in degrees
const int CLOSED_POS_GRIP2 = 180;
const int OPEN_POS2 = 180;
const int CLOSED_POS2_GRIP1 = 0;
const int CLOSED_POS2_GRIP2 = 0;
const int DELAY_TIME_GRIP1 = 300; // Delay in milliseconds
const int DELAY_TIME_GRIP2 = 300;
const int SERVO_TIMEOUT_TIME = 1500; // Time after which the servos will stop trying to turn and the arm will be available for another grip
const int lockSwitchDelayTime = 20; // Lockswitch debouncing constants
const int lockSwitchCounterLimit = 30; // Lockswitch debouncing constants
Please find below a table detailing the constants that you will need to change in order to calibrate each hand. For each constant we have given a value that you can start with.
You may want to change these values to calibrate:
- How far the hand opens and closes for each grip type.
- Relative times for which each finger closes.
| Constant | Description | Value |
|---|---|---|
| OPEN_POS | The open position (deg) of Servo Motor 1. | 0 |
| CLOSED_POS_GRIP1 | The closed position (deg) of Servo 1 in Grip 1. | 180 |
| CLOSED_POS_GRIP2 | The closed position (deg) of Servo 1 in Grip 2. | 180 |
| OPEN_POS2 | The open position (deg) of Servo 2. | 180 |
| CLOSED_POS2_GRIP1 | The closed position (deg) of Servo 2 in Grip 1. | 0 |
| CLOSED_POS2_GRIP2 | The closed position (deg) of Servo 2 in Grip 2. | 0 |
| DELAY_TIME_GRIP1 | Delay-time (ms) between Servo 1 and Servo 2 for Grip 1. | 300 |
| DELAY_TIME_GRIP2 | Delay-time (ms) between Servo 2 and Servo 1 for Grip 2. | 300 |
| SERVO_TIMEOUT_TIME | Time (ms) after which motors will time out (to save power and prevent crushing objects). | 1500 |
These parameters are used to:
- Activate and disactivate motors
- Change sensor types, sensors positions
- Activate the lock switch
- Toggle input between the EMG sensors and the debugging button
// Setup parameters
boolean buttonFlag = 0; // 0 to use EMG sensors; 1 to use button
boolean lockSwitchFlag = 1; // 0 to have lockswitch toggle between which EMG signal the button simulates; 1 to use lockswitch as a lock switch
boolean motorFlag1 = 1; // 0 to disable motor; 1 to enable
boolean motorFlag2 = 1; // 0 to disable motor; 1 to enable
boolean sensorType = 1; // 0 for Protesis Avanzada; 1 for OYMotion
boolean sensorType2 = 1; // 0 for Protesis Avanzada; 1 for OYMotion
int sensorFlag = 2; // 0 to disable sensor; 1 for bicep; 2 for forearm
int sensorFlag2 = 1; // 0 for disable sensor; 1 for bicep; 2 for forearm
Please find below an explanation of each parameter and recommended values for them.
Please note:
- The flag being "off" or "low" means having a value of 0 assigned.
- The flag being "on" or "high" means having a value of 1 assigned.
| Parameter | Description | Value |
|---|---|---|
| buttonFlag | When high, the processed EMG signals will be simulated by the pressing of the debug button. On each button press, the hand will toggle between open and closed position. By default Grip 1 will be triggered. If lockSwitchFlag is low and the lock switch is on, then Grip 2 will be triggered on each button press instead. |
0 |
| lockSwitchFlag | When this is high, the lock switch being on will cause the fingers to lock in position and not to move regardless of EMG sensor or debug button input. When it is low and buttonFlag is high, the lock switch can be used to toggle which grip the debug button will trigger (see above). | 1 |
| motorFlag1 | High to enable Motor 1; low to disable. | 1 |
| motorFlag2 | High to enable Motor 2; low to disable. | 1 |
| sensorType | Sensor type for Sensor 1. 0 if using the Protesis Avanzadas proprietary sensor; 1 if using the OYMotion sensor (recommended). | 1 |
| sensorType2 | Sensor type for Sensor 2 (as above). | 1 |
| sensorFlag | Position for Sensor 1. 0 to disable; 1 if mounted on patient bicep; 2 if mounted on patient forearm. | |
| sensorFlag2 | Position for Sensor 2 (as above). |
A much more detailed explanation on the EMG parameters and advice on setting their values can be found here.
A brief summary of the changeable parameters can be found below.
// Calibration parameters
float threshold_oy_forearm = .53;
float rise_time_oy_forearm = 2;
float fall_time_oy_forearm = 1000;
float threshold_pa_forearm = .5;
float rise_time_pa_forearm = 100;
float fall_time_pa_forearm = 1000;
float threshold_oy_bicep = .46;
float rise_time_oy_bicep = 2;
float fall_time_oy_bicep = 1000;
float threshold_pa_bicep = .5;
float rise_time_pa_bicep = 100;
float fall_time_pa_bicep = 1000;
| Parameter | Description |
|---|---|
| threshold_X_Y | The level that the transient portion of the EMG signal transient_signal must surpass to trigger a grip for sensor type X in position Y. |
| rise_time_X_Y | The average time that it takes for the transient portion of the EMG signal to increase from 10% to 90% of it's active value for sensor type X in position Y. |
| fall_time_X_Y | The average time that it takes for the transient portion of the EMG signal to decrease from 90% to 10% of it's active value for sensor type X in position Y. |
Once you have your code prepared you can load it onto the Arduino.
- Connect the Arduino Beetle to your computer using a USB cable.
- Choose Tools→Board→Leonardo to find your board in the Arduino menu. This changes how the program compiles to ensure it will work correctly for any particular arduino.
- Choose the correct serial port for your board. Choose Tools→Serial Port→comX and select the port marked with an arduino connected. In Windows the arduino should appear automatically in this list, if it does not try unplugging and plugging it back in.
- Click the Upload button. This is the button that points to the right in the bottom of the Arduino IDE. You can also use the keyboard shortcut Ctrl+U for Windows.
To test the code you can wire everything up by breadboard as suggested here or test your already finished circuit.
If you have any questions please send a email to enablemedellin@gmail.com with your name (+organisation), question and a link to the relevant GitHub wiki page. The email will be forwarded to the relevant team member, your question can be answered the documentation can be updated. You can also leave a question or problem as an issue on this repository.