Xan's Ps2 controller code did I find a bug?

Hi, I’m not sure if I found a bug or its just something stupid but Im using this
lynxmotion.com/images/files/phoen1.3.bas

When I change gait type pressing the square button it really appears that the there are only 2 gait’s and when I look into the code I see that there are 7 programmed…

Are all these gaits so similar you cant distinguish them apart from each other?

On a side note, I feel that I needed to slightly modify the code a tad to help me understand if there is some sort of issue with the gait selection code “the code looks well written” so I don’t want to step on anyone’s toes here when I say this.

So basically I added this

;[gait]
GaitType		var byte	;Gait type
SoundLoop		var	byte
NomGaitSpeed	var byte	;Nominal speed of the gait

then down where the gait variable adding is going on I added this

	  ;Switch to next Gait type
  		IF GaitType<7 THEN
		   GaitType = GaitType+1
		   		For SoundLoop = 1 to 7
		   		Sound P9,[50\4000]
		   		Pause 200
		   		SoundLoop = SoundLoop+1
		   		Next
  	  	ELSE
		  Sound P9,[50\4000, 50\4500]
		  GaitType = 0
 	  	ENDIF

the idea I find is a better solution to determining where you are audibly in the gait selection "1-7’

So it’s suppose to beep the number of times based on the gait selection gait 4… beep 4 times… ext…

come to think of it I suppose I could probably use gaittype variable rather then create my own variable… besides the point it just seems like there are 2 different gaits only???

What gives?

–Aaron

Actually I think there may be a problem with your code. I think maybe you wanted your for Soundloop not to always go from 1 to 7, but maybe more like: For Soundloop = 1 to GaitType

Just a thought.

Kurt

Might want to take the SoundLoop = SoundLoop+1 out of the for next loop as well. :wink: And remove the extra sound command immediately following the for next loop.

Thanks for the PM,

And yeah I was thinking that exact same thing when I was writing my original question, although that code doesn’t seem to work at all either.

Either way when I get my 3 pin servo wires in the mail i’ll try and make something with this,

the goal was to take xan’s ps2 code and adapt it for rc control, I was going to take quite a bit of features I really didn’t need out of it and i don’t know “fiddle with it”… anyway…

Although it’s still up in the air about how it seems there are only 2 of the 7 gait types accessible.

Well after a bit of dumbassness sure its a word.

Realized that select changed gait types, although it still seems like it does nothing? Im under the impression looking at the code there should be a beep when gait type is pressed and when I press select nothing happens.

I’m not sure if thats because the BB2 thinks its getting movement from the analog sticks, if so I recall asking on another post about how the robot appears to move on its own due to sony’s controller not centering properly, Is it possible for the ps2 sticks to not center properly while causing the robot to appear stopped, but still not able to change gait type with the select button?

–Aaron

Hi Aaron,

There are indeed 7 gaits in V1.3. Every time a gait is switched you’ll hear a single beep. If it returns to the first gait you’ll hear 2 beeps. For information:
6 steps ripple gait
12 steps ripple gait
9 steps quadripple
4 steps tripod
6 steps tripod
8 steps tripod
12 steps wave
18 steps wave
The ripple, tripod and wave are included with a different amount of steps. If the steps increase the gait is slower but more smooth. But I’m sure you can distinguish the 3 major gait types in there. :wink:

Jim already mentioned you should take SoundLoop = SoundLoop+1 out. But I think that you should also take the pause out as well. This takes a lot of processor time (worst case 7*200 = 1.4sec).

The hex will start walking if the ps2 sticks are not in the middle position. Is it walking in with the stick in the middle position?

Note: The hex needs to stand still when you switch gaits. It can’t switch gaits while walking.

Xan

Xan Hi,

Yeah the thing does not beep when I press select so not sure whats going on there.

The thing moves when the sticks are centered, which has been covered a while back from a couple people telling me the ps2 controller isn’t returning the correct center values all the time, this I can work around.

I think there is a problem possibly with the select button in general I don’t think it does anything for me.

–Aaron

Hi Aaron,

Here’s a snapshot from V1.3 showing the conditions for changing gaits.

[code] IF HexOn THEN
IF (DualShock(1).bit0 = 0) and LastButton(0).bit0 THEN ;Select Button test
IF TravelLengthX=0 & TravelLengthZ=0 & TravelRotationY=0 THEN

  ;Switch to next Gait type
	IF GaitType<7 THEN
	  Sound P9,[50\4000]
	  GaitType = GaitType+1
  	ELSE
	  Sound P9,[50\4000, 50\4500]
	  GaitType = 0
  	ENDIF

  	GOSUB GaitSelect
  ENDIF
ENDIF[/code]

In other words:

  1. The hex needs to be on (this can be done with the start button)
  2. The select Button is pressed
  3. The sticks need to be in the middle position

I don’t know how you build your workaround with the middle positions. But the sticks need to be in the middle position to change gaits.

Some steps you can do for debugging:
Check the working of your select button:
You can make something like this to let the BB2 beep if you push the select button

IF (DualShock(1).bit0 = 0) and LastButton(0).bit0 THEN ;Select Button test Sound P9,[50\4000] ENDIF

Check if the sticks are in the middle position by writing the travellength values to the pc using the serial connection. These values need to be 0 if you want to switch gaits.

serout s_out, i38400, "TravelLengthX=", sdec TravelLengthX, " TravelLengthZ=" , sdec TravelLengthZ, " TravelRotationY=", sdec TravelRotationY, 13]

I hope this gets you any further.

Xan

My guess is it is the middle test as he mentioned he has a wired PS2 cable and it wants to walk when it is in the center position.

He needs to add in a dead zone

Kurt

Hi Xan, Kurt,

Ok, so I don’t want to modify the code, I simply want to determine why it doesn’t seem to be working for me ya know.

I can get the robot to stop walking, although I’m curious if the robot is stopped if the values must be zero or if they can be such a small number like 1 or 2 where the robot still doesn’t move but it causes the change gait function to not work because the value is not zero on both sticks.

I’ll modify your 1.3 code so that it beeps after I press select and see if that beeps or does nothing…

Is it entirely possible that a sony ps2 controller select button sends out different data then all the other controllers you’ve tried?

Actually The dead zone code really isn’t necessary now for me, here Xan I think you might like how I found a workaround for your code “no disrespect” let me know what you think.

[code]IF HexOn THEN
IF (DualShock(1).bit0 = 0) and LastButton(0).bit0 THEN ;Select Button test
Sound P9,[50\4000] ;<—Added this
;IF TravelLengthX=0 & TravelLengthZ=0 & TravelRotationY=0 THEN ; <— Commented this out

  ;Switch to next Gait type
	IF GaitType<7 THEN
	  Sound P9,[50\4000]
	  GaitType = GaitType+1
  	ELSE
	  Sound P9,[50\4000, 50\4500]
	  GaitType = 0
  	ENDIF

  	GOSUB GaitSelect
  ;ENDIF ; <----- Commented this out also
ENDIF[/code]

I can now change gait types while walking “might look weird when that happens… and it does kinda”

either way I put a beep after the select statement so you have audible knowledge of when the gait’s change “HELPS A TON”

I see the gait types now, and previously that was my problem I think that this line here

commenting out the If Travel length statment and its endif statement actually correct the code so I believe the robot was stopped but one of the 3 values was actually above zero which was causing the robot to never switch gait types…

Cough cough cough “hey xan make a 1.4” of your code :stuck_out_tongue:
anyway here is what I changed.

IF TravelLengthX=0 & TravelLengthZ=0 & TravelRotationY=0 THEN

should be something like this

IF TravelLengthX<=10 & TravelLengthZ<=10 & TravelRotationY<=10 THEN

I’m not sure about the value 10, I’m not quite sure how you determine what max and min values that controller puts out to find an acceptable number for a “what appears to be stoped movement” on the phoenix.

… Well what do you guys think?

Not bad for not writing this code and possibly helping in its future usage :stuck_out_tongue: sorry “I had to be full of myself for a couple seconds”

–Aaron

You can use the constandthat is already in there for that purpose. It’s used with the gait itself.

TravelDeadZone

Dahaha crap you stole my mojo…

did you adapt this code to work with an RC remote? or was that zenta?

Cause that’s what I want to do eventually down the road,

Holy crap these different gait types are pretty slick, I know while holding R2 it looks like the less advanced gait’s make the spider move really really fast! so fast i move the thing twords me and it creeps me out a bit :stuck_out_tongue:

Seeing these less advanced gait types would be really interesting to see them work on uneven terrain I see in your other post your made the feet…

Very cool,

I’ll have to get with kurt here in the next week or so and see about trying to use his PWM assembly code and paste it into this ps2 remote and try and adapt it all once I recieve my 50 servo extension wires in the mail.

–Aaron
Humm looking at your code it looks like its super accurate, is this necessary? wouldn’t simply doing the calculations to the 1000th place be more then sufficient? even to the 100th place seems like ti would do… and if this was done you think it would speed up processing?

I guess the only thing i see is delays when you can press buttons and when you hear the beep’s on the bb2…

what are your thoughts?

any other ideas you might have for your 1.3 code xan?