go_away

Author Topic: Mouse Controlled  (Read 2357 times)

0 Members and 1 Guest are viewing this topic.

Offline wootwootmanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Mouse Controlled
« on: March 29, 2010, 09:02:10 PM »
hi, i had previously posted here about my first project ( http://www.societyofrobots.com/robotforum/index.php?topic=10710.msg81557#msg81557 ) and was wondering if someone can point me in the direction of finding out how to directly control two servos using a standard ps/2 mouse. nothing that requires it running through a pc, I'd like to have the mouse directly connected to my board (which by the way is an arduino duemilanove). I know the connections would work out something like this http://www.arduino.cc/playground/ComponentLib/Ps2mouse but i dont know how the programming would go.

In short: how do i translate a mouse's x,y coordinates into servo positions?

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Mouse Controlled
« Reply #1 on: March 29, 2010, 09:41:15 PM »
That link includes the code. The mouse basically reports velocity changes, so scale that to suit the servo.

Offline wootwootmanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: Mouse Controlled
« Reply #2 on: March 29, 2010, 10:07:56 PM »
the first download right? which file is it and do i use it? and does it output position or "velocity"?

Offline cyberfish

  • Robot Overlord
  • ****
  • Posts: 163
  • Helpful? 3
Re: Mouse Controlled
« Reply #3 on: March 30, 2010, 12:23:53 AM »
If you think about it, how does a mouse know its position? Does it have a high accuracy GPS chip inside?

Offline wootwootmanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: Mouse Controlled
« Reply #4 on: March 30, 2010, 09:15:34 AM »
no.....theres a little ball that moves around. the x y movements are picked up and sent through the wire, but im not sure how its decoded.

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,930
  • Helpful? 98
Re: Mouse Controlled
« Reply #5 on: March 30, 2010, 10:59:01 AM »
Do you try googling "PS2 mouse interface"?
Lots of hits with complete explanations of how a mouse works and how to interface a mouse.

It should be no problem to connect a PS2 mouse to any uController and write code for reading the mouse and using it for control.

Offline cyberfish

  • Robot Overlord
  • ****
  • Posts: 163
  • Helpful? 3
Re: Mouse Controlled
« Reply #6 on: March 30, 2010, 12:16:35 PM »
Quote
x y movements

Note that that's velocity, not position.

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
Re: Mouse Controlled
« Reply #7 on: March 30, 2010, 12:33:07 PM »
Quote
x y movements

Note that that's velocity, not position.

It's relative position.

Offline cyberfish

  • Robot Overlord
  • ****
  • Posts: 163
  • Helpful? 3
Re: Mouse Controlled
« Reply #8 on: March 30, 2010, 12:34:54 PM »
No, to get relative position, you need to integrate velocity over time.

Offline wootwootmanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: Mouse Controlled
« Reply #9 on: March 30, 2010, 05:00:57 PM »
i dont have a ucontroller, its an arduino. but that sketch doesnt return mouse values as x y positions? then how do i control the servos?

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
Re: Mouse Controlled
« Reply #10 on: March 30, 2010, 05:44:16 PM »
No, to get relative position, you need to integrate velocity over time.


http://www.computer-engineering.org/ps2mouse/

Offline wootwootmanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: Mouse Controlled
« Reply #11 on: March 30, 2010, 07:14:12 PM »
No, to get relative position, you need to integrate velocity over time.


http://www.computer-engineering.org/ps2mouse/


i dont understand any of that............

Offline cyberfish

  • Robot Overlord
  • ****
  • Posts: 163
  • Helpful? 3
Re: Mouse Controlled
« Reply #12 on: March 30, 2010, 08:47:07 PM »
Ah, relative position to the previous reading.

That IS velocity.

Velocity is the derivative of position, which is the change in position over some period of time (between 2 readings).

Offline wootwootmanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: Mouse Controlled
« Reply #13 on: March 30, 2010, 10:09:14 PM »
oh its calculus. i recognize it from junior year of high school. so the sketch returns "velocity" and not position? how would i change it?
« Last Edit: March 30, 2010, 10:10:50 PM by wootwootman »

Offline cyberfish

  • Robot Overlord
  • ****
  • Posts: 163
  • Helpful? 3
Re: Mouse Controlled
« Reply #14 on: March 30, 2010, 10:11:34 PM »
Just add all readings together ("integration"). It will give you the mouse's position, relative to the starting point.

Offline wootwootmanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: Mouse Controlled
« Reply #15 on: March 31, 2010, 09:33:20 AM »
you know which sketch im talking about right?

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Mouse Controlled
« Reply #16 on: March 31, 2010, 06:27:12 PM »
Hi,

Ah, relative position to the previous reading.

That IS velocity.

Velocity is the derivative of position, which is the change in position over some period of time (between 2 readings).
No, the mouse only gives number of tics in X and Y direction respectively. The mouse doesn't give any timing information whatsoever. Some mouse driver software add the timing to get a velocity reading for nonlinear mouse speed (often called acceleration in the driver setup).
But, in short, NO, relative position alone is NOT velocity.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline cyberfish

  • Robot Overlord
  • ****
  • Posts: 163
  • Helpful? 3
Re: Mouse Controlled
« Reply #17 on: March 31, 2010, 08:23:55 PM »
To get velocity we need delta position and delta time. The mouse only sends delta position because the host knows delta time already.

Anyways, we all know what we are talking about. This is just terminology/interpretation. Let's leave it at that.

Offline gossamer

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Re: Mouse Controlled
« Reply #18 on: April 01, 2010, 05:58:39 AM »
Nah, Mouse have two incremental encoders, for every axes it has one. So when you move your mouse in x axis it only gives you impulse per encoder gradation (depends on mouse resolution). Than OS calculates that movement with "absolute - on screen" position. So you will not have either position or velocity but only interrupt that position has been changed. You will need to measure time between impulses to get velocity and integrate those values to get relative position.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Mouse Controlled
« Reply #19 on: April 01, 2010, 07:39:01 AM »
Hi,

Anyways, we all know what we are talking about. This is just terminology/interpretation. Let's leave it at that.

Interpretation doesn't cover mixing up reality ;)  and you didn't seem to keen on letting it fly a while ago? (http://www.societyofrobots.com/robotforum/index.php?topic=10773.msg81873#msg81873)  ::)
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline cyberfish

  • Robot Overlord
  • ****
  • Posts: 163
  • Helpful? 3
Re: Mouse Controlled
« Reply #20 on: April 01, 2010, 09:37:31 PM »
When the mouse is not changing position, value returned is always 0.

If you move the mouse some distance, then stop, value returned will be some value for some time, then 0 when you stop it.

If you move the mouse at a constant velocity, value returned will be constant non-zero.

If you move the mouse at a constant acceleration, value returned will be linear.

All those behaviours match that of velocity.

If it smells like, feels like, and looks like velocity... I'm gonna call it velocity.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Mouse Controlled
« Reply #21 on: April 02, 2010, 06:47:44 AM »
Hi,

If you move the mouse at a constant velocity, value returned will be constant non-zero.
You really need to read up on how a mouse communicates.
There is nothing constant about it, it's polled packets.
That's how, when the OS is too busy to read the mouse, it may suddenly "jump", when it gets around to reading a larger accumulated X/Y set.


All those behaviours match that of velocity.

If it smells like, feels like, and looks like velocity... I'm gonna call it velocity.
A bicycle have similar behaviours of a motorcycle if you look at it as superficial as that, but I still know the difference  ;)
And however you call the world ain't gonna change it the least bit... It's just making it harder to do cyberfish comms when you disagree with the world at large  ;D
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline cyberfish

  • Robot Overlord
  • ****
  • Posts: 163
  • Helpful? 3
Re: Mouse Controlled
« Reply #22 on: April 02, 2010, 04:25:31 PM »
Ah, I was under the assumption that people would poll it at constant intervals, in which case it would be velocity.

Offline wootwootmanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: Mouse Controlled
« Reply #23 on: April 02, 2010, 04:42:22 PM »
so if i hooked it up, and used some random mouse sketch, moved the mouse forward along the mouse axis would it return y+1 ? and if i pulled it back y-1? or would it be 1,2,3,4,5,6,7.....?

Offline cyberfish

  • Robot Overlord
  • ****
  • Posts: 163
  • Helpful? 3
Re: Mouse Controlled
« Reply #24 on: April 02, 2010, 04:48:09 PM »
If you move it at a constant speed in a constant direction and read it at a constant interval, you'll get a constant. eg. 3,3,3,3,3,3,3

Offline wootwootmanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: Mouse Controlled
« Reply #25 on: April 02, 2010, 05:24:28 PM »
what if i had something like
pseudocode:
servo1.write("formerXval"+"returnedXval")
servo2.write("formerYval"+"returnedYval")
of course a negative x or y would be subtracted. can something like this be done?

Offline cyberfish

  • Robot Overlord
  • ****
  • Posts: 163
  • Helpful? 3
Re: Mouse Controlled
« Reply #26 on: April 02, 2010, 05:40:58 PM »
That would depend on what you want it to do.

Offline wootwootmanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: Mouse Controlled
« Reply #27 on: April 02, 2010, 05:47:09 PM »
i want to use a mouse to control a turret like contraption with two servos
actually, i think i may just use a ps2 controller. i just read that theyre arduino compatible

Offline cyberfish

  • Robot Overlord
  • ****
  • Posts: 163
  • Helpful? 3
Re: Mouse Controlled
« Reply #28 on: April 02, 2010, 05:48:12 PM »
Then that will work.

 


Get Your Ad Here

data_list