Preventing the car from crashing
How can I add manual over-ride?
In order to take control if my car is on its way to trouble, I wanted to setup my car such that if it detects input from the remote control, it will obey that input. If it does not detect that input, it will continue to operate autonomously.
How should I wire the arduino such that it detects the signal from the radio receiver?
After unsuccessfully trying to use a range of rc car receiver reading libraries (e.g., servodecode), I ended up getting PPMrcin (GitHub - domenicomonaco/PPM-Signal-Reader-ARDUINO: Arduino PPM signal reader/decoder Library) to work. To do the wiring, I used this tutorial: http://pillsofbits.com/project/libreria-di-arduino-leggere-segnali-ppm.
How should I code the arduino such that it detects the signal from the radio receiver?
To get the library working, I had to change the references from Wprogram.h to Arduino.h in the files PPMrcIn.cpp and PPMrcIn.h. I also had to install the Statistic library (GitHub - domenicomonaco/Arduino-Statistic-Library: Simple Statistic Library).
How should I code the arduino such that manual over-ride works?
If the basic idea is that the car will operate autonomously unless it receives input from the radio receiver, then I need to write some code that will detect whether or not input is received and, if so, to pass that input to the car's speed control.
This is what I came up with. It worked great for my purposes.
// Adapted from:
//
// ReadSignalFromRC.pde
// Example for PPMrcIn Arduino Library
//
// Created by Domenico Monaco on 20/11/2011
// Copyright 2011 Domenico Monaco - domenico.monaco@kiuz.it
//
// License: GNU v2
//
// Also
// Sweep
// by BARRAGAN http://barraganstudio.com
// This example code is in the public domain.
// include libraries & initialize class for reading signal
#include <PPMrcIn.h>
#include <Statistic.h>
Channel channel1;
// include libraries & initialize class for sending signal
#include <Servo.h>
Servo myservo;
int pulseWidth;
// specify discrepancy between pulse width received and sent
// and receiver neutral range
int receiveSendOffset = 50;
int receiverSignal;
int neutralMin = 1480;
int neutralMax = 1520;
void setup() {
Serial.begin(9600);
// prepare reading of receiver
Serial.println("Ready:");
pinMode (13, INPUT);
channel1.init(1,13);
// prepare writing of speed control
myservo.attach(9);
delay(5000);
}
void loop() {
// read the receiver signal
channel1.readSignal();
receiverSignal = channel1.getSignal() + receiveSendOffset;
// if the receiver signal is neutral, then let the car drive itself
if(receiverSignal >= neutralMin && receiverSignal <= neutralMax)
{
Serial.println(receiverSignal);
Serial.println("Automatic");
myservo.write(1500);
delay(1000);
}
// if the receiver signal is not neutral, then let the driver drive the car
else
{
Serial.println(receiverSignal);
Serial.println("Manual");
myservo.write(receiverSignal);
delay(1000);
}