차동 드라이브 모바일 로봇 (전자 퍽)을 프로그래밍하여 특정 방향으로 특정 좌표로 이동합니다. 로봇은 좌표에 도달하는 데 아무런 문제가 없습니다. 그러나 좌표에 도달하면 특정한 방향으로 정착 할 수없고 방향을 찾고있는 지점에서 "회전"을 유지할 수 없으므로 누구도이 사전 경험이 있습니까? 나는이 문제에 아주 오래 머물러 있으며, 왜 누군가가 그 이유를 알기를 바랍니다. 코드의 관련 부분이 아래에 붙여 넣어집니다.모바일 로봇 (전자 퍽) 프로그래밍 (C 언어)
static void step() {
if (wb_robot_step(TIME_STEP)==-1) {
wb_robot_cleanup();
exit(EXIT_SUCCESS);
}
}
.
.
.
.
.
static void set_speed(int l, int r)
{
speed[LEFT] = l;
speed[RIGHT] = r;
if (pspeed[LEFT] != speed[LEFT] || pspeed[RIGHT] != speed[RIGHT]) {
wb_differential_wheels_set_speed(speed[LEFT], speed[RIGHT]);
}
}
.
.
.
.
static void goto_position1(float x, float y, float theta)
{
if (VERBOSE > 0) printf("Going to (%f, %f, %f)\n",x,y,theta);
// Set a target position
odometry_goto_set_goal(&og, x, y, theta);
// Move until the robot is close enough to the target position
while (og.result.atgoal == 0) {
// Update position and calculate new speeds
odometry_track_step(og.track);
odometry_goto_step(&og);
// Set the wheel speed
set_speed(og.result.speed_left, og.result.speed_right);
printf("%f",ot.result.theta);
print_position();
step();
} //after exiting while loop speed will be zero
og.result.speed_left = 0;
og.result.speed_right = 0;
if (((og.result.speed_left == 0) && (og.result.speed_right == 0)))
og.result.atgoal = 1;
return;
}
.
.
.
int main(){
//initialisation
while (wb_robot_step(TIME_STEP) != -1) {
goto_position1(0.0000000001,0.00000000001,PI/4);
}
return 0;
}
관련성이있는 부작용으로 : 왜 'spee_left'와'speed_right'를 0으로 설정하고, 그들이 0인지 즉시 확인합니까? 어쨌든, 문제는'og.result.atgoal'의 계산과 같다. 로봇이 달성하기에 "너무 가깝다"라는 정의가 너무 정확하거나, 언제나 og.result.atgoal을 0으로 재설정하고 있습니다. 위에서 언급 한 'if'가 항상 true이기 때문에 'og.result.atgoal'은 항상 즉시 1이되어야하므로 다른 곳의 0으로 다시 초기화되는 것으로 의심됩니다. – Shahbaz
while 루프에서는 피드백을 얻고 있습니다. 즉, 설정 점 (원하는 위치)이있는 경우, 해당 위치에 얼마나 가까이 있는지 기능이 무엇입니까? 우연히'odometry_goto_step (&og);') 우연히? og 구조체의 정의를 게시 할 수 있습니까? posx, posy와 같은 위치 변수가 있다고 가정합니다. 제안 사항을 확인하는 데 도움이 될 것 같습니까 – ryyker