Need help in programming part for my hexa robot

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.

aa

PROBLEM SOLVED!
now i can made my robot walk forward when no object is in front and it will stop right there if a object is in front!

but anyway
please help me solve this

look at my code XSpeed = -50
it only will walk forward when Xsped = -50
if set to Xspeed = 50 it will walk backward.
just hope to ask, why this will happen?
Because I though when xspeed is positive and it should be walking front?

===================1st part====================
	;code for ping)))
	low p4
	pulsout p4, 5
	input p4
	pulsin p4, 0, toolong, 40000, wdist
	wdist = wdist / 148   ;convert for inches
	if wdist > 50 then		;when distance >50 move forward, <50 turn right
	aaa = 0			;turning right automatic is off
	Automode = 1    ;moving forward automatic is on
	else
	
	Automode = 0	;moving forward automatic is off
	aaa = 1			;turning right automatic is on
 
	endif
	toolong:      ; if the program gets here the sensor is not functioning, or wired wrong

============2nd part======================================
	;moving forward automatic code
	if Automode then
	   
   		YSpeed = 0
   		XSpeed = -50   ; moving forward
   		Steering = 0    ; 
		
   		StepFlag =  3  ; not sure try changing...
   		Height = 0  

	else
		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
	

=====================3rd part===============================
	;code turning right
		if aaa then
	   
   		YSpeed = 50	;turning right
   		XSpeed = 0   
   		Steering = 0    ; 
		
   		StepFlag =  3  ; not sure try changing...
   		Height = 0  


		endif

about the code on top
there are 3 part, first part is ping))) code, second part is forward code and 3rd part is move to right code.
At first is code for ping))), when distance >50, automode = 1 and aaa = 0, robot will move forward. When there is an object and distance <50,automoce = 0 and aaa=1, robot will move right.
My question is…
for my program, robot move forward, then meet object, then it will keep walking to right until i stop the robot.
Anyone have any idea to make this?
robot move forward, meet object, then move to right but still keep detect the object until distance >50(no more object in front), then robot move forward again. I try to figure this for whole day but i just can’t get the idea

Hi again, don’t have the time to fully code this (besides that is where the fun is!) :wink:

But it should not be very hard to layout the code that says go foreword as long as there is nothing in front of me else go right…

Something like:

if Automode then
   low p4
   pulsout p4, 5
   input p4
   pulsin p4, 0, toolong, 40000, wdist
   wdist = wdist / 148   ;convert for inches
   if wdist > 50 then      ;when distance >50 move forward, <50 turn right
        YSpeed = 0
         XSpeed = -50   ; moving forward
  else
          YSpeed = 50   ;turning right
         XSpeed = 0   
  endif
  Steering = 0    ; 
  StepFlag =  3  ; not sure try changing...
  Height = 0  
   ...
else
; the non-auto mode...

Hopefully that should get you moving.
Kurt

thank kurte for your help.

1 question
my robot still not walking straight.
It will slightly move to right site a bit.
offset and alignment (from powerpod) of my robot is quite ok already.
but still not walking straight.

So should i adjust the angle of the servo?
But i have no idea about the programming code of the servo in my programming part.
Can help?
THank~

EXPERIMENT!!!

Try things like what happens if I instead of: XSpeed=-50 and YSpeed=0
Try something like XSpeed=-50 and YSpeed = 1 or -1…

Kurt

oh thank kurte~
i didnt think of it…
i will try it out tomorrow
Thank!

[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[/code]

The code on top will show me sensor distance in terminal 1 after i click connect.
I need all of the result from initial i start to click connect and until i stop the program.
How can i transfer my output data to Excel or notepad?
Because the initial result in terminal 1 will gone if my sensor data run too long, right?

anyone can help about this please?