Putting robotics at your service™

Free shipping on orders over $200

PS2 analog sticks - Normalization of readings

Print view Share :
Previous topicNext topic

Page 1 of 3 [ 33 posts ]

1, 2, 3
User avatar
Guru ( offline )
Posts: 2956
Posted: 2010-06-08 21:26 
Are the PS2 sticks known to be erratic? I'm trying to control a pan/tilt with the left analog stick, but am not seeing any real change in readings and no change in positioning. I'm using code taken from the ps24wd1.bas program.

8-Dale


Attachment:
walter.bas [9.8 KiB]
Downloaded 83 times

_________________
I can usually handle complexity. It's the [b][i]simple[/i][/b] things that always confound me..
Check out my [url=http://www.hybotics.me]blog[/url] now!
Open your mind, Read, Learn, Think, Apply..


Last edited by linuxguy on 2010-06-10 09:00, edited 3 times in total.
User avatar
Guru ( offline )
Posts: 4904
Posted: 2010-06-08 23:03 
The Lynxmotion ones are usually pretty good. You still usually want some slop in the code, like + or - 2 or 3 from center (127 or 128). The old Sony wired ones that I have tried are another story! They don't tend to get back to the same zero points...

Kurt


User avatar
Guru ( offline )
Posts: 2956
Posted: 2010-06-08 23:08 
kurte wrote:
The Lynxmotion ones are usually pretty good. You still usually want some slop in the code, like + or - 2 or 3 from center (127 or 128). The old Sony wired ones that I have tried are another story! They don't tend to get back to the same zero points...

The code I am using is from the existing ps24wd1.bas program. As far as I can tell so far, I've ported over all the right bits of code. I'm not getting anything close to the movement I expected to get. I don't know if I have messed up some timing or not though.

8-Dale

_________________
I can usually handle complexity. It's the [b][i]simple[/i][/b] things that always confound me..
Check out my [url=http://www.hybotics.me]blog[/url] now!
Open your mind, Read, Learn, Think, Apply..


User avatar
Guru ( offline )
Posts: 4904
Posted: 2010-06-09 09:45 
Hi Dale,

I think the problem is that you are computing a pulse width centered at 1500 with a range of: 750 to 2250, but then passing this directly to HSERVO.
But Hservo has it's own input units, which are clock ticks centered at zero. which the conversion looks like: (X * 16) - 24000 for the Bap28 and
(X * 20) - 30000 for the Bap40/Arc32. (Another case where the code has to be modified to go between the two processors)...

So you might try:
hservo [PanServo\(PanPos*16)-2400\MoveSpeed, TiltServo\(TiltPos*16)-2400\MoveSpeed]

Kurt


User avatar
Guru ( offline )
Posts: 2956
Posted: 2010-06-09 10:54 
Hi Kurte

kurte wrote:
I think the problem is that you are computing a pulse width centered at 1500 with a range of: 750 to 2250, but then passing this directly to HSERVO.
But Hservo has it's own input units, which are clock ticks centered at zero. which the conversion looks like: (X * 16) - 24000 for the Bap28 and
(X * 20) - 30000 for the Bap40/Arc32. (Another case where the code has to be modified to go between the two processors)...

Late last night I had an AH HA moment, and it finally dawned on me that I was not using the proper values due to having the Atom Pro. :D I did use the proper formulas in the rest of my code for the steering servos though. :) I finally got a formula that works for at least one side, but I think the reason it doesn't work for the other side is my sticks never seem to go to 0 (meaning 0 - 255). I only seem to get 127 (centered) to 255 for the range on my sticks.

kurte wrote:
So you might try:
hservo [PanServo\(PanPos*16)-2400\MoveSpeed, TiltServo\(TiltPos*16)-2400\MoveSpeed]

I will try this also. :)

8-Dale

_________________
I can usually handle complexity. It's the [b][i]simple[/i][/b] things that always confound me..
Check out my [url=http://www.hybotics.me]blog[/url] now!
Open your mind, Read, Learn, Think, Apply..


User avatar
Guru ( offline )
Posts: 4904
Posted: 2010-06-09 11:33 
linuxguy wrote:
kurte wrote:
So you might try:
hservo [PanServo\(PanPos*16)-2400\MoveSpeed, TiltServo\(TiltPos*16)-2400\MoveSpeed]

I will try this also. :)

8-Dale


Personally if it were me, I would change this part of the code into hservo units.
Change the init of the two values to 0 instead of 1500.

Change the update of values:
PanPos = (PanPos + (lhori-127)) MAX 12000 MIN -12000
TiltPos = (TiltPos + (lvert-127)) MAX 12000 MIN -12000

Then simply pass it through to the HSERVO like before...

If the pan/tilt move too slow or too fast I would then scale the values in these calculations...

Then again I like to change lots of code :D Example in your code I would change the normalize function to use parameters and a return value... Something like:
Code:
Normalize[NormalizeValue, NormalizeNull]
   if NormalizeValue < (NormalizeNull-DeadBand) then
      NormalizeValue = (127*NormalizeValue)/(NormalizeNull-DeadBand) MAX 127
   elseif NormalizeValue > (NormalizeNull+DeadBand)
      NormalizeValue = (127*(NormalizeValue-NormalizeNull)/(255-DeadBand-NormalizeNull) + 127) MAX 255
   else
      NormalizeValue = 127
   endif
return NormalizeNull


Then your code using it can look a little cleaner... Probably produces about the same results code size/speed...
Code:
   Gosub Normalize[lhori, lhori_null], lhori
   Gosub Normalize[lvert, lvert_null], lvert
   Gosub Normalize[rhori, rhori_null], rhori
   Gosub Normalize[rvert, rvert_null], rvert


Back to playing :D
Kurt


User avatar
Guru ( offline )
Posts: 2956
Posted: 2010-06-09 12:00 
kurte wrote:
Change the init of the two values to 0 instead of 1500.

I changed the init as soon as I remembered the -12000 to +12000 range of HSERVO.

kurte wrote:
Change the update of values:
PanPos = (PanPos + (lhori-127)) MAX 12000 MIN -12000
TiltPos = (TiltPos + (lvert-127)) MAX 12000 MIN -12000

This does not seem to work. I am not getting response based on the stick position.

kurte wrote:
Example in your code I would change the normalize function to use parameters and a return value... Something like:
Code:
Normalize[NormalizeValue, NormalizeNull]
   if NormalizeValue < (NormalizeNull-DeadBand) then
      NormalizeValue = (127*NormalizeValue)/(NormalizeNull-DeadBand) MAX 127
   elseif NormalizeValue > (NormalizeNull+DeadBand)
      NormalizeValue = (127*(NormalizeValue-NormalizeNull)/(255-DeadBand-NormalizeNull) + 127) MAX 255
   else
      NormalizeValue = 127
   endif
return NormalizeNull

I will think about doing this. Right now, I don't fully understand some of the code, so am leaving it be for now. :)

kurte wrote:
Then your code using it can look a little cleaner... Probably produces about the same results code size/speed...
Code:
   Gosub Normalize[lhori, lhori_null], lhori
   Gosub Normalize[lvert, lvert_null], lvert
   Gosub Normalize[rhori, rhori_null], rhori
   Gosub Normalize[rvert, rvert_null], rvert

I agree. This is much cleaner.

Are the analog sticks supposed to go from 0 - 255? I am only getting 127 (centered) to 255 on my PS2 analog sticks

8-Dale

_________________
I can usually handle complexity. It's the [b][i]simple[/i][/b] things that always confound me..
Check out my [url=http://www.hybotics.me]blog[/url] now!
Open your mind, Read, Learn, Think, Apply..


User avatar
Guru ( offline )
Posts: 9258
Posted: 2010-06-09 12:07 
From the sound of it you are missing the most significant bit in your reading the PS2 routine. ;)

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...


User avatar
Guru ( offline )
Posts: 2956
Posted: 2010-06-09 12:09 
Robot Dude wrote:
From the sound of it you are missing the most significant bit in your reading the PS2 routine. ;)

I copied the Read_PSX_Data routine directly from the ps24wd1.bas program. I only changed the name of it.

My current formula is:
Code:
TestPos = (((lhori - 127) * 1.411) * StepsPerDegree)  ' MAX 12000 MIN -12000

I wanted to see the raw value being created by the formula, which never goes negative. If my sticks would give values < 127, this formula should work fine for all stick values. I calculated the 1.411 constant by doing 127 (half stick range) divided by 90 (half servo range in degrees).

8-Dale

_________________
I can usually handle complexity. It's the [b][i]simple[/i][/b] things that always confound me..
Check out my [url=http://www.hybotics.me]blog[/url] now!
Open your mind, Read, Learn, Think, Apply..


User avatar
Guru ( offline )
Posts: 9258
Posted: 2010-06-09 12:20 
Have you tested the controller with our simple test code to display the values in the terminal? This would eliminate the math from the equation. wutha, remove math from the equation... :shock: Bwaaaahaaaahaaa

http://www.lynxmotion.com/images/html/build034.htm

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...


User avatar
Guru ( offline )
Posts: 2956
Posted: 2010-06-09 12:35 
Robot Dude wrote:
Have you tested the controller with our simple test code to display the values in the terminal? This would eliminate the math from the equation. wutha, remove math from the equation... :shock: Bwaaaahaaaahaaa

The printed out by that program go by so fast I can not tell what is happening. All I can see is lots of 255 values no matter what I do on the controller.

I have in my code:
Code:
      serout S_OUT,i9600,["Remote, Left H: ",dec3 lhori\3,", Left V: ",dec3 lvert\3,", PanPos: ",sdec6 PanPos\6,", TiltPos: ",sdec6 TiltPos\6,", TestPos: ",sdec6 TestPos\6,13]

which does print the raw values. However, I am doing it at a slower speed.

8-Dale

_________________
I can usually handle complexity. It's the [b][i]simple[/i][/b] things that always confound me..
Check out my [url=http://www.hybotics.me]blog[/url] now!
Open your mind, Read, Learn, Think, Apply..


User avatar
Guru ( offline )
Posts: 9258
Posted: 2010-06-09 13:54 
dale wrote:
The printed out by that program go by so fast I can not tell what is happening. All I can see is lots of 255 values no matter what I do on the controller.


You can click disconnect to see the values. If they are all 255 then you are on the wrong pins or something is wrong... This would be a good help for me if you could get it to work. This will eliminate any code issues you may be having. You said your code prints, but you never actually said what the values were.

This is simple really.

If the test code works, meaning you get 0-255 across the entire range of the controller, then you have a code issue.

If you get 127-255 repeated twice in the throw, or you get 0 until moving the stick half way up, then 127-255 through the rest of the range, then you have a hardware / PS2 controller problem.

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...


User avatar
Guru ( offline )
Posts: 2956
Posted: 2010-06-09 14:16 
Robot Dude wrote:
You can click disconnect to see the values. If they are all 255 then you are on the wrong pins or something is wrong... This would be a good help for me if you could get it to work. This will eliminate any code issues you may be having. You said your code prints, but you never actually said what the values were.

I'm unable to disconnect while the test program is running. I actually can't do anything in Basic Micro Studio (#30) while this program is running. In fact, I just had to forcefully kill BMS because it was sapping 20% - 60% of my CPU time and I could not get it to come to the foreground.

Robot Dude wrote:
If the test code works, meaning you get 0-255 across the entire range of the controller, then you have a code issue.

I do not get 0 - 255 on either of the analog sticks (horizontal OR vertical). All I see is 127 - 255, at least when I am doing my own serouts from my software. I only see 255 values from the test program, which is weird.

Robot Dude wrote:
If you get 127-255 repeated twice in the throw, or you get 0 until moving the stick half way up, then 127-255 through the rest of the range, then you have a hardware / PS2 controller problem.

I only get 127 - 255 on the analog sticks when running my own code. I've never seen them go below 127. I can read all the buttons perfectly.

8-Dale

_________________
I can usually handle complexity. It's the [b][i]simple[/i][/b] things that always confound me..
Check out my [url=http://www.hybotics.me]blog[/url] now!
Open your mind, Read, Learn, Think, Apply..


User avatar
Guru ( offline )
Posts: 9258
Posted: 2010-06-09 14:36 
If you think you have problems with studio, then uninstall it and reinstall it. I'm approaching this with logic, but it's not getting me anywhere. Troubleshooting is a process of elimination... Eliminate something already...

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...


User avatar
Guru ( offline )
Posts: 2956
Posted: 2010-06-09 14:52 
Robot Dude wrote:
If you think you have problems with studio, then uninstall it and reinstall it. I'm approaching this with logic, but it's not getting me anywhere. Troubleshooting is a process of elimination... Eliminate something already...

I do know how to troubleshoot. Just because you and I might go about troubleshooting the same problem in different ways, it does not mean either of our methods is wrong. I am confident all my connections for the PS2 controller are correct. If I reverse my PS2 connections, I get a very fast blinking connect light on the receiver. I change a single thing and then retest - otherwise I have no idea what caused any change that might occur.

Troubleshooting does not always involve eliminating something.. I will continue working on this on my own.

Dale

_________________
I can usually handle complexity. It's the [b][i]simple[/i][/b] things that always confound me..
Check out my [url=http://www.hybotics.me]blog[/url] now!
Open your mind, Read, Learn, Think, Apply..


1, 2, 3

All times are UTC - 5 hours [ DST ]. It is currently 2014-09-17 15:33
Feedback Form
Feedback Form