Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help!!!!!!! #3

Open
judemoses opened this issue Jan 14, 2021 · 1 comment
Open

Help!!!!!!! #3

judemoses opened this issue Jan 14, 2021 · 1 comment

Comments

@judemoses
Copy link

hi !my english is limited 我猜你是中国人!我也是!如果可以的话请求你的帮助![email protected]
i want to turn by gyro,but i fail,the degrees of gyro is raising ,is a bug?how can i fix it?

void GyroLeftTurn(int nLTargetDegree, int nTurnLPower) {
//ev3_gyro_sensor_reset (SENSOR_G);
while (-1 * (ev3_gyro_sensor_get_angle(SENSOR_G)) <= nLTargetDegree) {
ev3_motor_set_power(R_MOTOR, nTurnLPower);
ev3_motor_set_power(L_MOTOR, 0);
}

ev3_motor_stop(L_MOTOR, true);
ev3_motor_stop(R_MOTOR, true);
}

@spsquared
Copy link

spsquared commented May 10, 2022

Most likely your gyro is drifting. The angle it reads does not always stay the same even when not moving, because it's not perfect. It has nothing to do with code, you just have to wait 3-5 seconds after resetting the gyro to make sure it starts properly. Resetting the gyro resets the count, and to fix drift you can run ev3_gyro_sensor_get_rate() and ev3_gyro_sensor_get_angle() and then waiting to reset the gyro completely (turn it off and then back on again), and if you move while it is turning on it will cause it to drift. This should fix the drift issue but might not in some cases.

中文(我用了Google Translate因为我的中文不好 ¯\_(ツ)_/¯):
您的陀螺仪很可能正在漂移。 即使不移动,它读取的角度也不总是保持不变,因为它并不完美。 它与代码无关,您只需在重置陀螺仪后等待 3-5 秒以确保其正常启动。 重置陀螺仪会重置计数,要修复漂移,您可以运行 ev3_gyro_sensor_get_rate()ev3_gyro_sensor_get_angle() 然后等待完全重置陀螺仪(将其关闭然后重新打开),如果您在它转动时移动 在它上面会导致它漂移。这应该可以解决漂移问题,但在某些情况下可能无法解决。

void GyroLeftTurn(int nLTargetDegree, int nTurnLPower) {
  ev3_gyro_sensor_reset (SENSOR_G);
  ev3_gyro_sensor_get_rate(SENSOR_G);
  ev3_gyro_sensor_get_angle(SENSOR_G);
  tslp_tsk(3000);
  while (-1 * (ev3_gyro_sensor_get_angle(SENSOR_G)) <= nLTargetDegree) {
    ev3_motor_set_power(R_MOTOR, nTurnLPower);
    ev3_motor_set_power(L_MOTOR, 0);
  }

  ev3_motor_stop(L_MOTOR, true);
  ev3_motor_stop(R_MOTOR, true);
}

Edit: add modified code

Also I'm just a person who just so happened to have used EV3 gyros before and I don't know a lot of C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants