Original document in French available here: https://www.robot-ma...ds/#entry111711
Once your robot, equipped with a raspberry pi, is connected to vigibot (follow the instructions here: https://www.robot-ma...r-the-internet/), the robot can be configured to control many elements (e.g. motors, LEDs or relays) directly from the GPIOs of the raspberry pi, or using an extra module called PCA9685, which allows "to increase the number of GPIOs".
The interface will consent to control for example LEDs or relays with a “all-or-nothing” approach, but could also allow to control LEDs with more or less brightness (also valid for controlling a fan more or less quickly via a transistor), and similarly to control servomotors and various drivers of DC motors.
To do this you will have to configure the "Hardware" configuration of your robot, clicking on the ‘gear’ icon.
If you haven't made any changes you will end up with an "empty" window in the “Modifications Made” tab, and that's normal. If you have already made changes, you will see all the tables in which you have changed something.
If you select the "Active Configuration" tab, you will then see the configuration currently applied to your robot. (You will find that you can configure a lot of things, but not everything will be presented in the present guide; we will only focus on "output devices": LEDs, motors, etc ...)
One of the Available tables is the "OUTPUTS" table. This table contains the configurations of all your output devices. Led, motors etc ... For each peripheral you have an OUTPUTS. Your default configuration already has many OUTPUTS.
An "Output" has the following different parameters:
NAME: you can fill this field as you like, the name will not be displayed, it is only for you to remember which outputs is that.
TYPE: this field indicates what type of equipment we are going to control. You can only put pre-defined types which are as follows:
=> Gpios: For everything that is all or nothing, 1 or 0, On or Off. Control of relays, transistor, leds ...
=> Servos: For everything that can be controlled with the same signal as the servomotors (servomotor, motor drivers or any other peripheral using the same kind of signal as a conventional servomotor)
=> Pwms: To drive the luminosity of a led or the speed of a motor drive by a transistor. (Do not use Pwms with a Relay!)
There are also more specialized types for motor drivers:
=> PwmPwm: Motor driver with two wires for L9110 type motors requiring two pwm to define the speed and direction of rotation of a motor (it requires two GPIOS specified)
=> PwmDir: Motor driver requiring two wires per motors of the type ‘MD10C citron’ requiring a Pwm pin for the speed and a Dir pin to choose the direction. (it requires two GPIOS specified, the first one is the PWM)
=> PwmDirDir: Motor driver requiring three wires per L298 type motors with one PWM pin (enable) and two direction pins (In) (it requires three GPIOS specified, the first one is the PWM)
ADDRESS: by default value to be left at -1 useful only if you wish to drive an element not with the GPIOs of the pi but through the GPIOs on a PCA. In this precise case, replace -1 by the number of your pca. 0 if you only have one PCA, 0 or 1 if you have two PCAs etc ... For more info on the pca9685: https://www.robot-ma...-leds/?p=111711
GPIOS: Contains the GPIOS to which your peripherals will be connected. Numbers from 0 to 27 for the gpio of the pi, and numbers from 0 to 15 for a pca.
The Gpios, Servos, Pwms types can have several gpio if you want to "duplicate the same signal" on several GPIOs, and at least 1 gpio defined.
WARNING: the specific types PwmPwm and PwmDir must absolutely have two GPIOS specified, and the type PwmDirDir must absolutely have three GPIOS specified. For the PwmDir and PwmDirDir types, the first gpio is the pwm.
WARNING again: avoid using Gpios which are already used by another Output. The presence of conflicts can cause erratic behavior.
SLEEPMODES: Defined in which states your pins are put when the robot is in sleep mode. You must have as many sleepmodes as there are GPIOs. 4 possible sleepmode values: None, High, Low or Floating.
None = We do not change the state of the Gpio when the robot goes into sleep mode, the gpio remains in the state in which it was.
High Low or floating = The gpio will be in the specified state when the robot is in sleep mode
INS: define the input range that will control your system. Usually to be matched with the parameters defined in your remote control.
Usually the ins are set between -180 and 180 for servos (degree control) and -100 to 100 for motors (percentage speed control) but can be set differently for other units if desired.
WARNING: the INS must always be listed in ascending order. You need to have at least two INS; you can have more, as soon as you keep the list in ascending order.
OUTS: defines the range of output values that your system will drive. For the Servos type the range of OUTS values is between 500 (µs) and 2500 (µs). For the Gpios type the range of values is 0 or 1. (translated High or Low). For other types the value range is -100 to 100. (percentage of pwm -100% to 100%, the sign used for the direction pins)
WARNING: there must absolutely be as many OUTS as INS! The INS-OUTS tables used to define the output behavior of your device according to the input it receives.
if ( INS[X] <= in && in <= INS[X+1] )
out = map (in, INS[X], INS[X+1], OUTS[X], OUTS[X+1] )
for more details you can look at the computeOut function in clientrobotpi.js
The configuration of the INS and the Outs allows you to make curves of behavior of the input compared to the output "linear by pieces".
You can for example pre-calculate an approximation of the behavior "squared" with the following config:
INS : -10 -7 -4 -2 0 2 4 7 10
OUTS: -100 -49 -16 -4 0 4 16 49 100
BACKSLASH: Backlash adjustment value, useful only for correcting servomotors with backlash.
0 by default = no correction. Fairly low value to put between 0 and 10 in general. This is a delta value of servo PWM in µs ... For those who are interested in its operation: this value "is added or subtracted" from the "out" output with changing sign according to the derivative of the reference.
For more details see the writeOutputs() function in clientrobotpi.js
To conclude:
COMMANDS16
GAINS16
COMMANDS8
GAINS8
COMMANDS1
GAINS1
These three pairs allow you to define which commands (among the commands defined in your remote control) will have an impact on your peripheral with which gains, according to the rule
in = Sum (Orders16 [i] * Gains16 [i]) + Sum (Orders8 [j] * Gains8 [j]) + Sum (Orders1 [k] * Gains1 [k])
For more details see the writeOutputs() function in clientrobotpi.js
WARNING: Always use a command number that exists in your remote control.
At the moment there are only 8 commands1 available numbered from 0 to 7; and 3 commands8 available numbered from 0 to 2 (Speed in x = left/right translation, speed in y = forward/backward, and speed in z = left/right rotation)
The number of commands16 can be configured in your remote controls.
It is thanks to this triplet of pairs of configurations that you can mix several commands together to control an actuator. This is very useful for controlling the propulsion motors of a robot for example, and allows you to configure both a differential displacement by playing with commands8, 1 and 2 as well as to configure the control of omnidirectional robots like mecanum, omniwheel or flying drones!