Pages: [1]   Go Down
Author Topic: READ Radio control car inputs with arduino  (Read 2485 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

halo people,

i am making a project where it involves an RC car(i am using traxxas 1/16 e-revo) and integrated with arduino.

the idea is this: the car would normally be run with the provided radio control transmitter. i want the arduino to be able to read the pulse input (perhaps i can use pulse in -advice me!!) from the RECEIVER of the radio-control. when the arduino acknowledge the pwm from the transmitter to receiver, then the arduino can send the corresponding PWM to the ESC(electronic speed control) then to the motor. i want the arduino to have the capability to read the input i press from the radio control transmitter which is sent to the receiver.

when the arduino can read the inputs, i believe i can do hell lots of manupulating of the RC behaviour with the arduino. (this is one of the main of obstacle of my project). anybody has suggestions?

oya one, just wanna this is the rough idea without any pulses manupulation(so take input from receiver and output to the ESC)
can i use the code like this:

"pulsein (read from the receiver) = pulsout(write to the ESC-motor)"

therefore, it will act exactly the same as the default radio control function but with the arduino as the middleman and able to read what is happening.
thank you in advance


RC - robotic freak
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26280
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And what did your searches of the forum throw up?

Quote
when the arduino can read the inputs, i believe i can do hell lots of manupulating of the RC behaviour with the arduino. (this is one of the main of obstacle of my project).

Did you mean "objective", rather than "obstacle"?

Do you think you could share your objectives?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Ohio
Offline Offline
Full Member
***
Karma: 0
Posts: 227
Arduino Hexapod
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There are a number of ways to read in the output of a RC receiver.
I am not a fan of pulse in.  It locks up the Arduino while it is waiting for the signal.  I would use interrupts.  This leaves the Arduino free to work on other tasks while it waits for the signal to change.
If you have a receiver that you can hack to get the Puls stream, then you can read in all the channels on one pin.
If you only need 2 channels, you can use 2 pins and the 2 available interrupts.
If you have a Mega, you can read up to 6 channels on 6 pins using 6 interrupts.
There are some other configurations possible.  I just bough a package of diodes from Radio Shack so that I can try putting multiple channels on 1 pin without the need to open the receiver up and find the pulse stream.  I will let you know how that goes.

So, how many channels do you want to read in from your receiver?  Which Arduino board do you have?

If you need 2 channels, I have some sample code that should get you started.

Out of curiosity, what manipulation do you want to do to the RC control?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

heloo, thank you guys for the replies

actually the big picture of my project is " radio control car with roll-over detection". microcontroller with IMU to be integrated with the radio control car system(receiver, ESC and steering servo).man,i cant paste pictures here can i? if not it would be easier since i have the rough schematic. anyway part of the objective is to be able to read the RC receiver inputs.

i came across an idea of either using pulsein(which i am not sure at all it will work) or use analogread(to read voltage value straight from the receiver)(i believe that pwm generated from the receiver is simply a varying voltage perhaps 0v-5v that could be read in the arduino then i can output exactly the same voltage to the motor ESC, what do you guys think? i am going to try this idea today).

i want to try the interrupts you suggested but i really do not know at all about it, any references or sample code?

thanks guys

Logged

0
Offline Offline
Edison Member
*
Karma: 0
Posts: 1103
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Before you proceed, please understand the PPM signal used in RC applications. This is very, very easy; and after it, there is no need to write funny things about analogRead of different channels anymore or ask irrelevant questions  smiley-wink
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1253149521/0#0

N.B. And pulseIn () will be fine for a start. http://arduino.cc/en/Reference/PulseIn
« Last Edit: August 30, 2010, 12:34:47 pm by mpeuser » Logged

Ohio
Offline Offline
Full Member
***
Karma: 0
Posts: 227
Arduino Hexapod
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So, how many channels do you want to read in from your receiver?
Quote
Which Arduino board do you have?

I have sample code, but it is tailored to my needs.  If you give me some feedback, I can make examples that will suit.
« Last Edit: August 30, 2010, 02:39:23 pm by vinceherman » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To get a ppm stream from a rc receiver, I have been successful with both diode's and OR-gate's. for OR-gate, put all channels on the input and put output to one of the interrupt pins on arduino. for diodes, hook one up to each channel, then connect them all to one of the interrupt pins. this will work with almost all rc receivers. but not all of them.

I did not write the following bit of code, but it works.

Code:
#define icpPin            8         // this interrupt handler must use pin 8
#define TICKS_PER_uS      2          // number of timer ticks per microsecond
#define MAX_CHANNELS    8         // maximum number of channels we can store  
#define SYNC_GAP_LEN      (3000 * TICKS_PER_uS) // we assume a space at least 3000us is sync (note clock counts in 0.5 us ticks)
volatile unsigned int Pulses[ MAX_CHANNELS + 1]; // array holding channel pulses width value in microseconds
volatile uint8_t  Channel;      // number of channels detected so far in the frame (first channel is 1)
volatile uint8_t State;         // this will be one of the following states:
#define NOT_SYNCHED_state  0    // the system is not synched so the data is random
#define ACQUIRING_state  1      // one sync pulse detected but not all channels have been received
#define READY_state     2       // synched and all channel data is valid


ISR(TIMER1_CAPT_vect){
   if(! bit_is_set(TCCR1B ,ICES1)){       // was falling edge detected ?  
       TCNT1 = 0;               // reset the counter
       if(Channel <= MAX_CHANNELS) {
           Pulses[Channel++] = ICR1 / TICKS_PER_uS;  // store pulse length as microsoeconds
        }
   }
   else {                          // rising  edge was detected  
        TCNT1 = 0;               // reset the counter
        if(ICR1 >= SYNC_GAP_LEN){   // is the space between pulses big enough to be the SYNC
            Channel = 1;       // if so, reset the channel counter to 1
              if(State == NOT_SYNCHED_state)
                  State = ACQUIRING_state;        // this is the first sync pulse, we need one more to fill the channel data array
              else if( State == ACQUIRING_state)    
                   State = READY_state;           // this is the second sync so flag that channel data is valid
        }    
   }    
   TCCR1B ^= _BV(ICES1);                 // toggle bit value to trigger on the other edge    
}

void setup()                    // run once, when the sketch starts
{
  Serial.begin(9600);  
  pinMode(icpPin,INPUT);
  Channel = 1;
  State = NOT_SYNCHED_state;
  TCCR1A = 0x00;         // COM1A1=0, COM1A0=0 => Disconnect Pin OC1 from Timer/Counter 1 -- PWM11=0,PWM10=0 => PWM Operation disabled
  TCCR1B = 0x02;         // 16MHz clock with prescaler means TCNT1 increments every .5 uS (cs11 bit set
  TIMSK1 = _BV(ICIE1);   // enable input capture interrupt for timer 1
}

int GetChannelPulseWidth( uint8_t channel) {
  // this is the access function for channel data
  int result;  
  if( (State == READY_state)  && (channel > 0) && (channel <=  MAX_CHANNELS)  ) {
     cli();             //disable interrupts
     result =  Pulses[channel] ;
     sei();             // enable interrupts
  }
  else
     result = 0;        // return 0 if no valid pulse is available  

  return result;

}

void loop()                     // run over and over again
{
int pulsewidth;

   // print the decoder state
   if(State == NOT_SYNCHED_state)
       Serial.println("The decoder has not detected a synch pulse ");  
   else if ( State == ACQUIRING_state)
       Serial.println("The decoder has detected one synch pulse and has started filling channel data");  
   else if( State == READY_state)
     Serial.println("The decoder is synched and the channel data is valid");  
   else
     Serial.println("Unknown decoder state, this should never happen!");
  

  // now print the channel pulse widths
  // they should be 0 if the state is not ready
  for ( int i =1; i <=4; i++ ){ // print the status of the first four channels
      Serial.print("Channel ");
      Serial.print(i);
      Serial.print(" has width ");
      pulsewidth = GetChannelPulseWidth(i);
      Serial.println(pulsewidth);
  }
  delay(100); // update 10 times a second        
}
 
Logged

0
Offline Offline
Edison Member
*
Karma: 0
Posts: 1103
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So you are using ready-made code. That is fine as you can now concentrate on your application. Sorry I misunderstood your first posting..
« Last Edit: August 30, 2010, 03:43:48 pm by mpeuser » Logged

Ohio
Offline Offline
Full Member
***
Karma: 0
Posts: 227
Arduino Hexapod
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
To get a ppm stream from a rc receiver, I have been successful with both diode's and OR-gate's. for OR-gate, put all channels on the input and put output to one of the interrupt pins on arduino. for diodes, hook one up to each channel, then connect them all to one of the interrupt pins. this will work with almost all rc receivers. but not all of them.

I will have to try that.  I was under the impression that there would not be a drop in the signal between each channel if they are all or'd together.
One scheme I was going to try was just or'ing together the odd channels, and the even channels would be the period of low between the adjacent odd channel highs.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

no worries man, it pretty useful too, i wont know if you didnt mention, thanks guys for the advices.

man interupt is pretty complex but i will give it a try after trying readanalog and pulsein. i dont have the time to try out yet today cos i am still waiting stuff.

oya, what i need to read is 2 channel from the receiver which is the  pulseout to the ESC and pulseout to steering servo from the receiver.

i am going to try it with arduino duminelove first then if i succeed i gonna replace it with smaller footprint chip - arduino mini pro that i can fit onto the car.

i believe i can control the steering servo and motor ESC with PWM of 1.2ms-1.5ms. however, my problem is to read the inputs (channel 1 for the ESC and channel 2 for the steering servo) from the receiver.

simply put, i need to have the arduino as the middleman between the receiver and (motor esc, steering servo).
so whatever pulses come out of the receiver have to go through the arduino first but the RC car has to be able to operate as NORMAL(meaning i can control and run it as default with the transmitter with no negligible bottlenecks or variations).

guys ,can you tell me how to upload pictures here, it tried pressing insert image but only words came out. i got the schematic that i can show.

Logged

Pages: [1]   Go Up
Jump to: