Skip to content

Commit 89828c9

Browse files
authored
Fix initialization on simulation mode and old devices (#223)
* Fix driver param initialization * Fix dummy YP_PARAM_PWM_MAX setting
1 parent f65ceca commit 89828c9

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/ypspur-coordinator.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ int main(int argc, char* argv[])
136136
int update_thread_en;
137137
Ver_t version;
138138
Param_t driver_param;
139-
int i, ret;
139+
int ret;
140140
ParametersPtr param;
141141
char paramfile[512];
142142
int quit;
@@ -227,6 +227,11 @@ int main(int argc, char* argv[])
227227

228228
yprintf(OUTPUT_LV_INFO, "Device Information\n");
229229

230+
// Clear driver params
231+
driver_param.robot_name[0] = 0;
232+
driver_param.pwm_resolution[0] = 0;
233+
strcpy(driver_param.motor_num, "2");
234+
230235
if (!(option(OPTION_WITHOUT_DEVICE)))
231236
{
232237
yprintf(OUTPUT_LV_INFO, " Port : %s \n", param->device_name);
@@ -237,6 +242,7 @@ int main(int argc, char* argv[])
237242
}
238243
if (!(option(OPTION_DO_NOT_USE_YP)))
239244
{
245+
int i;
240246
int current, age;
241247
int device_current, device_age;
242248
sscanf(YP_PROTOCOL_NAME, "YPP:%d:%d", &current, &age);
@@ -318,12 +324,6 @@ int main(int argc, char* argv[])
318324
break;
319325
}
320326
}
321-
else
322-
{
323-
driver_param.robot_name[0] = 0;
324-
driver_param.pwm_resolution[0] = 0;
325-
strcpy(driver_param.motor_num, "2");
326-
}
327327
fflush(stderr);
328328
}
329329
else
@@ -391,8 +391,7 @@ int main(int argc, char* argv[])
391391
{
392392
if (strlen(driver_param.pwm_resolution) > 0)
393393
{
394-
int i;
395-
for (i = 0; i < YP_PARAM_MAX_MOTOR_NUM; i++)
394+
for (int i = 0; i < YP_PARAM_MAX_MOTOR_NUM; i++)
396395
{
397396
*pp(YP_PARAM_PWM_MAX, i) = atoi(driver_param.pwm_resolution);
398397
}
@@ -401,7 +400,10 @@ int main(int argc, char* argv[])
401400
{
402401
if (option(OPTION_DO_NOT_USE_YP))
403402
{
404-
*pp(YP_PARAM_PWM_MAX, i) = 1000; // dummy value for simulation
403+
for (int i = 0; i < YP_PARAM_MAX_MOTOR_NUM; i++)
404+
{
405+
*pp(YP_PARAM_PWM_MAX, i) = 1000; // dummy value for simulation
406+
}
405407
}
406408
else
407409
{
@@ -465,7 +467,7 @@ int main(int argc, char* argv[])
465467
/* サーボをかける */
466468
SpurUserParamsPtr spur;
467469
spur = get_spur_user_param_ptr();
468-
for (i = 0; i < YP_PARAM_MAX_MOTOR_NUM; i++)
470+
for (int i = 0; i < YP_PARAM_MAX_MOTOR_NUM; i++)
469471
{
470472
spur->wheel_mode[i] = MOTOR_CONTROL_VEL;
471473
spur->wheel_mode_prev[i] = -1;

0 commit comments

Comments
 (0)