Aller au contenu


Photo
- - - - -

How to configure my vigibot robot to control Motors, Relays and LEDs?


3 réponses à ce sujet

#1 efarnioli

efarnioli

    Membre

  • Membres
  • 12 messages

Posté 11 janvier 2022 - 03:20

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!

 



#2 efarnioli

efarnioli

    Membre

  • Membres
  • 12 messages

Posté 11 janvier 2022 - 03:22

Use Case

 

Let’s consider the case in which I have a robot that uses an L298 type motor driver to move

(instead of a motor driver that drives like a servo motor, which is configured by default)

A ) I look at which Outputs are currently configured in the actual configuration, and I locate the OUTPUTS[4] and OUTPUTS[5] whose names are "Left wheels" and "Right wheels". It is therefore only these two outputs that we are going to modify.

B ) I’ll take the corresponding type for the output ( L298 => PwmDirDir ) 

C) I add two gpios in the GPIOS table to have the 3 gpios required for the PwmDirDir type, and I choose the GPIOS among the available gpios:

for a standard config the available Gpios are 0, 1, 4 9 10 11 12 13 24 25 26 27. (26 and 27 are used for the engines but you are working on the engines, so these two Gpios are also available ...)

Reminder: 2 and 3 are used by the I2C, 14 and 15 are for the UART 16 to 23 are the 8 Gpio of the switches, 5 to 8 are used for the head and the clamp)

(Note: To add parameters, choose text code editing mode or tree mode.)

D) I add 2 sleepmodes to have as many sleepmodes as there are gpios. For a motor driver setting all sleepModes to Low is a good idea. (Especially do not put the PWM in sleepmode to High one of the direction pins to High and the other to Low otherwise your robot will go to standby!)

E) I modify the values of outs to match the range of -100 to 100 of the PwmDirDir mode and I put as many outs as there are in.

By default 4 ins are configured: -100 -1 1 100, that's why I have 4 outs.

In general the two ends of the outs you can put them at -100 and at 100 to go to the maximum speed.

And the two central values are to be adjusted so that your robot moves forward as soon as you send a small impulse to move forward.

Example of valid outs: -100 -10 10 100 but -100 -1 1 100 is also valid, it depends on your robot.

If my robot does not drive straight I can adjust the outs of the motor which is going too fast to correct the fault observed by reducing the maximum speed for example.

What it gives as a modified configuration:

 

"NAME": "Left wheels",

"TYPE": "PwmDirDir", 

"ADRESSE": -1,

"GPIOS": [

        9,

        24,

        25

      ],

"SLEEPMODES": [

        "Low",

        "Low",

         "Low"

      ],

"OUTS": [

        -100,

        0,

        0,

        100

      ]

 

All the other entries can be left as by default

 

 

Here below, other example about the correct type to use for your specific case:

 

L9110 is a board that use PwmPwm,  the driver have only inA and inB, reversing those inputs reverse the motor direction.

L298 is a board that use PwmDirDir, the driver have a PWM/enable  + inA and InB.  For the particular case we can use PwmPwm if enable pin is forced to " run state " 

Cytron is a board tha use PwmDir, the driver have only two inputs, pwm and direction. Pwm mode alone can be used if you don't need to reverse the direction of the motor.
Servo driveris a board that require the same servo signal as for servo with only one input. 
PCA servo can be used to drive servomotors or any other of the board above by setting correctly the gpio and type and specifying pca address

PCA with motor driver included  this one include pca board + t6612fng woking with PwmDirDir mode.



#3 efarnioli

efarnioli

    Membre

  • Membres
  • 12 messages

Posté 11 janvier 2022 - 03:25

What is a PCA9685?

 

A pca9685 is a fairly widespread component allowing you to provide 16 additional PWM outputs which connects to I2C (GPIO 2 and 3 of your raspberry pi = SDA and SCL).

 

How to configure a PCA9685 on Vigibot?:

0) Connect your PCA to your raspberry pi on the I2C pins 2 and 3 (SDA and SCL)

1) Know the I2C address of your pca9685 (in decimal)

Method 1: read your card documentation

Method 2: run an I2C scan on your raspberry pi you will see all of the I2C peripherals present. (search for "raspberry pi i2cdetect")

 

=> Notice, often the I2C addresses are displayed in hexadecimal and not in decimal ...

In this case it will be necessary to convert the hexadecimal I2C address into decimal)

 

Example for a PCA9685 with the default I2C at 0x70, the decimal value is 112.

 

2) Add the address of Your PCA in your hardware configuration.

Go to Hardware Configuration, search for PCA9685ADDRESSES, and add your I2C address (in decimal!) Then save your configuration.

=> If you entered a valid I2C address, with a PCA connected your robot robot should still function as if nothing had changed.

=> If you have entered an invalid I2C address, or if your PCA is no longer connected, your robot will no longer be able to connect and will turn red on vigibot. (Removing the invalid address or correcting it with the valid address will correct the problem.

3) Configure the outputs you want to use with a PCA

In Hardware Configuration, modify the OUTPUTS that you want to use with the PCA9685 and in the "address" box replace -1 by 0 to assign it to the first PCA9685 whose address you have saved in PCA9685ADDRESSES.

In GPIOS, also check that the output numbers you want are between 0 and 15!

Save your configuration, if no configuration error normally your robot should work as desired and the output of your PCA be driven.

4) Bonus, connect several PCAs:

Add as many addresses as there are PCA9685 that you have in the PCA9685ADDRESSES table.

To select the PCA in OUTPUTS, change the -1 in address by 0 to select your first pca, by 1 to select the second 1 etc ...

 

Example of a card with PCA9685:

https://www.robot-ma...moteurs-32.html



#4 firened

firened

    Membre

  • Membres
  • 43 messages
  • Gender:Male

Posté 26 mars 2022 - 08:48

very detailed guide. thank you



Répondre à ce sujet



  


0 utilisateur(s) li(sen)t ce sujet

0 members, 0 guests, 0 anonymous users