2013-11-04 143 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'设置为零,然后立即检查它们是否为零?无论如何,这个问题似乎是与'og.result.atgoal'的计算。无论您对“足够接近”的定义是否太精确,机器人都无法实现,或者有人将“og.result.atgoal”每次重置为零。由于我上面提到的'if'总是正确的,所以'og.result.atgoal'应该总是立即变为1,所以我高度怀疑它在其他地方被重新初始化为零。 – 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可以看到你是新来的,欢迎!在将来你应该知道编辑_original post_有关你的问题的其他信息,也适合于***回答你自己的问题***,但是当你do_时,标记它回答了关闭问题(在所有答案旁边有一个复选标记符号,仅对原始海报可见,请在这种情况下标记满足您问题的答案) – ryyker