Society of Robots - Robot Forum
Electronics => Electronics => Topic started by: dellagd on May 07, 2009, 02:08:19 PM
-
hi-
I am wanting to build a RC robot, but not just any R/C robot, I want this to be like one of those futute cars. it will be placedd on a table, with a rangefinder placed at a angle on the front.. the rangefinder will be able to sence when the table ends at abot 6 inches form the edge.
you will be controlling the robot and like once every 1/4 second it will stop and say" am I near the edge?" if no, it will give the controlles back to you, if yes, it says "master is driving me off the edge!"it will then take controll of the servos, back up, u turn, and hand the controlles back to you.
now what I want to know is that if a MCU can decode the signals from a R/C rx and then run them through the program, and if the program says " am I near the edge?" , no, recreate that signal and give it to the servos.
MAIN QUESTION:
can a microcontroller decode the PMW signals from a RC Rx
-
Yes it can. If the PWM signals are designed to be plugged straight into servos, then you just have to use your microcontroller to measure the length of a pulse. its the old 1.5ms means stop, 1 or 2ms mean go (forwards or backwards).
It would be nicer if the robot didn't stop every 1/4 second (as i think your other robot with the sonar did). You could take sensor readings between the pulses sent from the RC Rx and then have a more flowing, natural drive.
-
you could connect your rc receiver to one of the digital input pin in your microcontroller... then connect your servo input signal into one of the
PWM digital output pin of your microcontroller... then connect your range
finger into one of the input pin (either digital or analog depends on your
sensor) of your microcontroller...
then connect your range finder to take samples several times per second like 10 samples per second (10Hz)... then when your range finder detected the edge of the table, program your microcontroller do its U-turn routines.. then give the control back to you...
you could do this by sampling your receiver PWM signal... you have to use
a pulseIn command (or something similar) to measure the speed of the
duty cycle (just like what was mentioned above 1.5ms for stop then
1.0ms - 2.0ms would move it in opposite direction at certain speed...
the micro would try to decode what was being sent to the receiver and use
PWM features of your micro to drive the servo according to the command
from the receiver... once the range finder detects the edge of the table, then
it cuts off the user's remote control transmitter signal and the micro takes
over...
so usually the rc receiver directly connects to the servos... to accomplish your
car project, you have to bypass the signal by putting your micro in between
your rc receiver and servos... when range finder detects the edge of the table,
the micro takes over and does a u-turn, when it's all clear, then user regains
control...
-
exactly
you nailed it
-
is there any line of code I can use to do this?
-
you could set a pin high when sensor reaches threshold which you calibrate?
-
still is there a exact line of code that can read the pulse width of a signal
-
i wouldn't really know... there probably is...
and btw in the name its pwm... not pmw... i cant believe i didn't pick that one out before...
-
still is there a exact line of code that can read the pulse width of a signal
Some Basics have a pulseIn command but if your using C then you will need to:
1. Keep looping until the pin goes high (start of pulse).
2. Read the value from a timer
3. Keep looping until the pin goes low (end of pulse)
4. Read the timer again and subtract the original value
5. You can then convert the result into a time by knowing the cpu clock speed and the prescaler used by the timer
This means your software 'hangs' whilst measuring the pulse and you should really disable interrupts at stage 4 so that the measurement is as accurate as possible.
If you are using an Axon then there are examples around the forum for doing the same thing with other sonar sensors.
Alternatively use the Timer Input Capture pin
1. Set interrupt to happen on rising edge
2. In interrupt routine - read the value from the Timer Capture and store it, then change interrupt to happen on falling edge
3. In interrupt routine - read the value from the Timer Capture and subtract previously stored value
Since this is interrupt based then it wont slow your program down. You will still need to convert the answer based on cpu speed and prescaler. You will also be restricted by which IO pin you can use as there is only one capture pin per 16 bit timer.
Other alternatives for ATMega168 and 640 include using pin change interrupts in the same way as the Timer Input Capture above.
So the quick answer is 'no - there is not one line of code'. But I will be adding one to my library ! ;)
The alternative: if the incoming PWM is a continuous stream then you can convert it to analogue (ie a voltage) using a low pass filter and then conect that to your analogue input on the processor. This wont be as accurate but takes the load off the processor.
-
Arduino has a nice built in function called pulseIn that is used by a lot of people to measure RC signals (the UAVs with the Ardupilot use that method for reading signals)
-
ok cool
-
hi...
even PIC microcontrollers have a built in module called CCP (Compare, Capture and PWM)
you can use the capture mode to capture the exact instant when the transition occurs.
-
by transition, i mean the transition from high to low/ low to high of the PWM pulse.
-
I've used the 'convert PWM to analogue' technique before for one of my projects. Its less accurate, but for my application (RC switch), it good enough (and easy). I've attached a circuit diagram that will convert the PWM to analogue signal, if you are interested. Hope it helps.
PS: I found the circuit diagram sometime ago on the internet and saved it to my disk. I don't remember where I got it, but its definitely not mine.
-
PS: I found the circuit diagram sometime ago on the internet and saved it to my disk. I don't remember where I got it, but its definitely not mine.
You got it from SoR (where else? :P)
http://www.societyofrobots.com/remote_control_robot.shtml (http://www.societyofrobots.com/remote_control_robot.shtml)
and dellagd, here is some code:
http://www.societyofrobots.com/robotforum/index.php?topic=3099.0 (http://www.societyofrobots.com/robotforum/index.php?topic=3099.0)
-
thx admin for the ACTUAL code