Basic Stamp Cruise Control
in BASIC Stamp
I have a motor control project that has been Basic Stamp for a long time. I keep upgrading the type of STAMP I use for more speed, etc. I can use SX or anything version I need.
What I need to do here is use a command speed (0 to 255) and use it to control a motor that drives my project. In this case it is a Train.
I get feedback that is MPH (again in the form of 0 - 255).
I am looking for way to compare the command speed ("peddle" 0-255), look at the actual speed ("mph" 0-255)
and generate a new speed command (throttle - 0-255).
I will need a couple of variables I can adjust to close the loop but this is a routine I am unfamiliar with.
I would appreciate any help I can get. I would like to use my normal speed control to get myself to a particular speed then turn on the sub-routine so that the STAMP program will then hold the speed.
Anyone care to chime in here?
Greg
What I need to do here is use a command speed (0 to 255) and use it to control a motor that drives my project. In this case it is a Train.
I get feedback that is MPH (again in the form of 0 - 255).
I am looking for way to compare the command speed ("peddle" 0-255), look at the actual speed ("mph" 0-255)
and generate a new speed command (throttle - 0-255).
I will need a couple of variables I can adjust to close the loop but this is a routine I am unfamiliar with.
I would appreciate any help I can get. I would like to use my normal speed control to get myself to a particular speed then turn on the sub-routine so that the STAMP program will then hold the speed.
Anyone care to chime in here?
Greg
Comments
-Phil
That aside, how are you presently sending the throttle value and getting the actual speed back?
Its 1/8th scale.
I have a Dial on a Pot that I read with an A to D Converter. I generate a throttle number (0-255) and send it to a Hobby Servo that operates throttle on a carburetor.
I am using a gear tooth sensor on a wheel and COUNT to get my actual speed.
What I have now works well -- This is a rideable train.
When I go up small inclines I need to give the throttle a boost to keep up my speed. When I go down, I need to let up a little. Basic cruise control.
I just don't have a clue how to do such interactive programming.
If you want to see my train, go to :
Greg
Stamp controls everything on my train. Brakes, throttle, headlights, horn....
My current reliability is high. I would have my control loop turn the cruise control off if I touch any other control.
For anyone interested, I would be happy to describe the control system further but it is pretty boring.
Greg
4.5 mph is represented as 045 out of 255. Max speed is about 10 mph
On flat level ground with a small load, my throttle command of about the same number will give me the same speed.
Greg
-Phil
http://lals.org/
https://www.yelp.com/biz/los-angeles-live-steamers-railroad-museum-los-angeles
Just wonderful, thank you Greg!
Can you maybe post the stamp code you have or describe more precisely how the wonderful Nautilus is using the stamp(s)?
Because a cruise control with say up/down/clear/set is doable and just needs to fit into your existing setup.
And don't even think that this might be boring for anyone here...
nevermind, I found your youtube viedeos. Just wonderful.
Enjoy!
Mike
Basically what you need to do is use the difference between the speed the dial pot is set to and the actual speed you are measuring to adjust the throttle position. The difference between the set speed and the actual speed is the error, which would be used to determine how far and in what direction the throttle needs to move.
So the calculations are:
error = set speed – actual speed
throttle = error * (some function)
Determining the optimum function to use is the challenge. You might start with a linear function (error * X )
I had to go offline for a day or so.
I have seen the pid-control article. Maybe I had had a couple of martini's when I read it but it mostly confused me.
I appreciate your sample code above. I am going to give it a whirl again now that I have a little time to concentrate.
Thanks to all. I'll keep you posted.
I will start another thread to explain the project. I am just a bBasic hack so my code is not that great, however it works.
Greg
I'm back on this project and looking at your suggested code.
As I am not much of a software guy, I wince at the complicated IF THEN commands in PBasic.
First of all -- my loop is very slow. Currently, its 2 times a second.
Your suggested code offers a solution that determines how far off the actual speed is from the throttle, then corrects by 10% at a time. I get that and it seems like a good approach.
However, I need to ask about the code you suggest and the nesting within IF THEN, ELSEIF, ENDIF, etc.
I admit my eyes roll up when I try to grok the intricacies of IF THEN but I always assumed that ENDIF concluded the statement.
In your suggestion, you have an ENDIF, a statement and then follow with ELSE.
ELSEIF (speedIn < throttle) THEN
error = throttle - speedIn
IF (error > 5) THEN
error = error */ $0019 ' multiply by 10%
ELSE
error = 0
ENDIF
speedOut = throttle + error
ELSE
error = speedIn - throttle
IF (error > 5) THEN ...
I need to get that clear in my head first.
Thanks for your help --
Greg
Is this correct?
Makes more sense to me now.
Greg
This has to be one of the coolest projects using a Basic Stamp, thank you for sharing. I hope you found the answers you were looking for on this forum.
I am lucky to have this forum to push me over occasional bumps in the road.
Greg