Author Topic: PMW decoder  (Read 3319 times)

0 Members and 1 Guest are viewing this topic.

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
    • Exodus Rocketry
PMW decoder
« 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
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline hazzer123

  • Supreme Robot
  • *****
  • Posts: 460
  • Helpful? 3
Re: PMW decoder
« Reply #1 on: May 07, 2009, 02:14:22 PM »
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.
Imperial College Robotics Society
www.icrobotics.co.uk

Offline aludra_55

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: PMW decoder
« Reply #2 on: May 07, 2009, 02:28:08 PM »
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...
« Last Edit: May 07, 2009, 02:34:03 PM by aludra_55 »

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
    • Exodus Rocketry
Re: PMW decoder
« Reply #3 on: May 07, 2009, 02:39:30 PM »
exactly
you nailed it
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
    • Exodus Rocketry
Re: PMW decoder
« Reply #4 on: May 09, 2009, 06:15:01 AM »
is there any line of code I can use to do this?
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline SmAsH

  • Supreme Robot
  • *****
  • Posts: 3,959
  • Helpful? 75
  • SoR's Locale Electronics Nut.
Re: PMW decoder
« Reply #5 on: May 09, 2009, 06:21:04 AM »
you could set a pin high when sensor reaches threshold which you calibrate?
Howdy

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
    • Exodus Rocketry
Re: PMW decoder
« Reply #6 on: May 09, 2009, 06:38:21 AM »
still is there a exact line of code that can read the pulse width of a signal
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline SmAsH

  • Supreme Robot
  • *****
  • Posts: 3,959
  • Helpful? 75
  • SoR's Locale Electronics Nut.
Re: PMW decoder
« Reply #7 on: May 09, 2009, 06:40:55 AM »
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...
Howdy

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: PMW decoder
« Reply #8 on: May 09, 2009, 12:32:29 PM »
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.
« Last Edit: May 09, 2009, 12:39:48 PM by Webbot »
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
    • RazorConcepts
Re: PMW decoder
« Reply #9 on: May 09, 2009, 01:16:07 PM »
 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)

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
    • Exodus Rocketry
Re: PMW decoder
« Reply #10 on: May 09, 2009, 01:57:20 PM »
ok cool
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline BEAMer

  • Full Member
  • ***
  • Posts: 105
  • Helpful? 0
Re: PMW decoder
« Reply #11 on: May 10, 2009, 05:12:59 AM »
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.


Offline BEAMer

  • Full Member
  • ***
  • Posts: 105
  • Helpful? 0
Re: PMW decoder
« Reply #12 on: May 10, 2009, 05:14:46 AM »
by transition, i mean the transition from high to low/ low to high of the PWM pulse.

Offline arixrobotics

  • Full Member
  • ***
  • Posts: 119
  • Helpful? 3
    • TalasTronics WCIT KL2008 Fund Raising
Re: PMW decoder
« Reply #13 on: May 16, 2009, 11:05:01 PM »
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.



Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,702
  • Helpful? 173
    • Society of Robots
Re: PMW decoder
« Reply #14 on: May 29, 2009, 01:45:13 PM »
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


and dellagd, here is some code:
http://www.societyofrobots.com/robotforum/index.php?topic=3099.0

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
    • Exodus Rocketry
Re: PMW decoder
« Reply #15 on: June 01, 2009, 03:20:53 PM »
thx admin for the ACTUAL code
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

 


Get Your Ad Here