sensor - Get Forward, Backward left right sesnor android -
i have small project, in need detect movement of device ex: have mobile held on table if move device left "like moving pc mouse", need know if move right, need know if move forward, , backward need know
i searched , used many tutorials, tutorials gave me numbers changes lot when device not moved!! tried this
if (event.sensor.gettype() == sensor.type_accelerometer){ mgravity = event.values.clone(); // shake detection float x = mgravity[0]; float y = mgravity[1]; float z = mgravity[2]; maccellast = maccelcurrent; maccelcurrent = (float)math.sqrt(x * x + y * y + z * z); float delta = maccelcurrent - maccellast; maccel = maccel * 0.9f + delta; // make higher or lower according how // motion want detect if(maccel > 0.0005){ ((textview)findviewbyid(r.id.xfield)).settext("x:" + string.valueof((x))); ((textview)findviewbyid(r.id.yfield)).settext("y:" + string.valueof((y))); ((textview)findviewbyid(r.id.zfield)).settext("z:" + string.valueof(z)); } }
thanks
from android documentation:
measures acceleration force in m/s2 applied device on 3 physical axes (x, y, , z), including force of gravity.
i.e.accelerometer detects acceleration, not movement, not speed , not direction. in nutshell: if movement @ constant speed accelerometer show 0. need write algorithm parse speed and/or direction acceleration. involves lot of study physics , mathematics. in nutshell: integral of acceleration speed, second integral of acceleration direction. (of course more complex, give direction of start exploring).
Comments
Post a Comment