PDA

View Full Version : What is wrong with this code


wolram
Oct14-05, 09:16 AM
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
'************************************************* *************

DaveC426913
Oct14-05, 09:22 AM
Please can any one see an error.
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?

ComputerGeek
Oct14-05, 09:30 AM
I see an error... but I will bite my toung, it has nothing to do with the code.

DaveC426913
Oct14-05, 09:30 AM
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.

wolram
Oct14-05, 09:30 AM
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?

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.

DaveC426913
Oct14-05, 10:00 AM
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.

wolram
Oct14-05, 10:12 AM
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.
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

DaveC426913
Oct14-05, 10:32 AM
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?)

wolram
Oct14-05, 11:19 AM
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?)

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.

Brad_1234
Oct15-05, 03:10 AM
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
'************************************************* *************

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

wolram
Oct15-05, 04:25 AM
Thankyou brad, i will work through it moer carefully.