Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 代码不';t在循环内工作,但在循环外工作_Loops_Webots - Fatal编程技术网

Loops 代码不';t在循环内工作,但在循环外工作

Loops 代码不';t在循环内工作,但在循环外工作,loops,webots,Loops,Webots,我有一段代码显示了一些奇怪的行为。当代码不在for循环中时,它会像expecred一样工作,但一旦我将其放入for循环中,它就会一次又一次地重复相同的值 const double *north = cp->getValues(); angle1 = atan2(north[1], north[2]); bearing = (angle1 - 1.5708) / M_PI * 180.0; std::cout<<"Bearing inside : &qu

我有一段代码显示了一些奇怪的行为。当代码不在for循环中时,它会像expecred一样工作,但一旦我将其放入for循环中,它就会一次又一次地重复相同的值

  const double *north = cp->getValues();
  angle1 = atan2(north[1], north[2]);
  bearing = (angle1 - 1.5708) / M_PI * 180.0;
  std::cout<<"Bearing inside : "<<bearing<<std::endl;
  if (bearing < 0.0)
    bearing = bearing + 360.0;
  t = abs(bearing - turn);
constdouble*north=cp->getValues();
角度1=atan2(北[1],北[2]);
轴承=(角度1-1.5708)/M_PI*180.0;

std::cout您应该调用循环中的
步骤
方法:

深入解释
步骤
方法:

    for(int i=0;i<100;i++)
    {
      double t_modifier = (180.0 - abs(t)) / 180.0;
      double threshold = 2.0;
      double Speedleft = 1.0;
      double Speedright = 1.0;
      int identifier;
      if(int(t)<0){
        Speedleft = -1;
      }
      else if(int(t)>0){
        Speedright = -1;
      }
      leftSpeed = threshold * Speedleft;
      rightSpeed = threshold * Speedright;
      {
        wheels[0]->setVelocity(leftSpeed);
        wheels[1]->setVelocity(rightSpeed);
        wheels[2]->setVelocity(leftSpeed);
        wheels[3]->setVelocity(rightSpeed);
      }
      
      const double *north = cp->getValues();
      angle1 = atan2(north[1], north[2]);
      bearing = (angle1 - 1.5708) / M_PI * 180.0;
      std::cout<<"Bearing inside : "<<bearing<<std::endl;
      if (bearing < 0.0)
        bearing = bearing + 360.0;
      t = abs(bearing - turn);
    }