Limiting Motor Action
ajit.nayak87
Posts: 76
Dear all.
I need Some coding Help Here . I just simple.
I have two angles coming out Desired and actual. The Difference of angle Might positive or negative.
If it is positive move motor in forward Direction
If it is Negetive move motor in reverse Direction
If between outer and inner band limit motor stop
How to put this in code.???
I wanted to keep band limit within 2 degree.
if difference of degree >+/- 2 degee within stop motor else fw/reverse direction
I need Some coding Help Here . I just simple.
I have two angles coming out Desired and actual. The Difference of angle Might positive or negative.
If it is positive move motor in forward Direction
If it is Negetive move motor in reverse Direction
If between outer and inner band limit motor stop
How to put this in code.???
I wanted to keep band limit within 2 degree.
if difference of degree >+/- 2 degee within stop motor else fw/reverse direction
static enum dir{ FWD, REV, STOP }DIR; void Setup() { Serial.begin(9600); pinMode(IN1,OUTPUT); pinMode(IN2,OUTPUT); pinMode(PWM,OUTPUT); } void loop() { void actuate(){ if(abs(tracker_des_angle - tracker_actual_pos) > TRACK_BAND){ if(tracker_actual_pos > tracker_des_angle) DIR = REV; else DIR = FWD; } else{ DIR = STOP; } moveActuator(); } } void moveActuator(){ Serial.print("Actuator DIR:"); switch(DIR){ case FWD: moveFWD(); break; case REV: moveREV(); break; case STOP: moveSTOP(); break; } } void moveFWD(){ Serial.println(FWD); digitalWrite(IN1,1); digitalWrite(IN2,0); } void moveREV() { Serial.println(REV); digitalWrite(IN1,0);//spdt digitalWrite(IN1,1);//dpdt } void moveSTOP(){ Serial.println(STOP); //Serial.print("Actuator DIR:"); digitalWrite(IN1,0); digitalWrite(IN2,0); }
Comments
describe a model of what you have, I will attempt to help.
I need code for this program
propeller. Code looks similar to C++ fomat. The type of platform you are using is important. Electrical components may
help any "slights" that may occur in your circuit.
what you have presented, and go from there. I may have to use a generic motor, with code,
to use as a model for an explanation. Thanks.
Loopy byteloose has a good point. With the information so far, we can not solve the problem, but we can analyze the
problem with products from parallax. If I assume from the type of program to be from a propeller, then we can pick
products like the motor, transducers, etc., from parallax. We would need more informaton........please.
Yes i have the feedback for it.
Assume i have two values a and b ; a reads Desired and B reads Actual Position
if a-b> 2.0 degree ,move reverse
if a-b<-2.o degree,move Forward
if a-b within -2.0 & 2.0 stop Motor.
every 3 minute t changes degree i.e my desired degree which will be 3 degree say , my actual try to goes there & stop
Depending on whatever you are using for position sensing, this could be a mechanical problem or a software problem.
It seems as though you are using a couple of limit switches of some sort for feedback. The quality of the limit switches and their configuration could make it impossible to do any better than what you have.
The motor and gearbox may have backlash that contributes to the problem as well.
About all I can tell is that you are using some sort of basic h-bridge.
So if you need more precision, you need to tighten up whatever you can - the mechanical, the feedback devices, and the code.
If the mechanics of the motor are good, the better the resolution of the rotation sensors, the better the results. Trying to improve the software without improving the rotation sensors isn't going to succeed.
I suppose that you could try the following:
a-b>1.0 degree, move reverse
b-a>1.0 degree, move forward
if a-b withing +1 and -1, stop.
In that way, you may actually hold to less than 2 degrees motion. This is called Fudge Factoring. You just fool the device into behaving the way you want.
I have some information in PDF format, just simple intro stuff from a basic stamp manual. (Got to figure out how to attach a file.?)
If this is simply a case of overshoot because of the mass and the mechanics, a tigher range may just clear it up.
for whatever you are trying to do. If you are doing high amp stuff, (industrial), then a substantal investment of other equipment
would be needed. I would start with a cheap, small model to work out the "bugs" in the system, then go on to a higher level.
Specific information would be needed (motor in question) to give an answer for dedicated device. Good luck!:cool: