Shop OBEX P1 Docs P2 Docs Learn Events
Robotic fish help BS1 servo trouble — Parallax Forums

Robotic fish help BS1 servo trouble

bryansc4bryansc4 Posts: 36
edited 2012-04-23 12:35 in Robotics
I am using a basic stamp one to control two servos for a fish tail. I need to actuate the servos left and right repeatedly. I'm having a bunch of trouble getting the servos to actuate. I am using a traxxas 2019 non modified servo. please help me get started with a code to actuate the servos. Also the movement needs to be pretty quick.

Thanks
«13

Comments

  • TtailspinTtailspin Posts: 1,326
    edited 2012-03-03 20:04
    Welcome bryansc4,
    Down toward the bottom of this page, you can find some code you can download for some instant fun...
    http://www.parallax.com/Store/Accessories/MotorServos/tabid/163/CategoryID/57/List/0/SortField/0/Level/a/ProductID/101/Default.aspx
    But you will get more use from this link though...
    http://www.parallax.com/Store/Books/EducationalTexts/tabid/181/List/0/CategoryID/66/Level/a/SortField/0/Default.aspx
    And You can download the pdf files for free, if you don't want to buy the hard copies...:thumb:

    -Tommy
  • bryansc4bryansc4 Posts: 36
    edited 2012-03-04 08:07
    thanks for the literature, but I still seem to be having an issue with getting the motor to go more than one direction. I tried to do this:

    start:
    pulsout 7, 85
    pause 50
    pulsout 7, 175
    pause 50
    goto start

    it will go to the first position at pulsout7, 85 then just stops and twitches. I've been at this for hours and all I want to do is make it turn about 120 degrees back and forth non stop.
  • ercoerco Posts: 20,255
    edited 2012-03-04 08:15
    You have to loop it for a while.

    start:
    for b0=1 to 50
    pulsout 7, 85
    pause 20
    next

    pause 1000

    for b0=1 to 50
    pulsout 7, 175
    pause 20
    next

    pause 1000

    goto start
  • ercoerco Posts: 20,255
    edited 2012-03-04 08:17
    Then try this:

    start:
    for b0=85 to 175
    pulsout 7, b0
    pause 20
    next

    pause 1000

    goto start
  • bryansc4bryansc4 Posts: 36
    edited 2012-03-04 10:12
    Hey man thanks a lot for taking the time to help. The motor is still doing the same thing with your code too. Im almost wondering if it's the servo or the way i have it wired. I have the servo wired as such:

    red wire to vdd
    black wire to vss
    white wire to pin 7

    again all the motor is doing is going to the first programmed position and staying there and oscillating slightly.
  • ercoerco Posts: 20,255
    edited 2012-03-04 10:33
    Don't use Vdd, use Vin. Vdd is regulated 5V for the Stamp only. You're likely starving the Stamp for power when the servo twitches, causing the Stamp to keep resetting.

    If you're using a 9V battery, connect the red wire to Vin, which is the same as the +9V terminal.

    Then try those previous programs and also:

    a:
    FOR B0=1 TO 50 'left
    PULSOUT 0,236
    PAUSE 20
    NEXT
    PAUSE 1000

    b:
    FOR B0=1 TO 50
    PULSOUT 0,134' center
    PAUSE 20
    NEXT
    PAUSE 1000

    c:
    FOR B0=1 TO 50 'right
    PULSOUT 0,52
    PAUSE 20
    NEXT
    PAUSE 1000

    GOTO a
  • bryansc4bryansc4 Posts: 36
    edited 2012-03-04 12:07
    Still not doing it for me. What if I connect the red and black wires from the servo to a separate power supply and then put the white wire into the stamp?
  • ercoerco Posts: 20,255
    edited 2012-03-04 14:21
    Good call, 6V is plenty for most servos. Also connect your battery grounds (negative connection) between your Stamp battery and servo power supply.
  • bryansc4bryansc4 Posts: 36
    edited 2012-03-04 16:04
    hey man definitely appreciate the help. I went and got all fresh batteries and tied the grounds together and modified the program you sent me and it all works well. I'm sure I'll have some more questions in the future, but this is a huge jump in my progress to my senior project. I dont have all the parts yet, but im going to wire up some led's to simulate the solenoids that are going to be on the ballast system and some push buttons to simulate the bump sensors. THANKS AGAIN DUDE!
  • ercoerco Posts: 20,255
    edited 2012-03-04 17:18
    You're on your way, bryansc4!
  • bryansc4bryansc4 Posts: 36
    edited 2012-03-07 12:02
    I'm having some difficulty with an If Then. I want to have it setup so when a push button is pressed, it breaks the motor from it's current routine and rudders to the left or right. I'm using two motors, one for ruddering and one for propulsion and in straight forward motion the two work together to create a wave form for propulsion. I have the push button wired from the the pin to ground. I tried:

    If pinx = 1 then turnleft
    If pinx = 0 then gostraight
    turnleft:
    PULSOUT 1, xxxx 'left turn
    PAUSE 4500 'rudders left for 4.5 seconds
    PULSOUT 1, xxxx 'neutral position


    FOR B0=1 TO 10 'left
    PULSOUT 0,210
    PAUSE 20
    NEXT

    FOR B0=1 TO 10 'right
    PULSOUT 0,152
    PAUSE 20
    NEXT


    I can't quite figure out what I'm doing wrong. any advice? Thanks.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-03-07 12:10
    You need a pull-up resistor on your button pin.
    *************************************************
        Push Button Schematic
    *************************************************  
                      5V
                              button
                       10KΩ   ─┻─
       BS1 Pin  ─────┻────────┘ └─┐
                                   
    
    

    I haven't used a BS1, but I'd image it has an ELSE statement. You have it check for the button press and do one thing if it's press and then use ELSE to have it do something if the button isn't pressed.
  • ercoerco Posts: 20,255
    edited 2012-03-07 12:59
    I don't think there is an ELSE statement in PBasic 1.0 for the BS1.
  • TtailspinTtailspin Posts: 1,326
    edited 2012-03-07 15:56
    Oh and Duane,.Get this...the BS doesn't even have Cogs... whats up wit that??.. :)
  • bryansc4bryansc4 Posts: 36
    edited 2012-03-07 16:00
    thanks guys, i def forgot about the resistor, makes a lot of sense haha. so bs1 pin --> resistor --> pushbutton --> GND. We'll see what happens. did the program look like it would work? also erco was correct, no else statement on bs1. I should have ponied up the extra cash and bought the bs2..
  • TtailspinTtailspin Posts: 1,326
    edited 2012-03-07 16:14
    That sounds like a pull down resistor, Duane shows a pull up resistor, so that might could mix up the signals in your code.

    whatever erco says is the way to go, cuz he do crasy stufffs with the stamp...
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-03-07 17:10
    bryansc4 wrote: »
    thanks guys, i def forgot about the resistor, makes a lot of sense haha. so bs1 pin --> resistor --> pushbutton --> GND. We'll see what happens. did the program look like it would work? also erco was correct, no else statement on bs1. I should have ponied up the extra cash and bought the bs2..

    You can switch the 5V and gound (the triangle symbol) to make the pin normally low. The schematic I posted is normally high (goes low when button is pressed). The resistor isn't in line with the button. The BS1 pin get connected to two things, the button and the resistor. Not the button through the resistor. (Not " bs1 pin --> resistor --> pushbutton --> GND", that wont work.)
  • bryansc4bryansc4 Posts: 36
    edited 2012-03-08 08:20
    The pushbutton works! you guys are a huge help, that resistor did the trick, pretty cool that it directs flow from going positive and diverts it to ground when the button is pressed, I never would have thought of that. I'm majoring in mechanical, so this electrical stuff is a huge learning experience. thanks again!
  • bryansc4bryansc4 Posts: 36
    edited 2012-04-10 17:04
    hey guys i finally managed to get all the parts. I'm wiring it all up, but I just wanted have yall take a look at my wiring diagram before i hook it up and start programming. I want to be able to program the fish while the stamp is on board. I followed the input pins from the computer to PCI, PCO, and Vss. I connected Vss to ground and the PCI and PCO pins to 3 pin servo lead along with Vss. Is this a correct configuration? Thanks

    2012-04-10_19-16-20_520.jpg
    1024 x 575 - 42K
  • bryansc4bryansc4 Posts: 36
    edited 2012-04-10 17:06
    oh yeah my bad, S=solenoid valves; m = motors; P= pushbuttons; B = batteries. and again, im using the BS1. thanks again!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-04-11 08:07
    What kind of solenoids are you using?

    I don't know of any solenoids that can be savely driven from a BS1 (not that I'm a solenoid expert). Usually one drives a solenoid with a transistor. You might also need a flyback diode across the solenoid.

    Are the motors "m" servos?

    I wonder (just a little) about having the switch on the ground side of the two batteries. Does anyone here know if there's a danger of having a voltage potential across the two batterys' positive sides? I doubt it's a problem but I think I would have gone for a DPDT switch on the two positive ends of the batteries.
  • bryansc4bryansc4 Posts: 36
    edited 2012-04-11 14:30
    Yes the m are the servo motors. the power sources are tied together on the grounds, but i have to have the +1 go to motors, solenoids, and sensors and +2 power the computer. I have to have the 2 power supplies like this other wise it robs the bs1 of power and causes it to reset. If i have 7.2V going to the stamp and I set the solenoid pins to high will it not supply 7.2V? The solenoid valves are just simple mini mouse valves from clippard. specs are: 2 way, 6V. I have a 16g 850psi CO2 cartridge running into a single stage mini regulator (like the ones you use for inflating bike tires) that steps it down to 20 psi then into the solenoid valves. I gotta do the calculations on my ballast volume to figure out the total time necessary to blow ballast. I plan on doing 10th second bursts every 10-20 seconds till ballast is fully blown to hopefully keep the ports from freezing over. I have the circuit built exactly as in my photo. What my main worry is, is programming it. I have the my laptop going to the VSS PCI and PCO each to the same pins as on the BOE (traced the lines on the back of the board from the computer input to the stamp pins) from the serial port and the VSS connected to ground. I wrote a rough program and I'm sure i'll be asking you guys for help all weekend on it. have a week to finish her up. I'll post videos of testing it in the campus pool soon. Thanks again guys!
  • bryansc4bryansc4 Posts: 36
    edited 2012-04-11 14:32
    and i definitely like your idea about the DPDT switch on the positive sides. what would be the difference though?
  • bryansc4bryansc4 Posts: 36
    edited 2012-04-11 19:01
    poop. just read up on the output power of the stamp. 5V.. need 6V min. You were right, I'm going to need a friggin transistor. Just tried to run the program and didn't get any clicking from the solenoid. hahaha thanks for saving me hours of frustration!

    would yall say something of the configuration shown on page 2 of this document would work? http://www.parallax.com/dl/docs/cols/nv/vol1/col/nv6.pdf

    Thanks.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-04-11 20:09
    I think you'll want a diode across the solenoids like they use on page 6 (printed page 58) with the relay. The inductive load will likely cause a sharp voltage spike when it's turned off.
  • bryansc4bryansc4 Posts: 36
    edited 2012-04-12 11:55
    Well i got the solenoid to actuate to open from the stamp, but now i cant get it to shut off grrr.. Gonna mess with it later tonight.
  • bryansc4bryansc4 Posts: 36
    edited 2012-04-12 18:25
    HAHA! we have victory. I switched from the 2n2222 transistor to another type that was in the pack i bought today, it is a 2n4401, and added the diode like you said and its going click click! Thanks a lot man you're a lifesaver!!
  • bryansc4bryansc4 Posts: 36
    edited 2012-04-12 21:08
    ' {$STAMP BS1}
    ' {$PBASIC 1.0}


    start:
    'fin motors

    IF PIN0 = 1 THEN left
    IF PIN1 = 1 THEN right


    a:
    FOR B0=1 TO 10 'left
    PULSOUT 6,210
    PAUSE 20
    NEXT


    FOR B0=1 TO 10 'right
    PULSOUT 6,152
    PAUSE 20
    NEXT

    GOTO a

    ballast:
    HIGH 3 'opens ballast solenoid valve and starts to sink
    PAUSE 15000 'allows 15 seconds to flood ballast
    LOW 3 'closes ballast
    PAUSE 20000 'allows fish to swim and lowest depth for 20 seconds
    HIGH 4 'opens solenoid valve
    PAUSE 100 'burst of 20 psi CO2 to partially blow ballast
    LOW 4 'closes solenoid valve
    PAUSE 20000 'swims at new depth for 20 seconds
    HIGH 4
    PAUSE 100
    LOW 4
    PAUSE 20000
    HIGH 4
    PAUSE 100
    LOW 4
    PAUSE 20000
    GOTO ballast 'returns to ballast program



    '
    turning >>fixes tail motor for about 5 seconds while the fin motor continues to oscillate

    left:
    PULSOUT 5, 152 'left turn
    PAUSE 5000 'rudders left for 4.5 seconds
    PULSOUT 5, 134 'neutral pos
    IF PIN1 = 1 THEN left
    IF PIN1 = 0 THEN start



    right:

    PULSOUT 5,210 'right turn
    PAUSE 4500 'rudders right for 4.5 seconds
    PULSOUT 5,134 'neutral pos
    IF PIN0 = 1 THEN right
    IF PIN0 = 0 THEN start




    Ok here's my initial attempt at a program. I tested all the parts with simple pulsouts, high's and low's and they all work individually so the wiring is good. I want the fin motor to actuate continuously throughout the whole program, I want the rudder motor to turn left or right depending on the bump sensor that gets hit and hold position for about 5 seconds then return to neutral, and the ballast program to run continuously like the fin motor. I downloaded this program and didn't get any of those things =/ any advice guys?

    Thanks.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-04-12 22:38
    I've never programmed a BS1, but I think I understand the syntax a bit.

    I don't see a way for the program to leave loop "a" once it has been entered.

    Is the "fin" servo on pin 5? You want the fin to move back and forth even when the rudder servo (on pin 6?) has been moved?

    If you want to keep the fin moving while the rudder is moved to one side, you wont want long pauses (I don't think you'll want them at all). Both servos should be receiving a pulse every 20 ms.

    Can you use variables to store data with the BS1? If so, about how many?
  • bryansc4bryansc4 Posts: 36
    edited 2012-04-13 09:09
    yeah i was really tired and just threw a bunch of stuff together in that program last night. I'm gonna go over it again now.

    The fin servo is on pin 6
    the rudder servo is on pin 5

    i believe you can store variables on the bs1. I found, on page 87 of the document, http://www.parallax.com/Portals/0/Downloads/docs/prod/stamps/web-BSM-v2.2.pdf, some material on it, but i have to read it a few times and try to figure out what its saying.
Sign In or Register to comment.