Hi,
I have a couple of RC cars and have 3 relatively cheap Tx/Rx combos. These combos suit my needs with the exception of the one for my on-road race car, the missing functionality is expo. On the high speed straights the steering is too sensitive and I would like to soften it.
I thought of doing an Arduino project reading out the steering channel PWM signal from the receiver and via an algorithm change it to create the expo functionality.
This is a photo of what I want to achieve, depending on the value of a potentiometer have a certain degree of expo (t (for "thickness" of expo)).
Vertical axis: PWM signal from uC to servo
Horizontal axis: PWM signal from receiver to uC
This is a photo of the electrical circuit I think I need. (I have left out the transponder)
This is the sketch so far, I have divided it into "chapters" (A, B, C & D) to help discussing it.
/*
Sketch: "poor_mans_expo"
This sketch is to be used in an electrical circuit on the steering channel
of a model RC car to add the expo functionality when this
functionality is not present in the Tx/Rx combo
The sketch is written for use in a ATtiny45 uC.
The two reasons for this project are learning and to save the need
for a more expensive high end Tx/Rx combo.
by Leo Groeneveld
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potPin = 2; // select the input pin for the potentiometer (hardware pin 7 on ATtiny45)
int pin = 1; // select the input pin for the PWM signal from the receiver ch. 1 (hardware pin 6 on ATtiny45)
int val = 0; // variable to store the value coming from the sensor
unsigned long duration;
/*
Put example code here during programming, remove after use.
*/
void setup() {
pinMode(pin, INPUT);
myservo.attach(0); // attaches the servo on pin 0 to the servo object (hardware pin 5 on ATtiny45)
}
void loop() {
/*
A) In this part of the sketch the pulse width of the receiver signal to the servo is read.
*/
duration = pulseIn(pin, HIGH); // read the PWM signal from the receiver ch. 1
/*
B) In this part of the sketch the adjustment of the potentiometer is read.
This adjustment is used to set the level of expo of the signal to the servo.
*/
val = analogRead(potPin); // read the value from the potentiometer
/*
C) In this part of the sketch the algorithm is located to calculate the PWM signal to the servo from
the PWM signal from the receiver and the adjustment of the potentiometer.
*/
// The result is a value (val) between 1 and 179 that is to be sent to the servo. (This the the TROUBLE AREA)
/*
D) In this part of the sketch the calculated value of the PWM signal is sent to the servo.
*/
myservo.write(val); // sets the servo position according to the scaled value
delay(5); // waits for the servo to get there (I'm not sure this line is needed due to the minimum delay of 18ms in PWM signal between pulses)
// Now start again.
}
Now the main question:
Because I'm not able to do the math needed to write the algorithm, can you please help me with that?
Regards,
Leo