[英]Creating delay between drone movements in Webots
I'm using Webots software to simulate a drone.我正在使用 Webots 软件来模拟无人机。 I want my drone to takeoff and after reaching the desired altitude, it will remain at that position for about 5 seconds before initiating some other moves automatically.
我想让我的无人机起飞,在达到所需高度后,它会在 position 停留大约 5 秒,然后自动开始其他一些动作。 I have tried to create that delay by using this code:`
我试图通过使用此代码来创建延迟:`
// Wait 5 seconds.
while (wb_robot_step(timestep) != -1) {
if (wb_robot_get_time() > 5.0)
break;
}`
but it only works when left outside the control loop, when I use it inside the control loop`, it affects the drone's performance, the drone gets unbalanced and flies wildly.但它只有在控制回路外才有效,当我在控制回路内使用它时,它会影响无人机的性能,无人机会失去平衡并疯狂飞行。 So can anyone tell me where I went wrong and if I want to create a delay between drone movements, what should I do?
那么谁能告诉我我哪里出错了,如果我想在无人机移动之间创建延迟,我应该怎么做? This is the code for movements that I have tried so far:
这是我到目前为止尝试过的动作代码:
// Actuate the motors taking into consideration all the computed inputs.
double front_left_motor_input = k_vertical_thrust + vertical_input - roll_input - pitch_input +
yaw_input;
double front_right_motor_input = k_vertical_thrust + vertical_input + roll_input - pitch_input -
yaw_input;
double rear_left_motor_input = k_vertical_thrust + vertical_input - roll_input + pitch_input -
yaw_input;
double rear_right_motor_input = k_vertical_thrust + vertical_input + roll_input + pitch_input +
yaw_input;
wb_motor_set_velocity(front_left_motor, front_left_motor_input);
wb_motor_set_velocity(front_right_motor, -front_right_motor_input);
wb_motor_set_velocity(rear_left_motor, -rear_left_motor_input);
wb_motor_set_velocity(rear_right_motor, rear_right_motor_input);
// Wait 5 seconds.
while (wb_robot_step(timestep) != -1) {
if (wb_robot_get_time() > 5.0)
break;
}
// Actuate the motors taking into consideration all the computed inputs. 2
for (double i=-1.5;i<1;i+=0.5){
if(i<0)
roll_input = k_roll_p * CLAMP(roll, -1.0, 1.0) + roll_acceleration +i ;
else
pitch_input = k_pitch_p * CLAMP(pitch, -1.0, 1.0) - pitch_acceleration +i ;
front_left_motor_input = k_vertical_thrust + vertical_input - roll_input -pitch_input + yaw_input;
front_right_motor_input = k_vertical_thrust + vertical_input + roll_input-pitch_input - yaw_input;
rear_left_motor_input = k_vertical_thrust + vertical_input - roll_input + pitch_input - yaw_input;
rear_right_motor_input = k_vertical_thrust + vertical_input + roll_input + pitch_input + yaw_input;
wb_motor_set_velocity(front_left_motor, front_left_motor_input);
wb_motor_set_velocity(front_right_motor, -front_right_motor_input);
wb_motor_set_velocity(rear_left_motor, -rear_left_motor_input);
wb_motor_set_velocity(rear_right_motor, rear_right_motor_input);}
I don't know the value of your time_step
variable, but assuming it's 10, why can't you simply call wb_robot_step(500 * time_step);
我不知道你的
time_step
变量的值,但假设它是 10,你为什么不能简单地调用wb_robot_step(500 * time_step);
? ? That's way simpler.
这样就简单多了。 Now, regarding the behavior of the drone, the commands send previously will continue to be applied during the waiting period, this may be the cause of the instabilities.
现在,关于无人机的行为,之前发送的命令将在等待期间继续应用,这可能是不稳定的原因。 Maybe you should consider changing these velocity commands (reset them to 0?) before entering the waiting period.
也许您应该考虑在进入等待期之前更改这些速度命令(将它们重置为 0?)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.