LibreServo commands (part one)

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

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.

param1: the first parameter indicates the position we want to go to (a 360 degree turn is 65,535). Range: -2.147.483.646, +2.147.483.647
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.

param1: final position. Range: -2.147.483.646, +2.147.483.647
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.

param1: final position. Range: -2.147.483.646, +2.147.483.647
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.

param1: final position. Range: -2.147.483.646, +2.147.483.647
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.

param1: final position. Range: -2.147.483.646, +2.147.483.647
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.

param1: final position. Range: -2.147.483.646, +2.147.483.647
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.

param1 (opcional): initial position. If not specified, it is the position at the beginning of the movement. Range: -2.147.483.646, +2.147.483.647
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.

param1: final speed at which we want to go (a 360 degree turn is 65,535, speed of one turn per second would be 65535). Range: -2.147.483.646, +2.147.483.647
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;
param1: final speed. Range: -2.147.483.646, +2.147.483.647
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;
param1: final speed. Range: -2.147.483.646, +2.147.483.647
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.

param1 (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
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.

param1: PWM del motor. Range: -1800, +1800
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.

param1: The milliseconds of waiting: Range: 0, +2.147.483.647

Example:
S17MW500; Servomotor 17 waits 500ms

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.

param1: Red color intensity. Range: 0, +255
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.

param1: Frequency of the tone/note. It is recommended to use frequencies above the sixth musical octave. Range: 0, +2.147.483.647
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%
Frecuencia notas musicales 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:

IDNameR/WDefinitionDefault value
0Temp_internaRTemperature in degrees (x10) as measured internally in the microcontroller
1Temp_externaRTemperature in degrees (x10) measured externally on NTC temperature sensor
2Temp_interna_rawRDirect readout (12 bits) from internal temperature sensor to microcontroller
3Temp_interna_kalmanRInternal temperature sensor reading to the microcontroller after Kalman filtering
4Temp_externa_rawRDirect reading (12 bits) of the external temperature sensor NTC
5Temp_externa_kalmanRExternal NTC temperature sensor reading after Kalman filter
6VoltageRVoltage, supply voltage of LibreServo (x100)
7Voltage_rawRReadout (12 bits) of the power supply voltage
8Voltage_kalmanRPower supply voltage reading after Kalman filtering
9CorrienteRCurrent consumed by the servomotor in mA
10Corriente_rawRReadout (12 bits) of the current consumed by the servomotor
11Corriente_kalmanRCurrent reading after Kalman filter
12Encoder_rawREncoder position reading (16 bits)
13Encoder_kalmanREncoder position reading after Kalman filter
14Velocidad_encRServomotor speed calculated from encoder position
15Aceleracion_encRServomotor acceleration calculated from encoder position
16Velocidad_simRServomotor speed calculated with the desired position of the servomotor
17Aceleracion_simRServomotor acceleration calculated with the desired position of the servomotor
18Posicion_objetivoRPosition LibreServo is marking
19ErrorRDifference between Posicion_objetivo and encoder reading after Kalman filter (Encoder_kalman)
20DErrorRDifferential error (PID)
21PDTermRPD Term of the PID
22ItermRIntegral Term of the PID
23PWMRMotor PWM
24PWM_preRPWM desired before looking to see if current draw is excessive
99Version_LSRLibreServo internal version
100ID ServomotorR/WID of the servomotor, through which it will listen for commands1
101q_corrienteR/WCurrent process uncertainty (x1000) (Kalman)1200
102q_temp_extR/WNTC temperature process uncertainty (x1000) (Kalman)1200
103q_temp_intR/WUncertainty process internal temperature STM32 (x1000) (Kalman)1200
104q_voltsR/WProcess voltage uncertainty (x1000) (Kalman)1200
105q_encoderR/WUncertainty encoder process (x1000) (Kalman)1200
106varianza_corrienteR/WCurrent variance (x1000) (Kalman)1000
107varianza_temp_extR/WNTC temperature variance (x1000) (Kalman)2500
108varianza_temp_intR/WVariance internal temperature STM32 (x1000) (Kalman)150
109varianza_voltsR/WVoltage variance (x1000) (Kalman)150
110varianza_encoderR/WEncoder variance (x1000) (Kalman)5000
111vel_serieR/WSerial port speed115200
112corte_temp_extR/WTemperature in degrees (x10) at the NTC stopping the motor800
113corte_temp_intR/WInternal temperature in degrees (x10) of the STM32 stopping the motor800
114corte_volts_altoR/WVoltage (x100) which, if exceeded, stops the motor1600
115corte_volts_bajoR/WVoltage (x100) which, if not exceeded, stops the motor450
116corte_corrienteR/WMaximum current in mA. Torque control7000
117uso_crcR/WCRC Use (0=False, 1=True, 2=Both)2
118CRC_START_CCITTR/WCRC initial value0x1D0F
119CRC_POLY_CCITTR/WCRC polynomial0x1021
120K_P_LSR/WConstant P PID servomotor mode200
121K_D_LSR/WConstant D PID servomotor mode1000
122K_I_LSR/WConstant I PID servomotor mode170
123K_P_MR/WConstant P PID motor mode200
124K_D_MR/WConstant D PID motor mode1000
125K_I_MR/WConstant I PID motor mode170
126offset_corrienteR/WCurrent offset (x1000) (0-222 -> -1000 - +1000)111
127offset_temp_intR/WInternal temperature offset (x10) (0-300 -> -150 - +150)150
128offset_temp_extR/WNTC temperature offset (x10) (0-300 -> -150 - +150)150
129envio_si_leoR/WSend 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
130saludo_inicialR/WInitial greeting (0=False, 1=True)1
131min_posicionR/WMinimum position limit (0-4294967294 -> -2147483647 - +2147483647)2147483647
132max_posicionR/WMaximum position limit (0-4294967294 -> -2147483647 - +2147483647)2147483647
133limit_posicionR/WUse position limits (0=False, 1=True)0
134t_ramp_tR/WDefault time trapezoidal ramp200
135t_ramp_sR/WDefault time sine ramp200
136a_ramp_tR/WTrapezoidal ramp default acceleration100
137deadbandR/WDeadband5

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.

param1: ID of the variable whose value we want to see.

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.

param1: Parameter where we indicate the ID or IDs of the variables to be read separated by commas ','. Range: 0, +137.
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.

param1: Parameter where we indicate the ID or IDs of the variables to be read separated by commas ','. Range: 0, +137.
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.

param1: The milliseconds of waiting. Range: 0, +2.147.483.647

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.

param1: Variable ID to be modified. Range: 0, +137
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.

param1: Variable ID to be reset Range: 0, +137

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.

param1: Variable ID to be reset. Range: 0, +137

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

Subscription

Receive an email for each new article.

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

3 + 9 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.