Last post (here) we looked at the ESC control in cars, with and without brakes. Here, I provide a sample code that managed to run the car autonomously (meaning: it ran without any Tx / Rx).
#include<Servo.h>
Servo esc; // Call the ESC "esc"
void setup()
{
esc.attach(9);
/*
As you can see - I am not arming the ESC here. For some reason, the ESC is now on a persistently armed mode now. Upon powering, the ESC automatically arms. Given sparse documentation for the ESC, I am not examining this weird behavior changes in this ESC. However, if your ESC refuses to arm, then I would suggest the code shown in post_1 be used.
*/
//Again - this is useful only during the testing part. For autonomous running, it is pointless.
int i=0;
Serial.begin(9600); }
void loop()
{
int i=0;
// Start at Servo Degree 70 and go till just above neutral.
// Note, Neutral is at 94 for this ESC.
// This will run it in one direction.
for(i=70;i<95;i++)
{
esc.write(i);
delay(200);
}
//Run for 2 seconds at moderately high speed (70).
esc.write(70); delay(2000);
// Apply Brakes for 40 millisecs.
esc.write(100); delay(40);
// Apply throttle in opposite direction for 2 seconds.
esc.write(110); delay(2000);
// Bring down throttle to neutral.
for(i=110;i>90;i--)
{
esc.write(i);
delay(200);
}
// Apply brakes again - to change directions for 40 millisecs.
esc.write(70); delay(40);
}
This code has not been rigorously tested at all. For example, there is no reason why I used 40 millisecs instead of, say, 35. All I have noticed is that at the pulse frequency (50Hz / 20 millisecs) this code doesn't work. So, in all likelihood, 21ms could also work. Also - I don't know what will happen if I bring the run throttle (70 and 110) closer to neutral (say,
85 and 100). In some cases, the ESC behavior abruptly changes, and the direction shifting doesn't happen (it stops running in one of the directions).
However, this code has allowed the RC car to move forward and in reverse without any external input at all. (time for a drink).
Given below is a photo of the car I had used for this purpose - it is a Traxxas / TT rip-off rally frame. The big (1/10) frame has plenty of room / power for carrying the Arduino board, a 7200 mAh NiMH battery for the car, a 10000mAh USB power bank (used to power the Arduino board) and everything else in between. I have not provided the connection drawing, because it is - at this point - trivial.
I intend to slap a SONAR on it and see if it can run around and not bump into obstacles (or walls). At that point, I will post a video :-)
Till then - ciao.
k
#include<Servo.h>
Servo esc; // Call the ESC "esc"
void setup()
{
esc.attach(9);
/*
As you can see - I am not arming the ESC here. For some reason, the ESC is now on a persistently armed mode now. Upon powering, the ESC automatically arms. Given sparse documentation for the ESC, I am not examining this weird behavior changes in this ESC. However, if your ESC refuses to arm, then I would suggest the code shown in post_1 be used.
*/
//Again - this is useful only during the testing part. For autonomous running, it is pointless.
int i=0;
Serial.begin(9600); }
void loop()
{
int i=0;
// Start at Servo Degree 70 and go till just above neutral.
// Note, Neutral is at 94 for this ESC.
// This will run it in one direction.
for(i=70;i<95;i++)
{
esc.write(i);
delay(200);
}
//Run for 2 seconds at moderately high speed (70).
esc.write(70); delay(2000);
// Apply Brakes for 40 millisecs.
esc.write(100); delay(40);
// Apply throttle in opposite direction for 2 seconds.
esc.write(110); delay(2000);
// Bring down throttle to neutral.
for(i=110;i>90;i--)
{
esc.write(i);
delay(200);
}
// Apply brakes again - to change directions for 40 millisecs.
esc.write(70); delay(40);
}
This code has not been rigorously tested at all. For example, there is no reason why I used 40 millisecs instead of, say, 35. All I have noticed is that at the pulse frequency (50Hz / 20 millisecs) this code doesn't work. So, in all likelihood, 21ms could also work. Also - I don't know what will happen if I bring the run throttle (70 and 110) closer to neutral (say,
85 and 100). In some cases, the ESC behavior abruptly changes, and the direction shifting doesn't happen (it stops running in one of the directions).
However, this code has allowed the RC car to move forward and in reverse without any external input at all. (time for a drink).
Given below is a photo of the car I had used for this purpose - it is a Traxxas / TT rip-off rally frame. The big (1/10) frame has plenty of room / power for carrying the Arduino board, a 7200 mAh NiMH battery for the car, a 10000mAh USB power bank (used to power the Arduino board) and everything else in between. I have not provided the connection drawing, because it is - at this point - trivial.
I intend to slap a SONAR on it and see if it can run around and not bump into obstacles (or walls). At that point, I will post a video :-)
Till then - ciao.
k