在Webots中进行机器人建模的过程

以最简单的四轮小车为例:

1. 添加Robot节点;

2. 在Robot节点下children里添加Group节点,将该Group命名为body;

3. 在该Group节点下children里添加Shape节点,在Shape节点中绘制机器人身体(主要是编辑appearance和geometry);

4. 回到Robot节点下的Bounding Object,USE body(很重要),此时边缘出现白线;同时设置physics节点,质量设为-1;

5. 在Robot节点下children里添加HingeJoint节点,对endPoint进行设置并在device下添加RotationalMotor并命名为motor_lf;由于该轮旋转中心即为形心,需将jointParameters下的anchor值设置成与endPoint下的translation值相同;

6. 通过Wizards添加controller,命名为wheel,添加如下代码编译,并将小车调整至合适位置进行测试;

/*
 * File:          wheel.c
 * Date:
 * Description:
 * Author:
 * Modifications:
 */

/*includes*/
#include <stdio.h>

#include <webots/robot.h>
#include <webots/motor.h>
#include <webots/position_sensor.h>
/*defines*/
static int time_step;   //仿真步长(毫秒)

/*main*/
int main(int argc, char **argv) {
    /*initialize*/
    wb_robot_init();
    time_step = wb_robot_get_basic_time_step();
    /*get devices*/
    WbDeviceTag motor;
    motor=wb_robot_get_device("motor_lf");
    wb_motor_set_position(motor,INFINITY);
    wb_motor_set_velocity(motor,3);
    
    /*main loop*/
    while (wb_robot_step(time_step) != -1) 
    {
      /*read sensor, process data, and actuate*/
    };
    /*finalize*/
    wb_robot_cleanup();

    return 0;
}

 7. 用相同方式对其他车轮进行建模(可直接复制粘贴),注意修改旋转中心anchor和电机传感器的name;

 

 8. 修改controller的代码,将小车调整至合适位置进行测试。

/*
 * File:          rover_ctrl.c
 * Date:
 * Description:
 * Author:
 * Modifications:
 */

/*includes*/
#include <stdio.h>

#include <webots/robot.h>
#include <webots/motor.h>
#include <webots/position_sensor.h>
/*defines*/
static int time_step;   //仿真步长(毫秒)

/*main*/
int main(int argc, char **argv) {
    /*initialize*/
    wb_robot_init();
    time_step = wb_robot_get_basic_time_step();
    /*get devices*/
    WbDeviceTag motors[4];
    char motor_names[4][12]={"motor_lf","motor_rf","motor_lh","motor_rh"};
    for (int i=0 ; i< 4 ; i++)
    {
        motors[i]=wb_robot_get_device(motor_names[i]);
        wb_motor_set_position(motors[i],INFINITY);
        wb_motor_set_velocity(motors[i],3);
    }
    
    /*main loop*/
    while (wb_robot_step(time_step) != -1) 
    {
      /*read sensor, process data, and actuate*/
    };
    /*finalize*/
    wb_robot_cleanup();

    return 0;
}

 

 建模完成。

参考文章:

Webots建模指南2 - 机器人建模 - 古月居

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值