Shop OBEX P1 Docs P2 Docs Learn Events
school project help — Parallax Forums

school project help

jessp118jessp118 Posts: 3
edited 2013-05-15 19:05 in BASIC Stamp
I'm in need of some help. I am using a stepper motor to open and close a gate depending on how far an object is from the ping sensor. My problem is that the motor will "pulsate" insted of staying at one location. Is there a way to have the server wait until the ping distance change and put it back through the if/elseif?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-05-06 11:17
    The type of motor you're using is an R/C Servo, not a stepper. Look at the descriptions in the Wikipedia for the differences.

    There are a variety of reasons for the servo to "twitch". One problem with your program is that you're producing the control pulses too fast. They need to happen once every 20ms or so. Add a PAUSE 20 after each PULSOUT for the servo and see what happens.
  • jessp118jessp118 Posts: 3
    edited 2013-05-06 18:34
    Adding the pause causes an undesired effect of a delayed response. We are in need of an almost instant reaction. the servo was listed as a "standard servo". I assumed that it was a stepper.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-05-06 18:42
    Another option is, instead of a FOR loop to open or close the gate, your IF statement changes the value of a variable to either 500 or 1000 (with one or the other as the initial value). You then have a single PULSOUT statement followed by a single PAUSE with the PULSOUT using the variable's value instead of a constant 500 or 1000. Your main loop then triggers the PING and gets the resulting time, converts time to distance, decides on which servo control pulse time to use (or keep the previous value), and sends out a control pulse to the servo. I'd compensate the PAUSE time to account for the PING delay. You'd use 20 - (the PING time in ms).
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-05-07 11:17
    jessp118 wrote: »
    Adding the pause causes an undesired effect of a delayed response. We are in need of an almost instant reaction.

    If the servo is refreshed every 20ms, this gives you 50Hz refresh rate.

    It's amazing what can be done at 50Hz. The 50Hz calculation rate is mentioned at 1:22 in the video.

    Does your system need a reaction time faster than the robots in the video? :smile:
  • jessp118jessp118 Posts: 3
    edited 2013-05-15 18:47
    Mike Green wrote: »
    Another option is, instead of a FOR loop to open or close the gate, your IF statement changes the value of a variable to either 500 or 1000 (with one or the other as the initial value). You then have a single PULSOUT statement followed by a single PAUSE with the PULSOUT using the variable's value instead of a constant 500 or 1000. Your main loop then triggers the PING and gets the resulting time, converts time to distance, decides on which servo control pulse time to use (or keep the previous value), and sends out a control pulse to the servo. I'd compensate the PAUSE time to account for the PING delay. You'd use 20 - (the PING time in ms).

    I'm don't really understand what you mean for the program. I am leaning toward getting the 4-phase unipolar stepper motor. Would that work better than the servo I'm currently using?

    I have updated the program with a single PAUSE 20 after the ENDIF.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-05-15 19:05
    A stepper motor is completely different from a servo motor and the programming is completely different. Each has its advantages and disadvantages. You could use a DC geared motor as well with an H-Bridge to interface to the Stamp. The Wikipedia has good articles on H-Bridges as well as stepper motors and RC Servo motors. It all depends on your gate and how much force it needs to open and close. Servo motors are usually the easiest to use since they include the motor, gearing, an H-Bridge, and position feedback. They're somewhat limited in the force that can be applied and in the distance to be moved although there are very strong servos and some that will do several turns (called winch servos).
Sign In or Register to comment.