Shop OBEX P1 Docs P2 Docs Learn Events
Limiting Motor Action — Parallax Forums

Limiting Motor Action

ajit.nayak87ajit.nayak87 Posts: 76
edited 2014-02-08 06:54 in General Discussion
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



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

  • mklrobomklrobo Posts: 420
    edited 2014-02-03 17:20
    :cool: Can not visualize what you are trying to do. need a schematic of the hookup to the motors. What type of motors? If you could
    describe a model of what you have, I will attempt to help.:smile:
  • ajit.nayak87ajit.nayak87 Posts: 76
    edited 2014-02-03 19:59
    12.pdf-page-001.jpg

    I need code for this program
    1024 x 1325 - 78K
  • mklrobomklrobo Posts: 420
    edited 2014-02-04 03:31
    If code is what you need, I will try to locate some similar programs that may be of help. I assume you are working with the
    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.
  • ajit.nayak87ajit.nayak87 Posts: 76
    edited 2014-02-04 04:02
    ya thanks. can modify accordingly
  • mklrobomklrobo Posts: 420
    edited 2014-02-04 16:19
    I am begining work on my propeller project, with very similar code research to yours. I will research
    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.
  • ajit.nayak87ajit.nayak87 Posts: 76
    edited 2014-02-04 20:13
    Post your code so i can understand
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-02-05 09:07
    Do you have a source of position feedback? a rotary encoder?
  • mklrobomklrobo Posts: 420
    edited 2014-02-05 12:05
    :cool:
    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.:smile:
  • ajit.nayak87ajit.nayak87 Posts: 76
    edited 2014-02-05 20:14
    Do you have a source of position feedback? a rotary encoder?

    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
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-02-05 21:02
    I can do a lot of guessing, but that really won't help.

    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.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-02-06 07:19
    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

    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.
  • mklrobomklrobo Posts: 420
    edited 2014-02-06 07:41
    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.?)
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-02-06 18:24
    Well, the original poster seems to be using C in floating point maths, and maybe even circular degrees. I am not sure the BasicStamp2 has much to offer.

    If this is simply a case of overshoot because of the mass and the mechanics, a tigher range may just clear it up.
  • MicksterMickster Posts: 2,694
    edited 2014-02-07 06:32
    Sounds like you need to be looking at one of the PID objects. The one authored by "cweber" should be adequate.
  • mklrobomklrobo Posts: 420
    edited 2014-02-08 06:54
    The attached file is a servo that parallax sells. The have code for it in their basic stamp manual. I would use this as a model
    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:
Sign In or Register to comment.