2013-11-04 2 views
2

차동 드라이브 모바일 로봇 (전자 퍽)을 프로그래밍하여 특정 방향으로 특정 좌표로 이동합니다. 로봇은 좌표에 도달하는 데 아무런 문제가 없습니다. 그러나 좌표에 도달하면 특정한 방향으로 정착 할 수없고 방향을 찾고있는 지점에서 "회전"을 유지할 수 없으므로 누구도이 사전 경험이 있습니까? 나는이 문제에 아주 오래 머물러 있으며, 왜 누군가가 그 이유를 알기를 바랍니다. 코드의 관련 부분이 아래에 붙여 넣어집니다.모바일 로봇 (전자 퍽) 프로그래밍 (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; 
} 
+1

관련성이있는 부작용으로 : 왜 'spee_left'와'speed_right'를 0으로 설정하고, 그들이 0인지 즉시 확인합니까? 어쨌든, 문제는'og.result.atgoal'의 계산과 같다. 로봇이 달성하기에 "너무 가깝다"라는 정의가 너무 정확하거나, 언제나 og.result.atgoal을 0으로 재설정하고 있습니다. 위에서 언급 한 'if'가 항상 true이기 때문에 'og.result.atgoal'은 항상 즉시 1이되어야하므로 다른 곳의 0으로 다시 초기화되는 것으로 의심됩니다. – Shahbaz

+0

while 루프에서는 피드백을 얻고 있습니다. 즉, 설정 점 (원하는 위치)이있는 경우, 해당 위치에 얼마나 가까이 있는지 기능이 무엇입니까? 우연히'odometry_goto_step (&og);') 우연히? og 구조체의 정의를 게시 할 수 있습니까? posx, posy와 같은 위치 변수가 있다고 가정합니다. 제안 사항을 확인하는 데 도움이 될 것 같습니까 – ryyker

답변

0

내가 지금 현재의 위치 정보를 제공하는 구성원이있는 가정, 당신의 og 구조체의 내용이 무엇인지을 알고 의 이익이없는, (나는 그들이 posx & posy입니다 가정합니다), 당신은해야

[편집] 재 위치 set_speed()

: 최신 위치, 이런 식으로 뭔가를 읽은 직후 테스트 문 언젠가이 있어야합니다
while (og.result.atgoal == 0) 
{ 
    // Update position and calculate new speeds 
    odometry_track_step(og.track); 
    odometry_goto_step(&og); 

    if(((og.result.posx - x) > 3) || (og.result.posy - y) > 3) //(distance assumed in mm) 
    { 
     //then report position, continue to make adjustments and navigate 
     printf("%f",ot.result.theta); 
     print_position(); 
     // Set the wheel speed 
     set_speed(og.result.speed_left, og.result.speed_right); 
     step(); 

    } 
    else 
    { 
      //set all speeds to 0 
      //report position.   
      //clear appropriate struct members and leave loop 
    } 

} //after exiting while loop speed will be zero 
0

나는 틀린 것을 마침내 알아 냈습니다. 왜냐하면 나는 while 루프에서 벗어날 수 없었고 로봇이 방향 검색을 멈출 수 없었기 때문입니다. 영감을 가져 주셔서 감사합니다.

+0

I 환영합니다! 귀하의 질문에 대한 추가 정보와 함께 원래의 게시물을 편집하는 것을 알고 있어야합니다. *** 자신의 질문에 대답 ***, 그러나 할 때 _ 그러나 _ 할 때 적합합니다. 질문을 끝내기 위해 답을 얻습니다. (원래의 포스터에만 표시되는 모든 대답 옆에 체크 표시 기호가 있으며,이 경우 귀하의 질문을 만족하는 대답을 표시하십시오) – ryyker