Well, attempt number two.
In this post I will try to talk about one of the parts of my graduation project.
Using a Mouse-type controller as a planar position sensor.
What is the plus Mouse?
')
Formulation of the problem.
- Getting coordinates from a mouse-type controller in the MatLab software package
First, a little theory.
Working with the mouse in MatLab will be implemented by working with
rs232 (on another com port), the MBED controller will communicate with the mouse and issue packets of 3 bytes to the port on request. In MatLab, packet analysis will be performed using a simple block scheme and then parsed into control signals and data signals.
Why was the method of communication through rs232 chosen? Because this way allows to work with the mouse through the standard blocks of MatLab, thereby leaving the possibility of use in all modes (Simulink, RTW, xPC).
Let's take a look at MBED now.

As we can see, the controller has just a crazy number of ports, from this variety we will need only 4, and 2 of them will be power :)
Here's what it looks like in a prototype board.

The mouse works with the end device through 2 ports DATA and CLOCK, by the names I think it is not difficult to guess what is what;)
In our case, we connect the CLOCK to the controller's 28 foot, and the DATA to the 26.
Power take with feet GND and VU.
The program for the controller is extremely simple.
////////////////////////////////////////////////
main.cpp
////////////////////////////////////////////////
#include "mbed.h"
#include "PS2Mse.h"
PS2Mse mse ( p28, p26 ) ;
Serial pc ( USBTX, USBRX ) ;
int main ( ) {
mse. wr ( 0xf0 ) ;
mse. wr ( 0xff ) ; // reset
mse. rd ( ) ; // ack byte
mse. rd ( ) ; // blank * /
mse. rd ( ) ; // blank * /
mse. wr ( 0xf0 ) ; // remote mode
mse. rd ( ) ; // ack
char mstat ;
char mx ;
char my ;
while ( 1 ) {
while ( pc. getc ( ) ! = 0 ) {
mse. wr ( 0xeb ) ;
mse. rd ( ) ;
mstat = mse. rd ( ) ;
mx = mse. rd ( ) ;
my = mse. rd ( ) ;
pc. printf ( "% c% c% c \ r \ n " , mstat, mx, my ) ;
}
}
}
////////////////////////////////////////////////
PS2Mse.cpp
////////////////////////////////////////////////
dumpz.org/17295////////////////////////////////////////////////
PS2Mse.h
////////////////////////////////////////////////
dumpz.org/17297As we see all that the program performs, it waits for any character from the host (PC) and returns the current values of the coordinates and mouse buttons in the form of a 3-byte packet.
Consider what happens next.
This is how our block looks like to work in MatLab.

Let's look inside the Mouse block.

As we see here, everything is also quite simple, the first byte is being analyzed, 7 flag bits are extracted from it
- 1 - The first mouse button is pressed
- 2 - The second mouse button is pressed.
- 3 - The third mouse button is pressed.
- 5 - increment sign for X
- 6 - Y increment sign
- 7 - X overflow
- 8 - Y overflow
The second and third bytes are increments in X and Y, respectively.
As we can see using the mouse is very simple.
If it is interesting to someone, then there will be metrological studies of the mouse.
UPDATE:
By the way, a slight clarification, my diploma about something else, I was asked to make a sensor (as is usually done at the institute) to help another specialist;)
My diploma is completely about other things, and more specifically about the Lego ball and compass :)
Nous try to explain a little why all this fuss was.
There is a task to control a two-stage non-rigid manipulator.
Many methods have been tried to determine the final position of each of the links, ranging from strain gauges glued to the links, ending with delusional ideas with laser distance sensors.
The ultimate goal to determine where all the same link moved after the supply of control pulses to the servos, as the link is non-rigid, and the design has some inertia, it’s useless to use tachogenerators and counters of the engines themselves.
Under MatLab, the sharpening was done precisely for this modeling / programming, selection of PID and similar regulators. Reference about the same tasks in the diploma
www.lib.ua-ru.net/diss/cont/61880.htmlIn general, the topic of controlling non-rigid manipulators is a favorite topic of the specialty of the Management System, so much has already been written about this topic.
The mouse was taken as the finished non-contact position sensor in the price clearly exceeds the cost of the mouse.
I tried as best I could to explain, on March 9 I would photograph and try to explain in detail.