RC Car Cruise Control
SteveWoodrough
Posts: 190
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
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
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
Propellers Rock
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Caught in the PropWash