我有一个项目要完成,该项目涉及“使用传感器控制PC鼠标光标”,其中我必须使用Java,Arduino和MPU-6050作为传感器。
我打算使用下面的代码来移动鼠标光标
public void moveRight() throws AWTException {
PointerInfo a = MouseInfo.getPointerInfo();
Point b = a.getLocation();
int x = (int) b.getX();
int y = (int) b.getY();
Robot r = new Robot();
r.mouseMove(x+10, y );}
我计划创建用于鼠标光标移动的moveRight(),moveLeft()moveUP(),moveDown()函数。该功能将在MPU-6050传感器运行的基础上调用。
但是我不知道如何将MPU-6050的原始数据转换为可用于光标移动的数据。
答案 0 :(得分:0)
MPU6050
has a accelerometer and a gyroscope (also a temperature sensor). What you need is the orientation of the device and to get this you could calculate the Euler
angles.
MPU6050 throws in raw accelerometer and gyro values that you must convert to Euler angles
which can be send over any serial bus to your PC. The rest your Java code will take care.
How to get started
1. Use an arduino library to fetch the raw readings
Here and here (this is a famous and well written library)
2. Use a complementary filter (use Madgwick's, you just need acc and gyro) to "sensor fuse" (google: sensor fusion) the two readings to calculate the yaw, pitch, roll (euler angles). These are your orientation in a 3D plane.
3. Pass on these calculations to the PC where you can assign the mouse behavior according to the orientation. Like higher speed of movement for the mouse pointer if we have a higher inclination.
Why all the trouble?
Your application needs to control the mouse by lets say how you move your hand. We could have calculated the angle of inclination using just accelerometer readings but your hand is not a stationary object and can influence the sensor to have more than "acceleration due to gravity".
So it's recommended you use a complementary filter (or a Extended Kalman, it.s a good read, but maybe a overkill for your application) to calculate the angles.
Each of the repos I've linked have example code and resources to help you get started. Good luck!