Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

What is wrong with this code

  1. Oct 14, 2005 #1

    wolram

    User Avatar
    Gold Member

    Please can any one see an error.

    '##############################################################################
    'Start Position: The Sted-E-Man needs a strat sequence to set the legs in the
    'correct position. Unless the servo positions are known, the feet could clash
    'on first start-up or reset and cause damage to the walker.
    '##############################################################################

    Dim Left_Hip As New oServo 'Left hip servo set
    Dim Right_Hip As New oServo 'Right hip servo set
    Dim Right_Foot As New oServo 'Right foot servo set
    Dim Left_Foot As New oServo 'Left foot servo set
    '******************************************************************************

    Sub Main()
    '###############################################################
    'This is the first routine that is entered on start up or reset.
    '###############################################################
    Left_Hip.IOLine = 14 'Left Hip servo IOLine
    Left_Hip.Center = 27 'Center position
    Left_Hip.Operate = CVTrue 'Servo object turns on

    Right_Hip.IOLine = 12 'Right Hip servo IOLine
    Right_Hip.Center = 27 'Center position
    Right_Hip.Operate = CVTrue 'Servo object turns on

    Right_Foot.IOLine = 10 'Right foot servo IOLine
    Right_Foot.Center = 30 'Center position
    Right_Foot.Operate = CVTrue 'Servo object turns on

    Left_Foot.IOLine = 8 'Left foot servo IOLine
    Left_Foot.Center = 28 'Center position
    'Left_Foot.Operate = CVTrue 'Servo oject turns on


    Call Start_Pos 'Call the start position for all servos
    oopic.delay = 300 '3 second delay for Sted-E-Man positioning
    End Sub
    '******************************************************************************

    Sub Start_Pos()
    '################################################################
    'A routine to set the start position is needed otherwise the
    'Sted-E-Man's feet could clash damaging the robot.
    '################################################################
    Right_Foot.Value = 0 'Move Right Foot outwards full
    oopic.delay = 200 '2 second delay
    Left_Foot.Operate = CVTrue 'Servo oject turns on
    Left_Foot.value = 56 'Move Left Foot outwards full
    oopic.delay = 200 '2 second delay
    Left_Hip.Value = 27 'Move the Hip servos to start
    oopic.delay = 200 '2 second delay
    Right_hip.Value = 10 'position
    oopic.delay = 200 '2 second delay

    'Right_Foot.Value = 30 'Move Right foot to start position
    'Left_Foot.Value = 28 'Move left foot to start position

    End Sub
    '**************************************************************
     
  2. jcsd
  3. Oct 14, 2005 #2

    DaveC426913

    User Avatar
    Gold Member

    I see an error, but not in the code.:uhh:
    Perhaps you could tell us where it's going awry. Any error messages you'd care to share?
     
  4. Oct 14, 2005 #3
    I see an error... but I will bite my toung, it has nothing to do with the code.
     
  5. Oct 14, 2005 #4

    DaveC426913

    User Avatar
    Gold Member

    Just shooting in the dark until I get more info:

    In your Start_Pos, you set Left_Foot.Operate , but I don't see any .Operate sets for any other servos.
     
  6. Oct 14, 2005 #5

    wolram

    User Avatar
    Gold Member

    This code is supposed to activate 4 servoes to a start possition, but they just
    go crazy, there are no error messages.
    the servoes work ok independantly, this from another set up code used to find
    center values that are then transfered into this one.
     
  7. Oct 14, 2005 #6

    DaveC426913

    User Avatar
    Gold Member

    OK, strip it down to the bare bones.
    Get one servo making one move.
    Get another servo making a move.
    Throw away everything else until you have a maximum of two movements coordinated.

    Question: the time units you are using: you sure they are 100ths of a second? If they are 1000ths of a second, then each of your delays are only fractions of a second.
     
  8. Oct 14, 2005 #7

    wolram

    User Avatar
    Gold Member

    Thanks for the help Dave, i can get 2 servoes to work, left foot,left hip as they
    should, and the same for right foot, hip, it is only when i try to get all 4 to work
    together, the delays are seconds.
    this is the latest code i tried.

    Sub Start_Pos()
    '################################################################
    'A routine to set the start position is needed otherwise the
    'Sted-E-Man's feet could clash damaging the robot.
    '################################################################
    Right_Foot.Value = 0 'Move Right Foot outwards full
    Left_Foot.value = 56 'Move Left Foot outwards full
    oopic.delay = 50 'small 0.5 second delay
    Left_Hip.Value = 27 'Move the Hip servos to start
    Right_hip.Value = 10 'position
    oopic.delay = 100 '1 second delay

    'Right_Foot.Value = 30 'Move Right foot to start position
    'Left_Foot.Value = 28 'Move left foot to start position

    End Sub
     
  9. Oct 14, 2005 #8

    DaveC426913

    User Avatar
    Gold Member

    Set your delays to, like, 5 seconds. Give your eyes & brain time to watch the action and see what it's doing. (eg. Is it really going randomly haywire? Or is it just one move that's out of place? What is the first move that is not as it should be?)
     
  10. Oct 14, 2005 #9

    wolram

    User Avatar
    Gold Member

    It seems random, the servoes do not complete a full movement and the right
    hip moves at the same time as the left, it is difficult to to fault find, as any
    clashes can damage the gears in the servoes, so i have switch it off quick.
    I have changed the output IO lines, thinking it could be a hardwear problem
    but it is the same, i have cleared the EPROM and stated from scratch with
    no joy.
     
  11. Oct 15, 2005 #10
    You dont show the code for "servos" or "man positioning"

    but in the last sub start_position you set Right_foot.value 2 times? you cannot set the variable more than ONE time!

    Code runs a million billlion zillion lines per second, but a motor is very slow by comparison. One has 'value' with uppercase another with lowercase. in basic it should be okay? but its a dangerous habit.

    Start by setting the items only one time. You may want to initialize each component one by one, checking limit switches slowly and if they dont work, throw an error which turns every motor off.

    An init routine will take time to make/debug but start there
     
  12. Oct 15, 2005 #11

    wolram

    User Avatar
    Gold Member

    Thankyou brad, i will work through it moer carefully.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?