Shop OBEX P1 Docs P2 Docs Learn Events
RC Car Cruise Control — Parallax Forums

RC Car Cruise Control

SteveWoodroughSteveWoodrough Posts: 190
edited 2008-06-18 18:12 in BASIC Stamp
I need a way to close the loop on an RC car speed control.· Below is a very condensed version of the code.· Essentially I pick a system level routine, Go Forward, which references lower level routines, steer straight, run the motor forward.· I limit the pulse width in the constants section so that I do not overspeed the motor on the bench.· The trouble of course is that a pulse width of 800 (1600ms) will not yield a consistant wheel speed depending upon the torque demand of the load.· What I need is a way to monitor wheel or motor speed and adjust the pulse width to get and maintain the desired speed.

What is a good way to monitor the motor speed?·

I was consider making an encoder of sorts and using an opto reflective switch to monitor the motor speed.· Something in the back of my mind says that this will not work, since in order to monitor the motor speed I'll have stop sending pulses to the speed controller.· Has anybody solved this already?

Thanks...Steve



'
[noparse][[/noparse] Title ]
'{$STAMP BS2}
'{$PBASIC 2.5}
' '
'
[noparse][[/noparse] I/O Definitions ]

SpeedControl······ PIN···· 13············· ' Speed Control
SteeringServo····· PIN···· 12············· ' Steering Servo

'
[noparse][[/noparse] Variables]
PulseSteering·· VAR Word
PulseSpeed····· VAR Word
PulseCount····· VAR Word ' FOR...NEXT loop counter.
'
[noparse][[/noparse] Constants ]
Pulse············· CON·· 20········ ' number of msec delay for applypulse routine
ForwardLimit······ CON·· 800······· 'Fastest forward pulsout to speed controler
NeutralSpeed······ CON·· 750······· 'Neutral Speed Control Setting
ReverseLimit······ CON·· 700······· 'Fastest reverse pulsout to speed controler
LeftSteeringLimit· CON·· 1000······ 'Steering Servo Left Limit
NeutralSteering··· CON·· 750······· 'Steering Servo Neutral Position
RightSteeringLimit CON·· 550······· 'Steering Servo Right Limit
'
[noparse][[/noparse] Initialization ]
FOR PulseCount = 0 TO 100 STEP 1
· HIGH 5············ 'LED indicates initialization loop on
· GOSUB IDLE
NEXT
· LOW 5············· 'LED indicates initialization loop off
· LOW SpeedControl·· '· Drives speed control LOW should also install 10K pull down
···················· '· resistor as well
PulseCount = 0······ 'need to return pulsecount back to zero for future use
'
[noparse][[/noparse] Main Routine ]
DO
··· FOR PulseCount = 1 TO 100 STEP 1
··· GOSUB FORWARD
· NEXT
'· DO:LOOP············ ' DO:LOOP puts the program in a endless loop rather than END.
··················· 'END results in a Sleep mode that pulses the outputs on startup
'++++++++++++SUBROUTINES++++++++++++++++++++
APPLY_PULSE:
· PULSOUT SteeringServo,PulseSteering ' Apply the pulse.
· PULSOUT SpeedControl, PulseSpeed
· PAUSE pulse·· ' Constant defined above
RETURN
'
SERVO LEVEL SUBROUTINES
STEER_STRAIGHT:
· PulseSteering = NeutralSteering
RETURN

MOTOR_FORWARD:
· PulseSpeed = ForwardLimit
RETURN
'
SYSTEM LEVEL SUBROUTINES
FORWARD:
· GOSUB STEER_STRAIGHT
· GOSUB MOTOR_FORWARD
· GOSUB APPLY_PULSE
RETURN

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-06-13 03:23
    Encoders or counters are the way they do it in the real world. Depending on the resolution you want it can be as easy as a hall sensor and a magnet.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-06-13 14:21
    Steve,

    Most likely you will need an SX or Propeller Chip to do this. The BASIC Stamp won't be able to count encoder pulse and adjust the output pulses fast enough.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • SteveWoodroughSteveWoodrough Posts: 190
    edited 2008-06-14 13:09
    Thanks Chris. Something in the back of my mind made me feel this way too. I suppose that if the pulse count was high enough and the time period short enough I might be able to "fake" it. I'm about 1 mm away from ordering a propeller chip set!
  • Capn_DaveCapn_Dave Posts: 20
    edited 2008-06-18 18:12
    Ive been using propellers since they came out. They will definately do the trick. Fast/Simple. Just remember that the propeller I/O is 3.3V Max, any more will damage the device.

    Propellers Rockyeah.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Caught in the PropWash
Sign In or Register to comment.