wrighizilla

4ws steering servo with inversely prop gain

Apr 29th, 2020
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. /* this shetch allow yo use a poor quality 2ch radio to control 4ws
  2. * the inversely proportional steering percentage is related to the rear servo end point values.
  3. * when the correction value increases, the end point decreases, zero correction enables 4 steering wheels at any speed
  4. * before setting the steering inversely percentage it is better to have set the rear end point values first
  5. * this because if you go over the top you turn the servo direction
  6. * you will have to try to find the right compromise, in any case it is easy to understand
  7. * values here in define list are only default, you will have to modify them according to your model
  8. * the connections are: pin 7 throttle signal, pin 8 steering signal, pin 10 rear servo output
  9. */
  10. #define antsx 1000 //-- in front servo endpoint sx
  11. #define antdx 2000 //-- in front servo endpoint dx
  12. #define postsx 50//-- out rear servo sx if inverted with postdx it reverse
  13. #define postdx 130 //-- out rear servo dx if inverted with postsx it reverse
  14. #define center 0 //-- add or subtract xx value to center steering
  15. #define tolerance 5 //-- if your poor quality servo vibrates try 5
  16. #define max_correction 50 //--amount steering by throttle
  17.  
  18. #include <Servo.h>
  19. Servo myservo;
  20. unsigned int rxpulse;
  21. unsigned int gaspulse;
  22. unsigned int correction;
  23. unsigned int newPos, oldPos;
  24. void setup() {
  25. myservo.attach(10); //-- rear servo signal out pin
  26. pinMode(8, INPUT); //-- front servo signal in pin
  27. pinMode(7, INPUT); //-- throttle signal in pin
  28. }
  29. void loop() {
  30. rxpulse = pulseIn(8, HIGH);
  31. gaspulse = pulseIn(7, HIGH);
  32. correction = map(gaspulse, antsx, antdx, 0, max_correction);
  33. newPos = map(rxpulse, antsx, antdx, (postsx+correction), (postdx-correction));
  34. if (abs(newPos - oldPos)> tolerance) {
  35. oldPos = newPos;
  36.  
  37. myservo.write(newPos + center);
  38. }
  39. }
Add Comment
Please, Sign In to add comment