Problems using a joystick as a cursor

I have a question about using the joystick as a cursor because I
intend to use it on the PSP.

The dilemma is that when the joystick is released, the cursor should
stop. However, it will continue at a slow speed in the direction it
was previously moving at. I figure this is becuase the joystick
position is only read after a joystick event and the previously read
event was ‘just’ before the joystick reached a neutral state.

When there is a joystick event, I’m recording the roll and yaw, using
that to create a cursor velocity, then updating the curosr position
every tick.

What makes this interesting is that when the joystick is still, but
not in a neutral position, the cursor should still be moving.

But I can only think of one way to avoid this issue and that is:

  • when there are no events, set the roll and pitch and therefore
    velocity of the cursor to zero.

But this assumes that there is always some kind of event happening
while there is no joystick event and that there are no events at all
when the joystick is neutral.

Hence this idea is completely crap. Unusually though it is only 'up’
and ‘right’ that will keep slowly moving in the previous direction.

I’m stumped, cheers for any ideas.

Glenn

I have a question about using the joystick as a cursor because I
intend to use it on the PSP.

What makes this interesting is that when the joystick is still, but
not in a neutral position, the cursor should still be moving.

So why not just keep moving it, until it DOES return to neutral?

e.g., when you receive an event, set some variables that record
the stick’s position. Then use THOSE variables, rather than the
events (which only come in during changes, it sounds like).

Admittedly, haven’t touched a PSP in quite a few months (sadly,
didn’t sund like a very interesting gaming platform…) so I can’t
remember what the joystick does, or what it feels like.
(Compared to, say, a Nintendo NES pad or Atari 2600 stick :slight_smile: )

-bill1On Mon, Feb 12, 2007 at 12:11:44AM +1300, Glenn McCord wrote:

What I want is when the joystick is moved hard left, the cursor moves
fast to the left. If it is moved partly to the left, the cursor moves
slowly to the left. When the joystick is released, the curosr stops.

The problem is that the cursor will sometimes continue to move very
slowly in the same direction after the joystick is released.

I use:
if ( (event.jaxis.value < -2000) || (event.jaxis.value > 2000) )
{
//get roll and pitch values
}
else
{
//set roll and pitch to zero
}

and increasing the buffer to 5000 does work, but it isn’t ideal
because the joystick becomes less sensitive.

So when there is an event, I ‘am’ getting the stick’s position and
using it to move the cursor, the problem is that sometime an event is
not triggered when the joystick hits zeroish. The last recorded event
is just outside the buffer.

It would be good if I could find out the position of the joystick
without requiring an event but my understanding is that it isn’t
possible.

If I give the joystick the tinyist of nudges, it stops. I may just be
asking too much and will have to use the larger buffer. But, I’m just
trying my luck at getting some alternative ideas.

In regards to programming with the PSP, the appeal for me was that I
can use SDL and OpenGL (using PSPGL), my preferred libraries. No other
handheld has 3D acceleration?

GlennOn 2/12/07, Bill Kendrick wrote:

On Mon, Feb 12, 2007 at 12:11:44AM +1300, Glenn McCord wrote:

I have a question about using the joystick as a cursor because I
intend to use it on the PSP.

What makes this interesting is that when the joystick is still, but
not in a neutral position, the cursor should still be moving.

So why not just keep moving it, until it DOES return to neutral?

e.g., when you receive an event, set some variables that record
the stick’s position. Then use THOSE variables, rather than the
events (which only come in during changes, it sounds like).

Admittedly, haven’t touched a PSP in quite a few months (sadly,
didn’t sund like a very interesting gaming platform…) so I can’t
remember what the joystick does, or what it feels like.
(Compared to, say, a Nintendo NES pad or Atari 2600 stick :slight_smile: )

-bill1


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Could it be because the joystick is still reporting that it’s not
centered after it’s been moved off center once? Have you looked at the
values that it’s reporting to determine if it still gives you a small
value?

Lilith

What I want is when the joystick is moved hard left, the cursor moves
fast to the left. If it is moved partly to the left, the cursor moves
slowly to the left. When the joystick is released, the curosr stops.

The problem is that the cursor will sometimes continue to move very
slowly in the same direction after the joystick is released.

I use:
if ( (event.jaxis.value < -2000) || (event.jaxis.value > 2000) )
{
//get roll and pitch values
}
else
{
//set roll and pitch to zero
}

and increasing the buffer to 5000 does work, but it isn’t ideal
because the joystick becomes less sensitive.

So when there is an event, I ‘am’ getting the stick’s position and
using it to move the cursor, the problem is that sometime an event is
not triggered when the joystick hits zeroish. The last recorded event
is just outside the buffer.

It would be good if I could find out the position of the joystick
without requiring an event but my understanding is that it isn’t
possible.

If I give the joystick the tinyist of nudges, it stops. I may just be
asking too much and will have to use the larger buffer. But, I’m just
trying my luck at getting some alternative ideas.

In regards to programming with the PSP, the appeal for me was that I
can use SDL and OpenGL (using PSPGL), my preferred libraries. No other
handheld has 3D acceleration?

Glenn

I have a question about using the joystick as a cursor because I
intend to use it on the PSP.

What makes this interesting is that when the joystick is still,
but>>> On 2/12/2007 at 3:02 AM, “Glenn McCord” <glenn.mccord at gmail.com> wrote:
On 2/12/07, Bill Kendrick wrote:
On Mon, Feb 12, 2007 at 12:11:44AM +1300, Glenn McCord wrote:

not in a neutral position, the cursor should still be moving.

So why not just keep moving it, until it DOES return to neutral?

e.g., when you receive an event, set some variables that record
the stick’s position. Then use THOSE variables, rather than the
events (which only come in during changes, it sounds like).

Admittedly, haven’t touched a PSP in quite a few months (sadly,
didn’t sund like a very interesting gaming platform…) so I can’t
remember what the joystick does, or what it feels like.
(Compared to, say, a Nintendo NES pad or Atari 2600 stick :slight_smile: )

-bill1


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

[regarding Sony PSP]

No other handheld has 3D acceleration?

The Nintendo DS does. Wikipedia says:

The system’s 3D hardware performs transform and lighting,
texture-coordinate transformation, texture mapping, alpha blending,
anti-aliasing, cel shading and z-buffering. […]

-bill!On Mon, Feb 12, 2007 at 10:02:35PM +1300, Glenn McCord wrote:

I am not sure which type of physical problem you have here so will
briefly discuss both in regards to analog joysticks: self centering
and non self centering. When I have programmed joysticks (analog
devices) in the past, even targeting high quality self centering
joysticks, I could not make an assumption the device would be
centered when let go. With analog devices there is usually drift of
which even ambient temperature can be a factor though usually very
small.

Keeping in mind the potential for drift, if you are programming for a
self centering joystick and you want an object to stop motion based
on a return to center then you need to ensure there is a centered
dead zone, a buffer if you will, in that if the signals twitch a
little they will be ignored.

If the joystick is not self centering and you need to stop an object
motion based on the joystick stopping at any given physical position
they you need to track that with dynamic centering which is just a
modification of the above suggestion.

With all that programming you will have the tools to track current
direction to keep a cursor moving where you want it to go with
control over keeping jerkiness out of the process.

ToddOn 2/12/07, Bill Kendrick wrote:

On Mon, Feb 12, 2007 at 12:11:44AM +1300, Glenn McCord wrote:

I have a question about using the joystick as a cursor because I
intend to use it on the PSP.

What makes this interesting is that when the joystick is still, but
not in a neutral position, the cursor should still be moving.

It’s starting to look like I was on the right and only track then by using

if ( (event.jaxis.value < -2000) || (event.jaxis.value > 2000) )
{
//get roll and pitch values
}
else
{
//set roll and pitch to zero
}

Until I can get text to display in an OpenGL world, I can’t see what
the joystick position is on this PSP (no console window obviously) and
not that many easy to use font libraries. I’m currently trying to
figure out SDL_ttf.

If using the code above, could it be possible that the last joystick
event might occur at position (2001, 0) before the joystick centres
itself? I suppose it would and that is the reason for the cursor
continuing to move in that direction. But shouldn’t events be
happening more regularly? Even so, it’s starting to look like 2000 is
a too smaller buffer. At least on a PSP anyway. It’s fine on my PC.

GlennOn 2/15/07, Todd A. Kennard <todd.a.kennard at earthlink.net> wrote:

On 2/12/07, Bill Kendrick wrote:

On Mon, Feb 12, 2007 at 12:11:44AM +1300, Glenn McCord wrote:

I have a question about using the joystick as a cursor because I
intend to use it on the PSP.

What makes this interesting is that when the joystick is still, but
not in a neutral position, the cursor should still be moving.

I am not sure which type of physical problem you have here so will briefly
discuss both in regards to analog joysticks: self centering and non self
centering. When I have programmed joysticks (analog devices) in the past,
even targeting high quality self centering joysticks, I could not make an
assumption the device would be centered when let go. With analog devices
there is usually drift of which even ambient temperature can be a factor
though usually very small.

Keeping in mind the potential for drift, if you are programming for a self
centering joystick and you want an object to stop motion based on a return
to center then you need to ensure there is a centered dead zone, a buffer if
you will, in that if the signals twitch a little they will be ignored.

If the joystick is not self centering and you need to stop an object motion
based on the joystick stopping at any given physical position they you need
to track that with dynamic centering which is just a modification of the
above suggestion.

With all that programming you will have the tools to track current direction
to keep a cursor moving where you want it to go with control over keeping
jerkiness out of the process.

Todd


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org