Multi Motor RC Control
I wanted to build a R/C controlled vehicle using 4 Individually controlled multiple dc brushed motors, that's where my problems started, there are a few videos out there and most only cover using 2 dc motors, some use motor drivers linked to an Arduino, some use ESC's but there are non that I could find that cover say 4 motors, and I'm not talking about Bluetooth controlled with an Android phone, that's not what I wanted so I started to dig deeper.
I started to look at other options from an Radio Controlled point of view, I have a FLYSKY FS-i6 and a FS-IA6B 6 channel receiver which came with it so I started to look at the ibus side of things using an Arduino, this basically is using the Receiver as a link between the Transmitter and the Arduino using a 4 motor driver, an Arduino code is used and through the ibus on the receiver the motors are run as per the code, thus moving a stick on the Transmitter for direction control.
It should be noted that you can still use the Receiver to control Servo's, LED's etc in the usual way anyway so I began to put some things together which I could I could try, I had a battered Mecanum 4 wheel chassis which I had not done much with for a long time purely because each time I picked it up the acrylic would just break apart, I would use this to try my experiment.
I had a fairly positive outcome, up next is how I went about it.
Supplies
Flysky FS-i6 Transmitter
Flysky FS-i6 Receiver
Suitable Chassis and Mecanum wheels
Arduino Uno
L293d Motor shield
Assorted Dupont cables
18560 x 2 Batteries
18560 Battery holder with on/off switch
Where to Start
I have the Transmitter and receiver, I also had a Arduino Uno and L293d 4 motor driver, the chassis has 4 Mecanum wheels with TT motors and a 2 x 18650 battery holder with an on board on/off switch which is useful.
The first thing to do is solder some wires onto the motors, doesn't matter which way round they go as you can swap the wires around in the terminals on the driver if the motors spin in the wrong direction, with Motors Installed it was time to look at the connections for use with Mecanum wheels, these motors are all being controlled separately.
I don't have a wiring sketch but the connections are fairly simple.
Looking down on the chassis with the Battery holder to the rear of the chassis this is the Rear of the vehicle I make the bottom left, Rear left M1 on the L293D Rear right into M2, Front left M3 and Front right M4, The battery holder is switched and connections are made to the Ext power connectors on the L293D +M and Gnd.
The remaining connections are to the Receiver, the 5V and Gnd come from the shield, I soldered a couple of Pins to the 5v and Gnd on the shield, I also soldered a pin to the 0 Pin on the shield, that is it for ibus connectivity
The battery holder is secured with double sided tape but that's it, it's only an experiment and all the components will be used for other projects at some time, ok it doesn't look pretty I know.
We can now move onto the Transmitter and Receiver side of things.
FLYSKY FS-i6 Transmitter and Receiver Set Up
The only connections to the receiver are the 5v and Gnd from the shield pins, and the ibus data cable from Pin 0 on the shield to the ibus data pin on the receiver, looking at the top of the receiver it says ibus, then to the left it says SENS to which there are 3 pins and to the right SERVO once again 3 Pins, from this side we select the furthest pin to the right for our ibus connection.
The Receiver Voltage is 4 to 8.4 Volts DC so it's ok to use the 2no 3.7V batteries in this case, it's best to check if unsure.
Now to the Arduino code we are using for this experiment.
Arduino Code
I trawled through many codes on the Internet, but the majority were for 2 motor set ups, some of the codes were unobtainable for whatever reason and a lot just didn't compile anyway, I found one which I thought I could manipulate to suit my needs with the Mecanum Wheels.
I will add the Arduino code as someone may be able to use it, I honestly couldn't find one project on the Internet which used four motors using the ibus, I may have missed something as it becomes very tedious after a while searching, and very confusing, anyway here is what I did with the code, I don't fully understand all the correct Syntax with Arduino but we need certain Libraries to run.
#include <AFMotor.h>
#include <IBusBM.h>
IBusBM ibus;
Then we create Objects.
AF_DCMotor motor1(1, MOTOR12_64KHZ);
AF_DCMotor motor2(2, MOTOR12_64KHZ);
AF_DCMotor motor3(3, MOTOR12_64KHZ);
AF_DCMotor motor4(4, MOTOR12_64KHZ);
Set up
Serial.begin(115200);
ibus.begin(Serial);
motor1.setSpeed(120);
motor2.setSpeed(120);
motor3.setSpeed(120);
motor4.setSpeed(120);
First part of the loop.
double ch1Value = readChannel(0, -100, 100, 0);
double ch2Value = readChannel(1, -100, 100, 0);
double ch3Value = readChannel(2, -100, 100, 0);
double ch4Value = readChannel(3, -100, 100, 0);
The rest of the Loop and where you adjust what motor is doing what.
if ((ch1Value == 0) && (ch2Value == 0))
{
motor3.run(RELEASE);//Front left
motor1.run(RELEASE);//Rear left
motor4.run(RELEASE);//Front right
motor2.run(RELEASE);//Rear right
}
if ((ch1Value < 30) && (ch2Value < -50))
{
motor3.run(FORWARD);//Forwards
motor1.run(FORWARD);
motor4.run(FORWARD);
motor2.run(FORWARD);
}
else if ((ch1Value < 30) && (ch2Value > 50))
{
motor3.run(BACKWARD);//Backwards
motor1.run(BACKWARD);
motor4.run(BACKWARD);
motor2.run(BACKWARD);
}
else if ((ch1Value < -50) && (ch2Value < 30))
{
motor3.run(BACKWARD);//Turn Left
motor1.run(FORWARD);
motor4.run(FORWARD);
motor2.run(BACKWARD);
}
else if ((ch1Value > 50) && (ch2Value < 30))
{
motor3.run(FORWARD);//Turn Right
motor1.run(BACKWARD);
motor4.run(BACKWARD);
motor2.run(FORWARD);
}
else if ((ch4Value < -50) && (ch2Value < 30))
{
motor3.run(BACKWARD);//Slew left
motor1.run(BACKWARD);
motor4.run(FORWARD);
motor2.run(FORWARD);
}
else if ((ch4Value > 50) && (ch2Value < 30))
{
motor3.run(FORWARD);//Slew right
motor1.run(FORWARD);
motor4.run(BACKWARD);
motor2.run(BACKWARD);
}
else if ((ch3Value < -50) && (ch4Value < 30))
{
motor3.run(FORWARD);//Diagonal
motor1.run(FORWARD);
motor4.run(RELEASE);
motor2.run(RELEASE);
}
else if ((ch3Value > 50) && (ch4Value < 30))
{
motor3.run(RELEASE);//Diagonal
motor1.run(RELEASE);
motor4.run(BACKWARD);
motor2.run(BACKWARD);
}
else if ((ch4Value > 50) && (ch3Value < 30))
{
motor3.run(RELEASE);//Diagonal
motor1.run(BACKWARD);
motor4.run(BACKWARD);
motor2.run(RELEASE);
}
else if ((ch4Value > 50) && (ch3Value < 30))
{
motor3.run(RELEASE);//Diagonal
motor1.run(FORWARD);
motor4.run(FORWARD);
motor2.run(RELEASE);
}
else
{
motor3.run(RELEASE);
motor1.run(RELEASE);
motor4.run(RELEASE);
motor2.run(RELEASE);
}
delay(200);
}
int readChannel(byte channelInput, int minLimit, int maxLimit, int defaultValue) {
uint16_t ch = ibus.readChannel(channelInput);
if (ch < 100) return defaultValue;
return map(ch, 1000, 2000, minLimit, maxLimit);
}
Don't copy and paste this file, it won't work from here, Download the Code from the file folder.
The next task is to set up the Transmitter:
Getting the Correct Settings Between Arduino Code and the Tranmitter
This part nearly fried my brain once again, what we have to do here is initially get the correct motor directions within the code, then you use the mix channels in the Transmitter to do the rest.
It's just a matter of trial and error, If you look at the screenshots you can see the Transmitter channel mixes I ended up with there is still work to do but its very useable, I don't know enough about Transmitters to know what I'm doing, hey it work's so I'm happy.
To the assumptions:
Assumptions
Was this harder for me than I expected? Yes it was, I struggled to find anything online with 4 motors, loads of videos with everyone doing the same thing more or less so I spent more time on this project than I should have done really, I go so confused in the end I had to leave it for a while.
Everyone is after the same end but all go about it in different ways really in my honest opinion, which is fine, I take my hat off to anyone who takes the time to upload a Tutorial.
At the end of the day all we want is motors to spin using a Transmitter and receiver, under normal circumstances a Transmitter and Receiver is used for Planes or drones etc and used with ESC's for single or dual motor control.
Anyway as usual I managed to get there in the end and ended up with something which works, the only thing I never got round to doing was controlling the acceleration of the motors, it's all or nothing with this code, within the code you can control the outright speed with
motor1.setSpeed(120);
motor2.setSpeed(120);
motor3.setSpeed(120);
motor4.setSpeed(120);
I opted for 120 Speed, 100 wouldn't work with the mecanum wheels on carpet, 200 was too much.
Anyway motor mapping is for another project.
I hope this Instructable helps someone who was in the same position as me and thanks for looking.