Need help in programming part for my hexa robot

this my robot from lynxmotion :
lynxmotion.com/Category.aspx?CategoryID=33

everything work fine now and i can use ps2 controller to control my robot.
but my project first aim is the robot can move automatic.

i know the place i need to edit is the programming but i have no programming knowledge about basic atom pro.

do anyone have any idea or example code to show me?
let say just simply click square on the ps2 controller and the robot will move forward automatic until i stop it.

i have read the orginal code that generate from powerpod but is too complicated for me to understand.
In the program that generate from powerpod, can anyone let me know which line of code is controlling the robot walking forward?

i have also attach the original code that create by powerpod.

hope someone can help.
thank
snake.bas (26.2 KB)

in powerpod you can select what control you want.
PS2,
Autonomous,
serial port.

program for autonomous is already there.
http://i531.photobucket.com/albums/dd355/innerbreed/power.jpg

oh ok
thank
but just simply asking…
if use auto…how can i control the robot?
let say i want walking straight or walking left or right…

you can use your “ps2” with “autonomous control”. it would be worth building both codes, Ps2 and Auto, then look at how both as structured to gain an understanding of whats needed to combine both. you could say control the robot with your ps2 and then select a button to put it into autonomous mode.

i do believe there was a thread on this somewhere.

what have you replied me is the main things i really hope to do it!
i hope to make it very simple only
let say with a one press of square button then the robot will move forward, and one more press the robot will stop there.
i am trying to find this kind of tread but i cant find it
can u please help?

Hi Deathsnake,

You have not mentioned if you have tried making a few changes to the code and see what happens? I don’t have time to do much here.

But for example have you found in your ps2 code where the square button is currently processed? It looks like:

if (DualShock(2).bit7 = 0) and LastButton(1).bit7 then ;Square Button test ... endif
One easy thing to do here is to toggle on and off a mode. Define a variable: maybe something like: AutoMode var byte;
The code in the test above could be as simple as: Automode = AutoMode ^1
Or if you don’t like using the operator something like:
if AutoMode
Automode = 0
else
Automode = 1

Then if you look farther down in the code you will see a label: NoSound1

Here you notice it is taking the PS2 inputs to set some variables in the code [code] YSpeed = DualShock(3) - 128 ; Right Stick Horizontal

XSpeed = DualShock(4) - 128		; Right Stick Vertical

Steering = DualShock(5) - 128		; Left Stick Horizontal

StepFlag = (GaitSpeedTmp - 2) max 3
if HeightAdjust or LockLegs then
	Height = LastHeight + (((DualShock(6) - 128) / 5) - LastHeight) / StepFlag; Left Stick Vertical
endif

Height = (Height Max HeightLimit) min - HeightLimit

[/code]
Well try putting this code user the condition that:
if AutoMode then
XSpeed = ???
YSpeed = ???
Steering = ???
Height = ???
else

endif

That hopefully should get you started. That is all for now
Kurt

ok…
now i use back the ps2 controller program that generated by powerpod.
i have delete all those controlling command but i still left all the variable or pin assign.
So now when i start my program, my robot is only “All = 1500” position and if i click any button on PS2 and it won’t be have any respond.

So first of all, i put in the sqaure button command which i already understand:

if (DualShock(2).bit7 = 0) and LastButton(1).bit7 then ;Square Button test gosub All1500 ;Learning to fly posture (uh ? nutty ?...it CAN fly...) for Index = 1 to 4 serout SSC32,i38400,"#",MRHV,MRHV2,"P1900#",MRK,MRK2,"P1800#",MLHV,MLHV2,"P1100#", | MLK,MLK2,"P1200T288",13] serout SSC32,i38400,"#",RRHV,RRHV2,"P1600#",RRK,RRK2,"P1600#",FRHV,FRHV2,"P1600#", | FRK,FRK2,"P1600#",RLHV,RLHV2,"P1400#",RLK,RLK2,"P1400#",FLHV,FLHV2,"P1400#", | FLK,FLK2,"P1400T576",13] pause 288 serout SSC32,i38400,"#",MRK,MRK2,"P1200#",MLK,MLK2,"P1800T288",13] pause 288 serout SSC32,i38400,"#",RRHV,RRHV2,"P1400#",RRK,RRK2,"P1400#",MRHV,MRHV2,"P1500#", | FRHV,FRHV2,"P1400#",FRK,FRK2,"P1400#",RLHV,RLHV2,"P1600#",RLK,RLK2,"P1600#", | MLHV,MLHV2,"P1500#",FLHV,FLHV2,"P1600#",FLK,FLK2,"P1600T576",13] pause 576 next serout SSC32,i38400,"#",MRHV,MRHV2,"P1800#",MRK,MRK2,"P1800#",MLHV,MLHV2,"P1200#", | MLK,MLK2,"P1200T288",13] pause 288 gosub All1500 endif

then i download it into atom, and yes when i click square button i does something that original does and that is learning to fly.

Then after that i delete the sqaure button code, and i try to put in the walking forward code.
I not really understand how the walking forward program look like, so i try this code in my main program.

[code] YSpeed = (DualShock(3) - 128)*3/5 ; Right Stick Horizontal

XSpeed = (DualShock(4) - 128)*4/5	; Right Stick Vertical

Steering = DualShock(5) - 128		; Left Stick Horizontal

StepFlag = (GaitSpeedTmp - 2) max 3
if HeightAdjust or LockLegs then
	Height = LastHeight + (((DualShock(6) - 128) / 5) - LastHeight) / StepFlag; Left Stick Vertical
endif

Height = (Height Max HeightLimit) min - HeightLimit[/code] 

But after that i download into my atom, moving my left or right stick, it does’nt show any respond on my robot.
What i think was my program on top has problem.
I have also attach my program code, just if someone free please help me check my code whether i have made some mistake in my programming code.

For now, i just hope to understand how the walking forward programming works in PS2 control.
self program.bas (13.1 KB)

anyone can help please?
i just hope to know the program of PS2 control, where is the forward walking programming code~

I took a quick look at your stuff and you more or less removed all of the code that does the walking…
You are simply getting input from the PS2, setting a few variables that are used for nothing and then go back to read the PS2 again.

The walking code is more or less everything from the commented out label H3 through the Serouts, all the way down to where it does a goto main. Yes the code is complicated. So you have a few options here.

  1. Use it as is as a black box and experiment, which is what I suggested in the previous post. That is as a suggestion, use something like the
    square button to toggle a mode on and off.

When the mode is on, experiment. Something like:

if AutoMode then
    ; here is where we experiment - what happens if you change XSpeed + or -
   YSpeed = 0
   XSpeed = 50    ; maybe  this will walk forward???
   Steering = 0    ; 

   StepFlag =  3  ; not sure try changing...
   Height = 0  
else
  ; This is the current code that sets the walking parameters...
   YSpeed = DualShock(3) - 128      ; Right Stick Horizontal

   XSpeed = DualShock(4) - 128      ; Right Stick Vertical

   Steering = DualShock(5) - 128      ; Left Stick Horizontal

   StepFlag = (GaitSpeedTmp - 2) max 3
   if HeightAdjust or LockLegs then
      Height = LastHeight + (((DualShock(6) - 128) / 5) - LastHeight) / StepFlag; Left Stick Vertical
   endif

   Height = (Height Max HeightLimit) min - HeightLimit
endif

... Fall through to the code that does the actual walking...
  1. Try something else. That is instead of using this code try using something the the SEQ program to generate the walking sequence you wish to use and then use that to make your hex walk.

Good Luck
Kurt

Have you tried any of the suggestions or code that I have mentioned in a couple of different posts or PMs? Have you looked at the code I mentioned ast night? Are you expecting that someone will do all of the work to integrate it into the actual code and then test it out?

Again back to the issue at hand. From a PM I sent you…

Have you followed up on this? If you had, you would see that the code is pretty much the same, except the stuff at the start of the main loop. Also you ask what variables impact the walking. If you look at the comments in the Autonomous version you would see:

[code]main

if Initialized = 0 then shunt

;--------------------------------------------------------------------
; ***************
; Buttons :
; ***************
; Bit 0 - Horn
; Bit 1 - ** Unused **
; Bit 2 - ** Unused **
; Bit 3 - ** Unused **
; Bit 4 - On/Off (you can test FlagOff(=1) to check if the servos are Off)
; Bit 5 - All = 1500
; Bit 6 - Attack
; Bit 7 - Learning to fly
; (for example, ‘Buttons.bit6 = 1’ will call the Attack mode posture)
; ‘Attack’ and ‘Learning to Fly’ must be called while the robot is not moving
; so, you’ll have to test the variable MovesDelay (=0) to make sure the H3R is not moving,
; else, it will not call the sub routine
;
; ***************
; Buttons2 :
; ***************
; Bit 0 - Open
; Bit 1 - Rotate Right
; Bit 2 - Close
; Bit 3 - Rotate Left
; Bit 4 - ** Unused **
; Bit 5 - ** Unused **
; Bit 6 - ** Unused **
; Bit 7 - ** Unused **
;
; ***************
; Steering (Rotation):
; ***************
; Range 120 (Right) to -120 (Left)
;
; ***************
; XSpeed (translation):
; ***************
; Range -120 (Forward) to 120 (Backward) (translation)
;
; ***************
; YSpeed (translation):
; ***************
; Range 120 (Right) to -120 (Left)
;
; ***************
; Height :
; ***************
; Range 25 (Body Down) to -25 (Body Up)
;
; ***************
; LegUpShift :
; ***************
; Range 20 (Close to Floor) to 70 (About 2.5 inches from floor)
; if LegUpShift > 45 the tripod Gait is modified to allow extra vertical move and the GaitSpeed is limited to 8-4 range
; if LegUpShift is close to 70 it’s recommended to use a 8-5 range for GaitSpeed
; (a too fast gait loop won’t allow extra vertical move)
; If LegUpShift > 45, you’ll have to move the Body Higher
; (Setting Height to -15 or -20 for example) to allow extra vertical move
;
; ***************
; GaitSpeed :
; ***************
; range 20 (Slow gait loop) to 3 (Fast gait loop)
; Note, gaitSpeed is limited to 20-4 range if LegUpShift > 45
;
; ***************
; KneeShiftOn
; ***************
; KneeShiftOn = 0 => normal gait
; KneeShiftOn = 1 => add a shift angle when tripod is Up
;
; ***************
; LockLegs
; ***************
; LockLegs = 0 => normal walk
; LockLegs = 1 => body moves
;
; ***************
; LeftStickMode
; ***************
; if locklegs = 1 => body moves mode :
; - LeftStickMode = 0 => Variable Steering and Height
; are used for vertical axis rotation (Yaw) and translation (Height)
; ---------------------------------------------
; - LeftStickMode = 1 => Variable Steering and Height
; are used for roll (right or left) and vertical axis translation (Height)
; ---------------------------------------------
; - LeftStickMode = 2 => Variable Steering and Height
; are used for vertical axis rotation (Yaw) and pitch (forward or backward)
; ---------------------------------------------
; - LeftStickMode = 3 => Variable Steering and Height
; are used for roll (right or left) and pitch (forward or backward)

;--------------------------------------------------------------------
; mine
Buttons = 0 ; Start off with no buttons pressed.

Prev_ButA = ButA		; remember previous state
ButA = in12				; get the new state of the Btn A on BB2

Prev_ButB = ButB		; remember previous state
ButB = in13				; get the new state of the Btn B on BB2

if ButA and (Prev_ButA = 0) then
	; Toggle the ON/Off switch
	Buttons.bit4 = 1	; Say that we pressed the on/off switch
endif

if ButB and (Prev_ButB = 0) then
	; Toggle the ON/Off switch
	Buttons.bit7 = 1	; Try Learn to fly...
endif

; need to figure out what we want to do but to start off with
; walking forward at some speed and height...		

Steering = 0	; not rotate
XSpeed = 0; 40		; go forward at some speed - 0 to not move...
YSpeed  = 0		; not diagnal...(translation):
Height  = 0
LegUpShift = 40	; higher up but not that it needs extra stuff
GaitSpeed = 10	; somewhere in the middle of speed
KneeShiftOn = 0 ; normal gait
LockLegs = 0	; Normal walk
LeftStickMode = 0 ; probably don't need to set

Shunt

[/code]

This is a version I modified earlier for a couple of different people. Notice that the start of this explains what the variables do and their ranges. The stuff at the end where the comment mine is, was the stuff I tried earlier. Pressing one button on the BB2 simulated pressing the start button, and pressing a different button simulated doing the learn to fly. It also walks forward!

I agree with Robot Dude that one way to do this is to offload the work to a different processor. But yes you can do it with the Bap28 as well. In the end the difference in the three versions is how the variables mentioned above get set.

Kurt

i would have thought that just be changing the button that is assigned to XSpeed would do it.
eg: XSpeed = (DualShock(2) - 128) ; square button test

maybe not?

i will try and run some test for you tonight to see what we can do. :wink:

Well I integrated the stuff I mentioned above into a powerpod PS2 program. However instead of using the square button, I used R3 (push the right joystick in). It still does the horn (We will rock you), but then it will start walking foreword until you press the button again. I had to configure the program for my hardware (PS2 on pins P0-3 using internal pull-up resistor) and P11 to talk to the SSC-32 (did have to change my ssc-32 back to slow speed (38400) but worked like a champ. Would not be hard to add in additional stuff like looking at sensor and change directons/speed, etc…

Kurt
powerpod ps2 for atom pro.bas (30.5 KB)

Thank Kurte
I will try your code on monday!
so i have to change my ps2 pins on p0-3 right?
and p11 that connect to ssc-32

Nope, you can leave yours on P12-P15. Mine are on P0-3 as I have my XBee on the hardware serial port P14-P15. Also the SSC-32 you can leave in your normal spot. All of the pin number changes were done under an #ifdef, which I do not have defined in the verison I uploaded.

Kurt

thank kurte~
so i will just copy and paste your code inside my atom pro 28 and without changing anything right?
you really help me a lot~
really thank very much~

just to help you deathsnake, here is some info on expanding the code for more range and direction if/when you come to it.

The XSpeed variable has a range of 120 (forward) to -120 (backwards).

The YSpeed variable has a range of 120 (right) to -120 (left). Rotation is named Steering. It’s not really steering because if you try to turn while both XSpeed and YSpeed are 0, the robot will rotate in place.

The range is 20 (right) to -20 (left) for steering and the speed of rotation is proportional to the value.

The body height is set by the Height variable and also has a range of -25 to 25.*
:wink:

just some question innerbreed~
actually i not really understand about xspeed~
just let say i put xspeed = 120 and xspeed = 50
both also walking front but different speed right?
120 has a faster speed then 50 right?

XSpeed and YSpeed represent the coordinates of the Stick movement in the PS2 controller.

http://www.knupps.net/xyz-coordinates.png
this image shows the direction of travel.

120 is the fastest, as it would be the furthest the j/stick will travel in a given direction.

Hi again Deathsnake,

At this point I think you should have plenty of information to start experimenting. There have been several posts from myself and others showing which variables, control walking and their ranges. If you look at the PS2 code, especially the part that I put in an if when you are not in Automode, which includes:

YSpeed = DualShock(3) - 128 ; Right Stick Horizontal XSpeed = DualShock(4) - 128 ; Right Stick Vertical Steering = DualShock(5) - 128 ; Left Stick Horizontal ... Height = LastHeight + (((DualShock(6) - 128) / 5) - LastHeight) / StepFlag; Left Stick Vertical
You see that XSpeed, YSpeed, Steering and Height variables are all set depending on the position of the two sticks on the PS2. The DualShock array is an array of bytes which imply that it has a range from 0 to 255. When the stick is in the center the values are typically around 127 or 128 depending on the stick. There is some code in place to handle the slop. In this program that code looks like:

for Index = 3 to 6 if DualShock(Index) > (128 + DeadZone) then DualShock(Index) = DualShock(Index) - DeadZone/2 elseif DualShock(Index) < (128 - DeadZone) DualShock(Index) = DualShock(Index) + DeadZone/2 else DualShock(Index) = 128 endif next
When you move a joystick to one edge the value will be near 0, when you move it to the other edge it will be near 255. So when you read the code and see something like:
XSpeed = DualShock(4) - 128 ; Right Stick Vertical
Then you know that when the stick is in the center XSpeed 128-128 = 0
When it is at one edge it will be: 0-128 = -128 and when it is at the other edge it will be: 255-128= 127.

So given the code above that shows how the different variables are set by the joystick values and your ability to run the robot with the PS2, you should now be able to reasonably deduce what your robot should do when you set these values. And I have already provided you a version of the program that you can easily try it out, to confirm this.

So it is now up to you. Remember programming is not a spectator sport! :smiley:

Kurt

thank kurte~
i will slowly test it out
the program that you provided i have tried on my robot and it works!
but your robot legs pin is different as mine and you are using leg-C and mine is leg-B.
but i will change it back base on my original code.

i have try on my ping))) using this code:

wdist var word

main:
low p4
pulsout p4, 5
input p4
pulsin p4, 0, toolong, 40000, wdist
wdist = wdist / 148   ;convert for inches
serout s_out, i9600, "Distance: ", sdec wdist, 13, 10]      ;display result in terminal
goto main

toolong:      ; if the program gets here the sensor is not functioning, or wired wrong
serout s_out, i9600, "Timeout, sensor is not working", 13]
goto main

success also and if no object in front of ping))) then terminal 1 is showing distance 125

So my next plan is make my robot automatic move forward, meet object (let say distance <=50), then move to left or right, then continue forward and then i will stop the robot.
I will try to read your automatic forward code and try to make my own code.
And also i hope you can help me out~
thank.