Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* this shetch allow yo use a poor quality 2ch radio to control 4ws
- * the inversely proportional steering percentage is related to the rear servo end point values.
- * when the correction value increases, the end point decreases, zero correction enables 4 steering wheels at any speed
- * before setting the steering inversely percentage it is better to have set the rear end point values first
- * this because if you go over the top you turn the servo direction
- * you will have to try to find the right compromise, in any case it is easy to understand
- * values here in define list are only default, you will have to modify them according to your model
- * the connections are: pin 7 throttle signal, pin 8 steering signal, pin 10 rear servo output
- */
- #define antsx 1000 //-- in front servo endpoint sx
- #define antdx 2000 //-- in front servo endpoint dx
- #define postsx 50//-- out rear servo sx if inverted with postdx it reverse
- #define postdx 130 //-- out rear servo dx if inverted with postsx it reverse
- #define center 0 //-- add or subtract xx value to center steering
- #define tolerance 5 //-- if your poor quality servo vibrates try 5
- #define max_correction 50 //--amount steering by throttle
- #include <Servo.h>
- Servo myservo;
- unsigned int rxpulse;
- unsigned int gaspulse;
- unsigned int correction;
- unsigned int newPos, oldPos;
- void setup() {
- myservo.attach(10); //-- rear servo signal out pin
- pinMode(8, INPUT); //-- front servo signal in pin
- pinMode(7, INPUT); //-- throttle signal in pin
- }
- void loop() {
- rxpulse = pulseIn(8, HIGH);
- gaspulse = pulseIn(7, HIGH);
- correction = map(gaspulse, antsx, antdx, 0, max_correction);
- newPos = map(rxpulse, antsx, antdx, (postsx+correction), (postdx-correction));
- if (abs(newPos - oldPos)> tolerance) {
- oldPos = newPos;
- myservo.write(newPos + center);
- }
- }
Add Comment
Please, Sign In to add comment