EDITED: 20/01/2023
FD function added in LibreServo v2.1.
I have spent a lot of time on the command part of LibreServo and I think it is one of the most important parts of the project, it is how LibreServo is presented to the user. It offers a flexibility and possibilities that I have never seen in any manufacturer.
The documentation of the commands I will divide it in two articles, this article is more focused on the description of the commands and the second part is focused on examples and explanation of execution in LibreServo.
The LibreServo commands are as follows:
- Motion commands
- Linear Motion [M]
- Trapezoidal Motion [MT]
- Trapezoidal Motion 50% [Mt]
- Accelerated trapezoidal Motion [MA]
- Sine Motion [MS]
- Sine Motion 50% [Ms]
- Hermitic Motion [MH]
- Continuous Motion [MC]
- Continuous Trapezoidal Motion [MCT]
- Continuous Sine Motion [MCS]
- Hermitic Continuous Movement [MCH]
- Motion PWM [MP]
- Free Motor [MF]
- Motor Wait [MW]
- Find Direction [FD]
- Light and sound commands
- Variable read and write commands
Motion commands
These are specific commands for the movement and control of the servomotor. The different motions and their curves are explained in more detail in the article on motion curves.
Linear motion [M]
- S12M12000[:1000]
The notation we see for 12000[:1000] indicates that the M command forces one parameter to be passed, but the second parameter is optional. It also tells us that the ':' character is used to separate the parameters. This notation is used for all other commands.
Returning to the command, the M command is a command in which the servomotor moves at constant speed to the end position.
param2 (optional): the second parameter indicates in milliseconds, ms, the time in which the movement should be completed, if no time is indicated LibreServo will try to arrive as soon as possible. Range: 0, +2.147.483.647
Example:
S12M12000:1000; | Servomotor 12 shall move to position 12000 in 1000 ms (1 second). |
---|
Trapezoidal motion [MT]
- S12MT12000[:150]:1000;
The MT command is a constant acceleration and deceleration motion calculated based on a fixed acceleration duration.
param2 (opcional): acceleration and deceleration time in ms. If not specified, the default value stored in flash (t_ramp_t) is taken. If the acceleration and deceleration time is greater than the total movement time, they are reduced to fit into the total movement time. Range: 0, +2.147.483.647
param3: total movement time. Range: 0, +2.147.483.647
Example:
S12MT-8000:1000; | Servomotor 12 shall move to position -8000 in 1000ms. The ramp time shall be the one that is at t_ramp_t |
---|---|
S12MT-8000:150:1000; | Servomotor 12 shall move to position -8000 in 1000ms. The ramp time shall be 150ms |
Trapezoidal motion 50% [Mt]
- S12Mt12000:1000;
It is the same as MT, but the acceleration time will be half of the total movement time and the deceleration time the other half.
param2: total movement time. Range: 0, +2.147.483.647
Example:
S12MT-8000:1000; | Servomotor 12 shall move to position -8000 in 1000ms. The ramp time shall be 500ms (500*2 = 1000) |
---|
Accelerated trapezoidal motion [MA]
- S12MA12000[:150]:1000;
It is a trapezoidal movement, but instead of indicating the acceleration time, you indicate the desired acceleration and LibreServo calculates the required acceleration and deceleration time.
param2 (opcional): Aceleración y desaceleración de la rampa. If not specified, the default value stored in flash (a_ramp_t) is taken. If the indicated acceleration does not reach the destination, a linear movement will be made. Range: 0, +2.147.483.647
param3: total movement time. Range: 0, +2.147.483.647
Example:
S12MA-8000:1000; | The servomotor 12 shall move to position -8000 in 1000ms. The acceleration of the ramp shall be the one that is at a_ramp_t |
---|---|
S12MA11000:125:1000; | Servomotor 12 shall move to position -8000 in 1000ms. The acceleration of the ramp shall be 125 |
Sine Motion [MS]
- S12MS12000[:150]:1000;
The MS command produces a movement with variable acceleration and deceleration in the form of a sine, hence its name.
param2 (opcional): acceleration and deceleration time in ms. If not specified, the default value stored in flash (t_ramp_s) is taken. If the acceleration and deceleration time is greater than the total movement time, they are reduced to fit into the total movement time. Range: 0, +2.147.483.647
param3: total movement time. Range: 0, +2.147.483.647
Example:
S12MS50000:2000; | Servomotor 12 shall move to position 50000 in 2000ms. The ramp time shall be the one at t_ramp_s |
---|---|
S5MS50000:150:2000; | Servomotor 5 shall move to position 50000 in 2000ms. The ramp time shall be 150ms |
Sine Motion 50% [Ms]
- S12Ms12000:1000;
It is the same as MS, but the acceleration time will be half of the total movement time and the deceleration time the other half.
param2: total movement time. Range: 0, +2.147.483.647
Example:
S8MT-8000:3000; | Servomotor 8 shall move to position -8000 in 3000ms. The ramp time will be 1500ms (1500*2 = 3000) |
---|
Hermitic Movement [MH]
- S12MH12000[:0][:8000][:0]:1000;
As a rule, all movements assume that the servomotor starts a motion from stop and ends stopped, but in this curve we indicate the starting point of movement, the initial speed, the end point and the final speed and LibreServo calculates the entire path. It is ideal for when we want to interrupt a movement and that the servomotor already starts from the speed in which it was, to make complex chained movements ... or to generate different curves to the previous movements.
param2 (opcional): initial velocity. If it is not specified, it is the one it had at the beginning of the movement. Range: -2.147.483.646, +2.147.483.647
param3: final position. Range: -2.147.483.646, +2.147.483.647
param4 (opicional): final velocity. If not specified, it is zero. Range: -2.147.483.646, +2.147.483.647
param5: total movement time. Range: 0, +2.147.483.647
Example:
S7MH12000:1000; | Servomotor 7 will move to position 12000 in 1000ms. The initial position and velocity of the movement will be the one just at the beginning of the curve. It also assumes that the final velocity we want will be zero |
---|---|
S15MH5000:12000:1500; | Servomotor 15 will move to position 12000 in 1500ms. The initial position is 5000, the initial velocity will be the one right at the beginning of the curve and the final one is assumed to be zero |
S3MH1300:0:-12000:-300:4000; | Servomotor 3 will move to position -12000 in 4000ms. The initial position is 1300 with an initial velocity of zero and final velocity of -300 |
Continuous Motion [MC]
- S12MC65535[:1000]
Like Linear Motion, MC behaves in the same way but takes into account the speed of the servomotor and not its position.
param2 (opcional): the second parameter indicates in milliseconds, ms, the time in which the speed should be reached, if no time is indicated LibreServo will try to arrive as soon as possible. Range: 0, +2.147.483.647
Example:
S9MC-131070:1000; | Servomotor 9 should move -2 turns per second (65535*2 = 131070) in 1000 ms (1 second). |
---|
Continuous Trapezoidal Motion [MCT]
- S12MCT65535[:150]:1000;
param2 (opcional): acceleration and deceleration time in ms. If not specified, the default value stored in flash (t_ramp_t) is taken. If the acceleration and deceleration time is greater than the total movement time, they are reduced to fit into the total movement time. Range: 0, +2.147.483.647
param3: total movement time. Range: 0, +2.147.483.647
Example:
S5MCT-32767:1000; | Servomotor 5 shall reach the speed of minus half a revolution per second in 1000ms. The ramp time shall be the one at t_ramp_t |
---|---|
S4MCT-32767:150:1000; | Servomotor 4 shall reach the speed of minus half a revolution per second in 1000ms. The ramp time shall be 150ms |
Continuous Sine Motion [MCS]
- S12MCS65535[:150]:1000;
param2 (opcional): acceleration and deceleration time in ms. If not specified, the default value stored in flash (t_ramp_s) is taken. If the acceleration and deceleration time is greater than the total movement time, they are reduced to fit into the total movement time. Range: 0, +2.147.483.647
param3: total movement time. Range: 0, +2.147.483.647
Example:
S6MCS65535:2000; | The servomotor 6 shall reach the speed of one revolution per second in 2000ms. The ramp time shall be the one at t_ramp_s |
---|---|
S2MCS65535:150:2000; | Servomotor 2 shall reach the speed of one revolution per second in 2000ms. The ramp time shall be 150ms |
Hermitic Continuous Movement [MCH]
- S12MCH12000[:0][:8000][:0]:1000;
In this command we pass the initial and final velocity of the movement as well as the initial and final acceleration that we want and LibreServo calculates the entire path. It is ideal for when we want to interrupt a movement and that the servomotor already starts from the speed in which it was, to make complex chained movements ... or to generate different curves to the previous movements.
param2 (opcional): initial acceleration. If it is not specified, it is the one it had at the beginning of the movement. Range: -2.147.483.646, +2.147.483.647
param3: final speed. Range: -2.147.483.646, +2.147.483.647
param4 (opicional): final acceleration. If not specified, it is zero. Range: -2.147.483.646, +2.147.483.647
param5: total movement time. Range: 0, +2.147.483.647
Example:
S3MCH65535:1000; | Servomotor 3 will reach the speed of one revolution per second in 1000ms. The initial velocity and acceleration of the motion will be whatever it is right at the start of the curve. It also assumes that the final velocity we want will be zero |
---|---|
S7MCH65535:-32767:1500; | The servomotor 7 will reach the speed of minus half a turn per second in 1500ms. The initial speed is one revolution per second, the initial acceleration will be the one just at the beginning of the curve and the final acceleration is assumed to be zero |
S16MCH0:10:131070:-300:4000; | The servomotor 16 will reach the speed of two turns per second in 4000ms. The initial velocity is zero with an initial acceleration of 10 and final acceleration of -300 |
Motion PWM [MP]
- S12MP500[:1000];
To directly control the PWM of the motor, we use the command MP.
param2 (optional): Time that the command will last. If we do not enter time, the command will end immediately but will leave the motor with the PWM we have entered. If time is entered, at the end of the time, the motor will stop.
Example:
S12MP-500; | Servomotor 12 will set a PWM of 500 with negative direction |
---|---|
S10MP300:1000; | Servomotor 10 will set a PWM of 300 for 1000ms |
Free Motor [MF]
- S12MF;
The MF command disables the motor. What it does is to turn off the H-bridge. As soon as another motion command arrives, the H-bridge is automatically enabled.
Example:
S14MF; | Servomotor 14 disables the motor |
---|
Motor Wait [MW]
- S12MW250;
The MW command functions as a Delay. It introduces a wait. It is useful for when we want to send from the same command several tasks that we want to be done separated in time and not one after the other.
Example:
S17MW500; | Servomotor 17 waits 500ms |
---|
Example:
S1FD; | Servomotor 1 seeks motor polarity. |
---|
Light and sound commands
LED RGB [L]
- S12L150:25:210;
The L command controls the color and intensity of the built-in LibreServo RGB LED. Theoretically it could display any color we want.
param2: Green color intensity. Range: 0, +255
param3: Blue color intensity. Range: 0, +255
Example:
S7L150:25:210; | The LED of the servomotor 7 turns lilac |
---|
LED Rainbow [LR]
- S12LR;
The LR command instructs the LED to start rotating through the colors automatically.
Example:
S9LR; | The servo motor LED 9 starts to rotate in colors and intensities automatically |
---|
Tone [T]
- S12T2093:200:50;
The T command attempts to generate a tone using the servo motor itself. No speaker is needed to generate your favorite music! It is recommended to use high frequencies, above 1500Hz, for best performance, sixth or seventh octave onwards depending on each servomotor. At low frequencies it may not sound and instead vibrate the entire servomotor.
param2: Note length in milliseconds. Range: 0, +2.147.483.647
param3: Note amplitude, its volume. Range: 0, +100
Example:
S12T3136:200:50; | Servomotor 12 generates a SOL6 tone lasting 200ms with an amplitude of 50% |
---|
Frequency of musical notes @ciudadpentagrama
Variable read and write commands
Variable read commands are executed from a separate task manager. Within the variables to be recovered, there are RAM variables that are read-only and are not saved after LibreServo is turned off, and there are FLASH variables, which are read and write variables that can be modified and/or saved so that the next time LibreServo is started it will keep the value that we have given it.
The variables are:
ID | Name | R/W | Definition | Default value |
---|---|---|---|---|
0 | Temp_interna | R | Temperature in degrees (x10) as measured internally in the microcontroller | |
1 | Temp_externa | R | Temperature in degrees (x10) measured externally on NTC temperature sensor | |
2 | Temp_interna_raw | R | Direct readout (12 bits) from internal temperature sensor to microcontroller | |
3 | Temp_interna_kalman | R | Internal temperature sensor reading to the microcontroller after Kalman filtering | |
4 | Temp_externa_raw | R | Direct reading (12 bits) of the external temperature sensor NTC | |
5 | Temp_externa_kalman | R | External NTC temperature sensor reading after Kalman filter | |
6 | Voltage | R | Voltage, supply voltage of LibreServo (x100) | |
7 | Voltage_raw | R | Readout (12 bits) of the power supply voltage | |
8 | Voltage_kalman | R | Power supply voltage reading after Kalman filtering | |
9 | Corriente | R | Current consumed by the servomotor in mA | |
10 | Corriente_raw | R | Readout (12 bits) of the current consumed by the servomotor | |
11 | Corriente_kalman | R | Current reading after Kalman filter | |
12 | Encoder_raw | R | Encoder position reading (16 bits) | |
13 | Encoder_kalman | R | Encoder position reading after Kalman filter | |
14 | Velocidad_enc | R | Servomotor speed calculated from encoder position | |
15 | Aceleracion_enc | R | Servomotor acceleration calculated from encoder position | |
16 | Velocidad_sim | R | Servomotor speed calculated with the desired position of the servomotor | |
17 | Aceleracion_sim | R | Servomotor acceleration calculated with the desired position of the servomotor | |
18 | Posicion_objetivo | R | Position LibreServo is marking | |
19 | Error | R | Difference between Posicion_objetivo and encoder reading after Kalman filter (Encoder_kalman) | |
20 | DError | R | Differential error (PID) | |
21 | PDTerm | R | PD Term of the PID | |
22 | Iterm | R | Integral Term of the PID | |
23 | PWM | R | Motor PWM | |
24 | PWM_pre | R | PWM desired before looking to see if current draw is excessive | |
99 | Version_LS | R | LibreServo internal version | |
100 | ID Servomotor | R/W | ID of the servomotor, through which it will listen for commands | 1 |
101 | q_corriente | R/W | Current process uncertainty (x1000) (Kalman) | 1200 |
102 | q_temp_ext | R/W | NTC temperature process uncertainty (x1000) (Kalman) | 1200 |
103 | q_temp_int | R/W | Uncertainty process internal temperature STM32 (x1000) (Kalman) | 1200 |
104 | q_volts | R/W | Process voltage uncertainty (x1000) (Kalman) | 1200 |
105 | q_encoder | R/W | Uncertainty encoder process (x1000) (Kalman) | 1200 |
106 | varianza_corriente | R/W | Current variance (x1000) (Kalman) | 1000 |
107 | varianza_temp_ext | R/W | NTC temperature variance (x1000) (Kalman) | 2500 |
108 | varianza_temp_int | R/W | Variance internal temperature STM32 (x1000) (Kalman) | 150 |
109 | varianza_volts | R/W | Voltage variance (x1000) (Kalman) | 150 |
110 | varianza_encoder | R/W | Encoder variance (x1000) (Kalman) | 5000 |
111 | vel_serie | R/W | Serial port speed | 115200 |
112 | corte_temp_ext | R/W | Temperature in degrees (x10) at the NTC stopping the motor | 800 |
113 | corte_temp_int | R/W | Internal temperature in degrees (x10) of the STM32 stopping the motor | 800 |
114 | corte_volts_alto | R/W | Voltage (x100) which, if exceeded, stops the motor | 1600 |
115 | corte_volts_bajo | R/W | Voltage (x100) which, if not exceeded, stops the motor | 450 |
116 | corte_corriente | R/W | Maximum current in mA. Torque control | 7000 |
117 | uso_crc | R/W | CRC Use (0=False, 1=True, 2=Both) | 2 |
118 | CRC_START_CCITT | R/W | CRC initial value | 0x1D0F |
119 | CRC_POLY_CCITT | R/W | CRC polynomial | 0x1021 |
120 | K_P_LS | R/W | Constant P PID servomotor mode | 200 |
121 | K_D_LS | R/W | Constant D PID servomotor mode | 1000 |
122 | K_I_LS | R/W | Constant I PID servomotor mode | 170 |
123 | K_P_M | R/W | Constant P PID motor mode | 200 |
124 | K_D_M | R/W | Constant D PID motor mode | 1000 |
125 | K_I_M | R/W | Constant I PID motor mode | 170 |
126 | offset_corriente | R/W | Current offset (x1000) (0-222 -> -1000 - +1000) | 111 |
127 | offset_temp_int | R/W | Internal temperature offset (x10) (0-300 -> -150 - +150) | 150 |
128 | offset_temp_ext | R/W | NTC temperature offset (x10) (0-300 -> -150 - +150) | 150 |
129 | envio_si_leo | R/W | Send data over the serial port if I read other data over the serial port (0=False, 1=True, 2=True cancelar sólo el comando de envío actual) | 2 |
130 | saludo_inicial | R/W | Initial greeting (0=False, 1=True) | 1 |
131 | min_posicion | R/W | Minimum position limit (0-4294967294 -> -2147483647 - +2147483647) | 2147483647 |
132 | max_posicion | R/W | Maximum position limit (0-4294967294 -> -2147483647 - +2147483647) | 2147483647 |
133 | limit_posicion | R/W | Use position limits (0=False, 1=True) | 0 |
134 | t_ramp_t | R/W | Default time trapezoidal ramp | 200 |
135 | t_ramp_s | R/W | Default time sine ramp | 200 |
136 | a_ramp_t | R/W | Trapezoidal ramp default acceleration | 100 |
137 | deadband | R/W | Deadband | 5 |
GET [G]
- S12G116;
The G command asks LibreServo for an internal parameter/variable that it will return over the serial port. The G command like the rest of the GX commands go in a separate task manager from the main one.
Example:
S11G13; | Read servomotor position 11 |
---|
Get Several [GS]
- S12GS5[,7,8,100,102]:10:500;
The GS command returns not only one variable, but several variables that we want (up to a maximum of 15). In addition, it can be programmed to return the values every X milliseconds.
param2: Number of times we want to send us the value of the variables. Range: 1, +2.147.483.647
param3: Every how many milliseconds we want to send us the value of variables. Range: 1, +2.147.483.647
Example:
S12GS9,23:1000:1; | Read from servomotor 12 the current consumption and PWM of the motor 1000 times with a time between readings of 1 millisecond. It will be one second sending data |
---|---|
S5GS0,1:1,1; | Read servomotor 5 temperatures. Only sent once |
Get Several with Header [Gs]
- S12Gs5[,7,8,100,102]:10:500;
The Gs command is the same as the GS command with a difference, it sends us at first a line with the name of all the variables we want separated by commas, this is very useful to get a .csv file output, or to see the variables drawn in the Serial Plotter of Arduino. The Gs command returns not only one variable, but several variables that we want (up to a maximum of 15). In addition, it can be programmed to return the values every X milliseconds.
param2: Number of times we want to send us the value of the variables. Range: 1, +2.147.483.647
param3: Every how many milliseconds we want to send us the value of the variables. Range: 1, +2.147.483.647
Example:
S3Gs9,23:1000:1; | Read from servomotor 3 the current consumption and PWM of the motor 1000 times with a time between readings of 1 millisecond. It will spend one second sending data. Send an initial header line |
---|---|
S9Gs0,1:1,1; | Read servomotor 9 temperatures. Only to be sent once and with header |
Get Wait [GW]
- S12GW250;
The GW command works as a Delay. It introduces a wait in the task manager for reading variables. It is useful for when we want to start receiving data but after a wait to match some specific engine command.
Example:
S16GW500; | Servomotor 16 waits 500ms in the task manager for reading variables |
---|
Set [S]
- S12S111:9600;
With the S command we change the value of LibreServo variables that are writable.
param2: New variable value. Range: -2.147.483.646, +2.147.483.647
Example:
S1S100:10 | Change the servomotor ID 1 to 10 |
---|---|
S10S111:9600 | Changes the serial port speed [variable 111] of servo motor 10 to 9600 bps |
Save [SV]
- S12SV;
The SV command saves the current LibreServo configuration, the value of the modifiable variables, in the microcontroller Flash, so the configuration will not be lost when the servo motor is turned off.
Example:
S39SV; | Saves the value of all modifiable variables of the servomotor 39 in Flash |
---|
Reset variable [RV]
- S12RV116
The RV command returns the value of a variable to the value it has in flash. If the variable was saved just before with the SV command, the variable will have the same value in memory as in flash.
Example:
S23RV137; | Returns the flash value of the servomotor 23 to the variable deadband |
---|
Reset variable default value [Rv]
- S12Rv116
The Rv command returns the value of a variable to the default value specified in the table. And saves that variable in flash.
Example:
S18Rv117; | The variable 117 (uso_crc) of the servomotor 18, returns to its default value, 2 |
---|
Reset Servo [RS]
- S12RS;
The RS command returns the value of all servomotor variables to the value they have in flash.
Example:
S10RS; | The servomotor 10 returns the value in flash to all its variables |
---|
Reset Servo default [Rs]
- S12Rs
The Rs command changes the value of all variables to their default value and saves it in flash.
Example:
S45Rs; | The servomotor 45 returns the value of all its variables to their default value and saves them to flash |
---|