【问题标题】:Adding delay to robot controller in webots在 webots 中为机器人控制器添加延迟
【发布时间】:2021-01-28 22:03:28
【问题描述】:

我正在使用 webbots 中的 UR3 执行拾取和放置任务。 我需要机器人去拾取位置,抓住物体(合上手指),然后去放置位置。类似于以下代码:

  while (wb_robot_step(TIME_STEP) != -1) {
   // 1. Go to Pick position
   for (i = 0; i < 6; ++i)
     wb_motor_set_position(ur_motors[i], pick_position[i]);                  

   // 2. Grasp the object
   for (i = 0; i < 2; ++i)
      wb_motor_set_position(finger_motors[i], 0.5);
        
   // 3. Go to Place position
   for (i = 0; i < 6; ++i)
     wb_motor_set_position(ur_motors[i], place_position[i]);                     
} 

但是,当我运行代码时,我看到当机器人要拾取位置时,手指也会闭合。我在文档中读到“wb_motor_set_position 函数存储新位置,但它不会立即启动电机”。所以我想知道如何在第 1 步和第 2 步之间添加延迟,即只有在电机驱动达到所需位置后手指才会闭合。我使用了 sleep 但没有帮助。

【问题讨论】:

    标签: webots


    【解决方案1】:

    有不同的可能性来实现你想要的。 一个简单的方法是引入一个时间计数器变量(您可能需要根据您的 TIME_STEP 调整 100 和 200 值):

      int counter = 0;
      while (wb_robot_step(TIME_STEP) != -1) {
       // 1. Go to Pick position
       if (counter == 0)
         for (i = 0; i < 6; ++i)
           wb_motor_set_position(ur_motors[i], pick_position[i]);                  
    
       // 2. Grasp the object
       else if (counter == 100)
         for (i = 0; i < 2; ++i)
            wb_motor_set_position(finger_motors[i], 0.5);
            
       // 3. Go to Place position
       else if (counter == 200)
         for (i = 0; i < 6; ++i)
           wb_motor_set_position(ur_motors[i], place_position[i]);                     
       counter++;
    }
    

    另一种可能性是使用wb_robot_get_time() 检索当前模拟时间(而不是counter 变量)并仅在达到特定时间时执行某些操作。

    最后,另一种可能性是仅在达到目标位置时(而不是在某个固定时间延迟之后)使用位置反馈来执行下一个动作(关闭夹具)。

    【讨论】:

    • 感谢@OlivierMichel,使用计数器解决了它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-10
    • 2023-03-26
    相关资源
    最近更新 更多