I am a student and want to make a project where the computer mouse pointer can be controlled via the MPU6050 sensors. So far I have calculated the below things.
pitch and roll with accelerometer data:
def read_word(adr):
high = bus.read_byte_data(address, adr)
low = bus.read_byte_data(address, adr+1)
val = (high << 8) + low
return val
def read_word_2c(adr):
val = read_word(adr)
if (val >= 0x8000):
return -((65535 - val) + 1)
else:
return val
accel_xout = read_word_2c(0x3b)
accel_yout = read_word_2c(0x3d)
accel_zout = read_word_2c(0x3f)
accel_xout_scaled = accel_xout / 16384.0
accel_yout_scaled = accel_yout / 16384.0
accel_zout_scaled = accel_zout / 16384.0
Accpitch=round((math.atan2(accel_yout_scaled,accel_zout_scaled)+math.pi) * 180 / math.pi)
Accroll=round((math.atan2(accel_xout_scaled, accel_zout_scaled)+math.pi) * 180 / math.pi)
mouse_coordinates_x=Accpitch*720/360
mouse_coordinates_y=Accroll*480/360
My question is: Is this the correct way of mapping the output result(degree of orientation in a 3d plane) to the mouse pointer coordinates(x,y)? Is there any other optimal way to do this? Can anyone please help here or give some hints. Thank you in advance.