Hi Geniuses,
I am in the process of learning the arduino basics to enable me to use an arduino with an rc controller to control a childs electric car. The desired outcome is that the child in the car can control the car (child guided) using the normal in car controls, and whilst the child is learning to use the car, or before they are able to use the car properly, I can drive the child around (parent guided) using an rc transmitter.
The in-car controls, perhaps unsurprisingly are:
- Steering wheel (connected mechanically to the steering rack, but also has a servo motor on the rack to steer with a motor).
- Throttle pedal (currently only on or off, but would like to make this proportional)
- Gear stick - This has 3 positions, forwards, neutral, reverse
I would like to be able to have three modes of operation.
- Ability to have full parent guided control over the car regardless of what the child does with the controls
- Child to guide the car, and the parent to be able to override the steering or throttle if required
- Complete child guidance with no need for the rc transmitter to be turned on
These modes should be controlled via a switch in the car.
I have a fair bit of experience with RC gear having flown rc aircraft for about 10 years. I have a good working understanding of channels and PWM outputs.
I have already made some headway, and already successfully made the car "parent guided/remote control) by implementing a rc receiver in the car, using a standard brushed speed controller for the drive, and a H-bridge connected to a potentiometer for steering.
A bit more on the steering, I have used a servo (with servo motor removed) to determine the position of the steering. I have connected the wires that would normally go the servo motor to a H-bridge to drive a large motor to control the steering. This works well.
The Throttle is fairly straightforward and works out of the box as its a standard rc setup.
OK, here are my questions/assumptions.
Inputs
- RC Steering control signal
- RC throttle Signal
- In car steering control signal
- In car throttle Signal
- In car driving mode switch (to select child guided or parent guided)
- In car gear stick (To determine neutral, forward, reverse).
I have already written some code in Arduino to do something similar but it doesn't work as i'd expect
Before I show the code - this is what is supposed to happen:
I have a potentiometer on A0 - When the potentiometer is providing a value of less than 1000, then LEDS should light up dependant on the position of the steering wheel signal
If the potentiometer on A0 is providing a value greater than 1000pwm, then do nothing.
I am guessing this is how i'd structure the code for the entier thing. Three big if statements, one for each driving mode:
- parent guided
- child guided (with parent over ride)
- child guided
Question 1 - Can someone please let me know if I am heading in the right direction....
Here is the code with just one mode for now..
/*
This sketch uses a single RC input - RC Steering input on Pin 6 turns LEDs on and off depending on the steering wheel position.
There is a Potentiometer on input A0 that determines whether the below behavior is invoked or not.
If the Potentiometer value is less than or = 1000, run the below code:
If the steering is neutral, where the RC input is PWM between 1400 and 1500 - The Yellow LED should light up
If the steering is full left, where the RC input is PWM less than 1400 - The Green LED should light up
If the steering is full right, where the RC input is PWM greater than 1500 - the Red LED should light up
If the Potentiometer value is greater than 1000 = turn all LEDS off an do nothing.
*/
int rcsteering;
int rcthrottle;
int rcdrivemode;
int sensorValue = 0;
int RedLedPin = 13;
int YellowLedPin = 12;
int GreenLedPin = 8;
void setup() { // put your setup code here, to run once:
// Initialize RC inputs
pinMode(3, INPUT); // RC Throttle input
pinMode(6, INPUT); // RC Steering input
pinMode(5, INPUT); // RC Driving Mode input
//Initialize Manual inputs
pinMode(A0, INPUT);
// Initialize LED Outputs
pinMode(RedLedPin, OUTPUT); // Red
pinMode(YellowLedPin, OUTPUT); // Yellow
pinMode(GreenLedPin, OUTPUT); // Green
Serial.begin(9600);
Serial.println("Initialise");
}
void loop() {
// put your main code here, to run repeatedly:
rcsteering = pulseIn(6, HIGH, 25000);
sensorValue = analogRead(A0);
/*Serial.print("Steering");
Serial.print(rcsteering);
Serial.println(" ");*/
rcdrivemode = pulseIn(5, HIGH, 25000);
/*Serial.println(rcdrivemode);*/
Serial.println(sensorValue);
if (sensorValue <= 1000)
{
if (rcsteering <= 1400)
{
digitalWrite(GreenLedPin, HIGH);
digitalWrite(YellowLedPin, LOW);
digitalWrite(RedLedPin, LOW);
};
if (rcsteering >= 1400 && rcsteering <= 1500)
{
digitalWrite(YellowLedPin, HIGH);
digitalWrite(GreenLedPin, LOW);
digitalWrite(RedLedPin, LOW);
};
if (rcsteering >= 1500)
{
digitalWrite(RedLedPin, HIGH);
digitalWrite(GreenLedPin, LOW);
digitalWrite(YellowLedPin, LOW);
}
else
{
digitalWrite(YellowLedPin, LOW);
digitalWrite(GreenLedPin, LOW);
digitalWrite(RedLedPin, LOW);
};
}
}
When printing out the values of the PWM signal in the Serial window, every few seconds the pwm values seem to get lost - Should i be doing something clever with the pwm inputs when reading them in?
If anyone could point me in the general direction i'd be very grateful... And if I have not obeyed forum etiquette, please let me know, and i'll do better next time!
Thanks in advance guys (and girls)!
rich


