Thursday, November 15, 2012

First R/C Test Using Arduino Uno

The objective of this test was to learn how to read the R/C (Radio Control) receiver signal, convert it and write the correct values to the speed controller. For this test, just one motor is being used.

First step:

Reading the R/C Receiver signal from channel 3, print them on the screen in order to know the min and max values, and then convert the input range to the output range (ESCs' range)
ESC - Electronic Speed Controller


So, the channel 3 of the R/C receiver was connected to the Arduino's digital pin 2 and this was the code used to establish the connection:
  attachInterrupt(2,rc1,CHANGE);


By this time I just knew this way to make the connection between the Arduino and the R/C receiver:


Later I found out that the Arduino UNO has just 2 external interrupts (pins 2 and 3), which would limit us to read just 2 PPM channels (for the hexa control, we need at least 4).

This was solved by using the PinChangeInt.h library and this code to establish the connection:
   PCintPort::attachInterrupt(THROTTLE_IN_PIN, rc1,CHANGE);

By using this code we are able to use any digital port of arduino to read the R/C signals.

This was used to determine the min and max values of the throttle:
Serial.println(RCVal1);


Min = 1108
Max = 1900


So the range is almost the values accepted by the ESCs (in microsseconds - distance between the PPM pulses). But, the min value happens when the throttle control is on the top, and the Max value is when the throttle control is at bottom position. This way, we needed to convert the range using the map function so we could write the correct values to the ESC:

Using angles:
map(RCVal1, 1900, 1108, 0, 180)

Using microseconds:
map(RCVal1, 1900, 1108, 1000, 2000)



Second step:
Connect the ESC to the digital pin 11 and write the correct values to it according to the input from the R/C control.

There are 2 ways of writing the values to the ESC. First I used the servo angles, using:
0 - as the minimum speed, and
180 - as the maximum speed

servo1.write(map(RCVal1, 1900, 1108, 0, 180));

It works, but after testing by writing the microseconds, I had the impression that this way is more accurate (better response). So, this is the code that is being used:

servo1.attach(11);
servo1.writeMicroseconds(map(RCVal1, 1900, 1108, 1000, 2000));


The Hardware config was:
R/C    >>>    R/C Receiver  ---> Arduino Digital Pin 2 as input --> Software --> Arduino Digital Pin 11 as output (PWM) --> ESC --> Motor


Here is the result:





No comments:

Post a Comment