Shop OBEX P1 Docs P2 Docs Learn Events
Rockem Sockem Robots — Parallax Forums

Rockem Sockem Robots

RobbyjoeusnRobbyjoeusn Posts: 4
edited 2012-07-15 08:42 in Learn with BlocklyProp
For my final project in my class we have to design, build, code etc, something practical and exciting beyond the scope of "whats a microcontroller" I'm going to attempt to make rockem sockem fighters using pushbuttons to control servo "punhcing function" pushbuttons as targets on the robots, and leds, lcds, buzzer etc, for theatrics. Can someone just simply explain code for using one pushbutton for clockwise the whole range of motion quickly "like a punch" and retract either using the same pushbutton or a very short amount of time, so an additional punch could happen, Im not sure if its an

if (PB1=1) then
pulsout, pin, one extreme
pause
etc etc
other extreme
and a loop while or loop until

ideally, I'd like each player to have a pushbutton that when they hit it, it does the entire servo range quickly, then when they hit it again it comes back(or it comes back on its own after a short time like I mentioned), then again it punches, all the other craziness, like the buzzer, leds, lcds, is fine, I just figure theres an easier way then using 2 pushbuttons, since I have everything wired on with 22gauge and theres PVC pipe and action figures and a mess, one pushbutton is gotta be the way.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-07-15 08:42
    First of all, servos require multiple pulses, about 50 times a second or they will stop moving. Second, they're not that fast. Most servos need a sizable fraction of a second to move from one end of their range to the other. You can get specialized servos with less gearing that move more quickly, but it sounds like you need to think this through more.

    Have you read "Robotics with the BoeBot"? It discusses in detail how to control servos with a Stamp. It mostly deals with continuous motion servos (like those used for the BoeBot's wheels), but the same things apply for standard servos.

    You're going to have problems with just testing for the pushbuttons being pressed. What happens if the servo finishes moving and you haven't let go of the button yet? Usually a program will test for the button being released first, then being pushed a moment later. You can use the BUTTON statement to handle this and "debouncing". BUTTON acts like a GOTO when a button is pushed and it makes sure that the button is actually pushed, not still down from an earlier button press. You'd have a variable with the desired position (pulse width) for a servo and change the variable value from one extreme to the other when the pushbutton is pushed. You could do this in a loop along with the PULSOUTs for each of the servos (using the variable values you've set) and maybe a little delay to bring the loop time up to around 20ms (for the servos). This is similar to what you've sketched out, but the details are different.
Sign In or Register to comment.