Shop OBEX P1 Docs P2 Docs Learn Events
New to programming, need help turning a motor — Parallax Forums

New to programming, need help turning a motor

goochiigoochii Posts: 4
edited 2011-11-19 14:21 in Learn with BlocklyProp
okay, so this is my first time on this website and i struggled to find anything that answered my problem. Sorry if this is the wrong topic area, but it seemed to fit.

To start off with some background, my classmate and i are doing a miniproject so to speak in our allied tech engineering class. We had never, ever even used any programming code before and kind of threw ourselves into unknown waters with this project. The goal was that this project can be set up in a hallway and detect people that walk by. When the people are detected, a motor spins a transmission, raising a head on a rod. That head would then look around the hallway then return to the resting position.

All the coding has been done in BASIC Stamp 2.5 and a Board of Education Microcontroller.

So far in programming we have successfully coded the raising, holding and dropping of this rod and head. However, what we cant do is that when the rod is holding in the upright position, a second motor will run and spin the head. unfortunately, the code is on a school computer and we cannot access it, but the code is some what simple.

it is something like:

IF IN0 = 1 THEN
duration = duration - 100
ENDIF

we have this setup for all possible combinations that require action from sensors. however, when the rod goes up to a holding state, we can get the motor to spin the head, just not evenly. What kind of code should we be writing in the subsystem for it to run evenly in both directions(forward and reverse)? or even better, how can we say something like, turn 85 degrees, turn 170 degrees reverse, turn 170 degrees forward, turn 85 degrees reverse, return to main program?

Any help is appreciated. i understand the post is long and can seem confusing so just ask for clarification where needed! thanks!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-11-19 10:48
    Your post is long, but there's some crucial information you haven't provided ... specifically what kind of motors and sensors are you talking about, how do you have them connected (a schematic would be helpful), and what is your program (attach the whole thing to a reply using the Go Advanced button and the attachment manager)? It's very difficult to advise you without the specifics of what you have and how you're trying to use it. Often people give pieces of their code in an attempt to save effort, but it's often the missing pieces that are the source of the problem.
  • goochiigoochii Posts: 4
    edited 2011-11-19 11:58
    Like i said, i dont have the exact code one me right now unfortunately. I understand that is a crucial part of understanding my problem. IN0 is a PIR sensor, this one exactly, http://www.parallax.com/Store/Sensors/ObjectDetection/tabid/176/CategoryID/51/List/0/SortField/0/Level/a/ProductID/83/Default.aspx.

    I should've stated this earlier, but the motors are being run by 2 GEARS EDS Speed controllers, one for each motor.
    http://guides.machinescience.org/file.php/29/GRS/LEDAnimation.gif

    For IN1 and IN2, these are just simple switches that work like limit switches. they look a lot like http://rocky.digikey.com/weblib/Omron/Web%20Photo/SS-5GL.jpg

    I
    t is a little hard to understand through words, but on the transmission when the code runs, there is a piece of metal that will spin on the axle that hits these switches and when the switche is hit, the motor stops.

    I'm not sure if you are familiar with the What's a Microcontroller? book, but this code was modeled straight form one of those.

    We have all of the main program running properly, we just do not know how to the motor run evenly. The area of the code in question reads something along the lines of:

    '
    Main Program
    '
    DO
    IF IN0=1 AND IN1=1 THEN ' meaning the motion detector and the limit switch for the upright position is tripped.
    GOSUB Spin 'Here we want the code to move to the subprogram below
    ENDIF


    '
    Subprograms
    '
    Spin:
    duration = 750 'this keeps the first motor from spinning, while keeping a pulse through the first speed controller.
    For X = 1 to 1000
    For x = 1 to 500
  • goochiigoochii Posts: 4
    edited 2011-11-19 12:03
    The motion sensor is
    http://www.parallax.com/Store/Sensors/ObjectDetection/tabid/176/CategoryID/51/List/0/SortField/0/Level/a/ProductID/83/Default.aspx

    the limit switch is something similar to
    http://rocky.digikey.com/weblib/Omron/Web Photo/SS01GL13D, SS5GL13D.jpg

    and the motors are run by this speed controller
    http://guides.machinescience.org/file.php/29/GRS/LEDAnimation.gif

    All of the programming runs perfectly except for this section. It is something along the lines of

    IF IN0 = 1 and IN2 = 1 THEN 'IN0 = 1 means the motion detector sees people and IN2=1 means the
    GOSUB Spin 'transmission is at its highest point
    ENDIF

    '
    Subprograms
    '

    Spin:
    duration = 750
    For x = 1 to 1000
    For x = 1 to 500
    pulsout 12, 500 '12 is the constant for the second motor
    NEXT
    For x= 501 to 1000
    pulsout 12, 1000
    NEXT
    NEXT
    RETURN

    This program is attempting to get a motor to run in one direction evenly, then another for the same length of time

    It may not be exactly correct, but i cannot access the code itself for about 40 hours. Anything you could understand form these two posts is greatly appreciated, but if not i understand completely!
  • Mike GreenMike Green Posts: 23,101
    edited 2011-11-19 12:53
    Your link for the motor controller just shows a picture of it. Please provide a link to a manual or other document that describes what it does.

    If your motor controller is supposed to behave like a servo motor and respond to pulses from roughly 1ms to roughly 2ms, your problem may be that the pulses are coming too quickly together. For a servo motor, there needs to be a 20ms pause between successive pulses and you don't have any pause in your program except for the execution time of the FOR / NEXT statements which isn't much. Put a PAUSE 20 after each PULSOUT and see what happens.
  • goochiigoochii Posts: 4
    edited 2011-11-19 14:21
    i believe that worked, according to what im being told by my classmate! thank you for your help, even though i was terrible at explaining the problem
Sign In or Register to comment.