Skip to content

Commit

Permalink
Fix initial absolute encoder value handling (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat authored Apr 4, 2019
1 parent 22515b6 commit 2b7f724
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/odometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef struct _odometry
double wvel[YP_PARAM_MAX_MOTOR_NUM];
double wang[YP_PARAM_MAX_MOTOR_NUM];
short enc[YP_PARAM_MAX_MOTOR_NUM];
int enc_init[YP_PARAM_MAX_MOTOR_NUM];
double wtorque[YP_PARAM_MAX_MOTOR_NUM];
double torque_trans;
double torque_angular;
Expand Down
10 changes: 10 additions & 0 deletions src/odometry.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ void init_odometry(void)
g_odometry.theta = 0;
for (i = 0; i < YP_PARAM_MAX_MOTOR_NUM; i++)
{
g_odometry.enc[i] = 0;
g_odometry.enc_init[i] = 0;
g_odometry.wang[i] = 0;
g_odometry.wtorque[i] = 0;
g_odometry.wvel[i] = 0;
Expand Down Expand Up @@ -160,6 +162,14 @@ void odometry(OdometryPtr xp, short *cnt, short *pwm, double dt, double time)
{
cnt_diff = (short)cnt[i] - (short)xp->enc[i];
xp->enc[i] = cnt[i];
if (!xp->enc_init[i])
{
cnt_diff = 0;
if (cnt[i] != 0)
{
xp->enc_init[i] = 1;
}
}
}
else
{
Expand Down

0 comments on commit 2b7f724

Please sign in to comment.