Components and supplies
Jumper wires (generic)
Arduino Nano R3
Tools and machines
Soldering iron (generic)
Solder Wire, Lead Free
Apps and platforms
Arduino IDE
Project description
Code
4ws steering controller
arduino
set nano board
1/* 2I used an inexpensive nano board v3 ATmega 328p 3the pins used are: 4VIN(+)and GND(-) 5you can feed the power from your bec (5-9 volt) 6D7 throttle signal input. 7D8 front steering input signal. 8D10 rear steering signal output. 9D4 blinking dx leds 10D5 blinking sx leds 11----------------------------------------- 12basic setup instructions: 13first you must obtain the best mechanical setup from your front and rear servos and linkage. 14best without subtrims or radio adjustements. 15the values you find default should make the controller work quite right away. 16however if you want to be sure about what are your real radio signal inputs, or if they are reversed check them before starting this sketch. 17create a new tab and check your input signals with this program (7 for steering - 8 for throttle gas) 18 19int rxpulse; 20void setup () { 21Serial.begin (9600); 22} 23void loop () { 24rxpulse = pulseIn (7, HIGH); // - 7 to know front steering signal values, change to 8 and load again to check throttle values in serial monitor 25Serial.println (rxpulse); 26 27you can read the values in the serial monitor by turning the steering wheel of the radio control or moving the throttle. 28write the values obtained ann fill the first define part of the controller setup, replace the default ones with yours custom values. 29-------------------------------------------------- ------ 30the user driving setup consists of 2 main functions: 31first you can choose how much throttle allow at low speed 32before the width of the rear servo starts to close (Speedlimit function). 33 34the second function allows you to determine rear servo width at maximum throttle (Max_gain). 35you can choose to close it completely to 2ws or keep 4ws available even at maximum speed 36 37the other functions are: 38tolerance give stepper movement to servo (set it to zero). 39Blinkpoint allow steering travel before led start to blink. 40 41----------- 42somethimes it can happen that you exceed with the values the direction result inverted, be careful to find the best suitable values for your model. 43to get the servo reverse you just have to exchange the Postsx Postdx rear steering values and put a sign (-) in front of the Max_gain value 44there is a relationship between Slowlimit and Max_gain, it can happen that if you lower one you will have to raise the other 45however I am sure that it will take you little time to understand how controller works 46*/ 47 48//----------- signal setup ------------------------------------- 49#define Neutral 1500 // -- default 1500//minimum throttle forward signal or neutral position 50#define Maxspeed 2000 // -- default 2000//maximum throttle forward signal 51#define Antsx 1000 // -- default 1000//in front servo signal sx 52#define Antdx 2000 // -- default 2000//in front servo signal dx 53#define Streight 1500 //-- default 1500//neutral signal steering centered position for blinking arrow light (if seering center is not zero: add or subtract half of Center value) 54 55#define Postsx 1000 //-- default 1000//out rear servo sx end point (if inverted with postdx it reverse) 56#define Postdx 2000 //-- default 2000//out rear servo dx endpoint (if inverted with postsx it reverse) 57#define Center 0 //-- default 0//add or subtract your value to center steering (+- 50 or more) 58 59//--------- user driving setup ------------------------------ 60 61#define Max_gain 400 //-- default 400//gain steering reduction width at max throttle (if work reverse add (-) before value) 62#define Slowlimit 1600 //-- default 1600//slow forward percentage without endpoint correction 63#define Blinkpoint 300 //-- default 300//steering value where led start to blink, small values start led blink close near to center 64#define Tolerance 0 //-- default 0//add/remove stepper servo steering movement 65 66//---------------------------- 67#include <Servo.h> 68Servo myservo; 69#define N_STST 7 //--default7//if servo response is slow low this value to 4 values less 4 may give servo vibration 70#define N_STGAS 7 //--default7//if servo response is slow low this value to 4 values less 4 may give servo vibration 71unsigned int stSt[ N_STST ]; 72unsigned int stGas[ N_STGAS ]; 73long toStSt = 0; 74long toStGas = 0; 75int inSt = 0; 76int inGas = 0; 77unsigned int Rxpulse; 78unsigned int Gaspulse ; 79unsigned int Gain; 80unsigned int NewPos, OldPos; 81int led1 = 4;//--led dx 82int led2 = 5;//-- led sx 83void setup() { 84for ( int i=0; i<N_STST; i++ ) stSt[ i ] = 0; 85for ( int i=0; i<N_STGAS; i++ ) stGas[ i ] = 0; 86myservo.attach(10); //-- rear servo signal out pin 10 87pinMode(8, INPUT); //-- front servo signal in pin 8 88pinMode(7, INPUT); //-- throttle signal in pin 7 89pinMode(led1, OUTPUT); 90pinMode(led2, OUTPUT); 91} 92void loop(){ 93 94 95 noInterrupts(); 96Rxpulse = pulseIn(8, HIGH); 97Gaspulse = pulseIn(7, HIGH); 98 interrupts(); 99delay(5); 100if (Gaspulse > Slowlimit) { //-- default >// if your throttle signal is reverse must change "<" 101Gain = map(Gaspulse, Slowlimit, Maxspeed, 0, Max_gain ); 102NewPos = map(Rxpulse, Antsx, Antdx, (Postsx + Gain), (Postdx - Gain)); 103 } 104else { 105NewPos = map(Rxpulse, Antsx, Antdx, Postsx, Postdx); 106 } 107if (abs(NewPos - OldPos)> Tolerance) { 108OldPos = NewPos; 109myservo.write(NewPos + Center); 110 111if (OldPos > Streight+Blinkpoint) digitalWrite(led1, (millis() / 100) % 2); //--default 100 is led blink speed 112 113 else digitalWrite(led1, LOW); 114if (OldPos < Streight-Blinkpoint) digitalWrite(led2, (millis() / 100) % 2); //--default 100 is led blink speed 115 116 else digitalWrite(led2, LOW); 117 118} 119}
4ws steering controller
arduino
set nano board
1/* 2I used an inexpensive nano board v3 ATmega 328p 3the pins used 4 are: 5VIN(+)and GND(-) 6you can feed the power from your bec (5-9 volt) 7D7 8 throttle signal input. 9D8 front steering input signal. 10D10 rear steering 11 signal output. 12D4 blinking dx leds 13D5 blinking sx leds 14----------------------------------------- 15basic 16 setup instructions: 17first you must obtain the best mechanical setup from your 18 front and rear servos and linkage. 19best without subtrims or radio adjustements. 20 21the values you find default should make the controller work quite right away. 22however 23 if you want to be sure about what are your real radio signal inputs, or if they 24 are reversed check them before starting this sketch. 25create a new tab and check 26 your input signals with this program (7 for steering - 8 for throttle gas) 27 28int 29 rxpulse; 30void setup () { 31Serial.begin (9600); 32} 33void loop () { 34rxpulse 35 = pulseIn (7, HIGH); // - 7 to know front steering signal values, change to 8 and 36 load again to check throttle values in serial monitor 37Serial.println (rxpulse); 38 39you 40 can read the values in the serial monitor by turning the steering wheel of the radio 41 control or moving the throttle. 42write the values obtained ann fill the first 43 define part of the controller setup, replace the default ones with yours custom 44 values. 45-------------------------------------------------- ------ 46the user 47 driving setup consists of 2 main functions: 48first you can choose how much throttle 49 allow at low speed 50before the width of the rear servo starts to close (Speedlimit 51 function). 52 53the second function allows you to determine rear servo width at 54 maximum throttle (Max_gain). 55you can choose to close it completely to 2ws or 56 keep 4ws available even at maximum speed 57 58the other functions are: 59tolerance 60 give stepper movement to servo (set it to zero). 61Blinkpoint allow steering travel 62 before led start to blink. 63 64----------- 65somethimes it can happen that 66 you exceed with the values the direction result inverted, be careful to find the 67 best suitable values for your model. 68to get the servo reverse you just have to 69 exchange the Postsx Postdx rear steering values and put a sign (-) in front of the 70 Max_gain value 71there is a relationship between Slowlimit and Max_gain, it can 72 happen that if you lower one you will have to raise the other 73however I am sure 74 that it will take you little time to understand how controller works 75*/ 76 77//----------- 78 signal setup ------------------------------------- 79#define Neutral 1500 // -- 80 default 1500//minimum throttle forward signal or neutral position 81#define Maxspeed 82 2000 // -- default 2000//maximum throttle forward signal 83#define Antsx 1000 84 // -- default 1000//in front servo signal sx 85#define Antdx 2000 // -- default 86 2000//in front servo signal dx 87#define Streight 1500 //-- default 1500//neutral 88 signal steering centered position for blinking arrow light (if seering center is 89 not zero: add or subtract half of Center value) 90 91#define Postsx 1000 //-- 92 default 1000//out rear servo sx end point (if inverted with postdx it reverse) 93#define 94 Postdx 2000 //-- default 2000//out rear servo dx endpoint (if inverted with postsx 95 it reverse) 96#define Center 0 //-- default 0//add or subtract your value to center 97 steering (+- 50 or more) 98 99//--------- user driving setup ------------------------------ 100 101 102#define Max_gain 400 //-- default 400//gain steering reduction width at max 103 throttle (if work reverse add (-) before value) 104#define Slowlimit 1600 //-- default 105 1600//slow forward percentage without endpoint correction 106#define Blinkpoint 107 300 //-- default 300//steering value where led start to blink, small values start 108 led blink close near to center 109#define Tolerance 0 //-- default 0//add/remove 110 stepper servo steering movement 111 112//---------------------------- 113#include 114 <Servo.h> 115Servo myservo; 116#define N_STST 7 //--default7//if servo response 117 is slow low this value to 4 values less 4 may give servo vibration 118#define 119 N_STGAS 7 //--default7//if servo response is slow low this value to 4 values less 120 4 may give servo vibration 121unsigned int stSt[ N_STST ]; 122unsigned int stGas[ 123 N_STGAS ]; 124long toStSt = 0; 125long toStGas = 0; 126int 127 inSt = 0; 128int inGas = 0; 129unsigned 130 int Rxpulse; 131unsigned int Gaspulse ; 132unsigned int Gain; 133unsigned int NewPos, 134 OldPos; 135int led1 = 4;//--led dx 136int led2 = 5;//-- led sx 137void setup() { 138for 139 ( int i=0; i<N_STST; i++ ) stSt[ i ] = 0; 140for ( int i=0; i<N_STGAS; i++ ) stGas[ 141 i ] = 0; 142myservo.attach(10); //-- rear servo signal out pin 10 143pinMode(8, 144 INPUT); //-- front servo signal in pin 8 145pinMode(7, INPUT); //-- throttle signal 146 in pin 7 147pinMode(led1, OUTPUT); 148pinMode(led2, OUTPUT); 149} 150void loop(){ 151 152 153 154 noInterrupts(); 155Rxpulse = pulseIn(8, HIGH); 156Gaspulse = pulseIn(7, 157 HIGH); 158 interrupts(); 159delay(5); 160if (Gaspulse > Slowlimit) { //-- 161 default >// if your throttle signal is reverse must change "<" 162Gain = map(Gaspulse, 163 Slowlimit, Maxspeed, 0, Max_gain ); 164NewPos = map(Rxpulse, Antsx, Antdx, (Postsx 165 + Gain), (Postdx - Gain)); 166 } 167else { 168NewPos = map(Rxpulse, Antsx, Antdx, 169 Postsx, Postdx); 170 } 171if (abs(NewPos - OldPos)> Tolerance) { 172OldPos = NewPos; 173myservo.write(NewPos 174 + Center); 175 176if (OldPos > Streight+Blinkpoint) digitalWrite(led1, (millis() 177 / 100) % 2); //--default 100 is led blink speed 178 179 else digitalWrite(led1, 180 LOW); 181if (OldPos < Streight-Blinkpoint) digitalWrite(led2, (millis() / 100) 182 % 2); //--default 100 is led blink speed 183 184 else digitalWrite(led2, 185 LOW); 186 187} 188}
Downloadable files
pin plug breadboard
pin plug breadboard
schematics
schematics
3
without led
3
1 basic
basic connection to nano board
1 basic
3
without led
3
1 basic
basic connection to nano board
1 basic
schematics
schematics
pin plug breadboard
pin plug breadboard
2
connection with y cords and led blinking lights
2
Comments
Only logged in users can leave comments
wrighi
4 years ago
also you can look at 3ch version, it have more functions, brakes and beam lights. basically the two projects are so similar, 3ch version can be used as the same with 2ch radio. or copy the code lines about brake and beam from 3ch scketch to this.
wrighi
5 years ago
yesterday I added brakes.. https://vimeo.com/434351978
wrighi
2 years ago
also you can look at 3ch version, it have more functions, brakes and beam lights. basically the two projects are so similar, 3ch version can be used as the same with 2ch radio. or copy the code lines about brake and beam from 3ch scketch to this.