E-puck2-webots下的仿真实现

2023-10-11 04:59
文章标签 实现 仿真 webots puck2

本文主要是介绍E-puck2-webots下的仿真实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Webots是专业的移动机器人仿真软件包。它提供了快速的原型制作环境,使用户可以创建具有物理特性(例如质量,关节,摩擦系数等)的3D虚拟世界。用户可以添加简单的被动对象或称为移动机器人的主动对象。这些机器人可以具有不同的移动方案(轮式机器人,有腿机器人或飞行机器人)。此外,它们可能配备有许多传感器和执行器设备,例如距离传感器,驱动轮,摄像机,马达,触摸传感器,发射器,接收器等。最后,用户可以对每个机器人进行单独编程以表现出所需的行为。Webots包含大量机器人模型和控制器程序示例,以帮助用户入门。

Webots还包含许多与真实移动机器人的接口,因此,一旦您模拟的机器人表现出预期的行为,您就可以将其控制程序转移到诸如e-puck,DARwIn-OP,Nao等真实机器人上。可以添加新接口通过相关系统。
在这里插入图片描述

什么是世界?

Webots中的世界是对机器人及其环境的属性的3D描述。它包含对每个对象的描述:位置,方向,几何形状,外观(如颜色或亮度),物理属性,对象类型等。世界组织为层次结构,其中对象可以包含其他对象(例如VRML97)。例如,一个机器人可以包含两个轮子,一个距离传感器和一个关节,该关节本身包含一个摄像头等。世界文件不包含机器人的控制器代码;它仅指定每个机器人所需的控制器名称。世界保存在“ .wbt”文件中。“ .wbt”文件存储在每个Webots项目的“ worlds”子目录中。
在这里插入图片描述
在这里插入图片描述

什么是控制器?

控制器是控制世界文件中指定的机器人的计算机程序。可以使用Webots支持的任何编程语言编写控制器:C,C ++,Java,Python或MATLAB。当模拟开始时,Webots将启动指定的控制器,每个控制器都是一个单独的进程,并将控制器进程与模拟的机器人相关联。请注意,多个机器人可以使用相同的控制器代码,但是将为每个机器人启动一个不同的过程。

一些编程语言需要编译(C和C ++),其他语言需要解释(Python和MATLAB),而另一些则需要同时进行编译和解释(Java)。例如,C和C ++控制器被编译为平台相关的二进制可执行文件(例如Windows下的“ .exe”)。Python和MATLAB控制器由相应的运行时系统(必须安装)解释。Java控制器需要编译为字节码(“ .class”文件或“ .jar”),然后由Java虚拟机进行解释。

每个控制器的源文件和二进制文件一起存储在控制器目录中。控制器目录放置在每个Webots项目的“ controllers”子目录中。

在这里插入图片描述

/** Copyright 1996-2019 Cyberbotics Ltd.** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/#include <stdio.h>
#include <string.h>#include <webots/accelerometer.h>
#include <webots/camera.h>
#include <webots/distance_sensor.h>
#include <webots/light_sensor.h>
#include <webots/motor.h>
#include <webots/position_sensor.h>
#include <webots/robot.h>#define WHEEL_RADIUS 0.02
#define AXLE_LENGTH 0.052
#define RANGE (1024 / 2)static void compute_odometry(WbDeviceTag left_position_sensor, WbDeviceTag right_position_sensor) {double l = wb_position_sensor_get_value(left_position_sensor);double r = wb_position_sensor_get_value(right_position_sensor);double dl = l * WHEEL_RADIUS;         // distance covered by left wheel in meterdouble dr = r * WHEEL_RADIUS;         // distance covered by right wheel in meterdouble da = (dr - dl) / AXLE_LENGTH;  // delta orientationprintf("estimated distance covered by left wheel: %g m.\n", dl);printf("estimated distance covered by right wheel: %g m.\n", dr);printf("estimated change of orientation: %g rad.\n", da);
}int main(int argc, char *argv[]) {/* define variables */WbDeviceTag distance_sensor[8], left_motor, right_motor, left_position_sensor, right_position_sensor;int i, j;double speed[2];double sensors_value[8];double braitenberg_coefficients[8][2] = {{0.942, -0.22}, {0.63, -0.1}, {0.5, -0.06},  {-0.06, -0.06},{-0.06, -0.06}, {-0.06, 0.5}, {-0.19, 0.63}, {-0.13, 0.942}};int time_step;int camera_time_step;/* initialize Webots */wb_robot_init();if (strcmp(wb_robot_get_model(), "GCtronic e-puck2") == 0) {printf("e-puck2 robot\n");time_step = 64;camera_time_step = 64;} else {  // original e-puckprintf("e-puck robot\n");time_step = 256;camera_time_step = 1024;}/* get and enable the camera and accelerometer */WbDeviceTag camera = wb_robot_get_device("camera");wb_camera_enable(camera, camera_time_step);WbDeviceTag accelerometer = wb_robot_get_device("accelerometer");wb_accelerometer_enable(accelerometer, time_step);/* get a handler to the motors and set target position to infinity (speed control). */left_motor = wb_robot_get_device("left wheel motor");right_motor = wb_robot_get_device("right wheel motor");wb_motor_set_position(left_motor, INFINITY);wb_motor_set_position(right_motor, INFINITY);wb_motor_set_velocity(left_motor, 0.0);wb_motor_set_velocity(right_motor, 0.0);/* get a handler to the position sensors and enable them. */left_position_sensor = wb_robot_get_device("left wheel sensor");right_position_sensor = wb_robot_get_device("right wheel sensor");wb_position_sensor_enable(left_position_sensor, time_step);wb_position_sensor_enable(right_position_sensor, time_step);for (i = 0; i < 8; i++) {char device_name[4];/* get distance sensors */sprintf(device_name, "ps%d", i);distance_sensor[i] = wb_robot_get_device(device_name);wb_distance_sensor_enable(distance_sensor[i], time_step);}/* main loop */while (wb_robot_step(time_step) != -1) {/* get sensors values */for (i = 0; i < 8; i++)sensors_value[i] = wb_distance_sensor_get_value(distance_sensor[i]);const double *a = wb_accelerometer_get_values(accelerometer);printf("accelerometer values = %0.2f %0.2f %0.2f\n", a[0], a[1], a[2]);/* compute odometry and speed values*/compute_odometry(left_position_sensor, right_position_sensor);for (i = 0; i < 2; i++) {speed[i] = 0.0;for (j = 0; j < 8; j++)speed[i] += braitenberg_coefficients[j][i] * (1.0 - (sensors_value[j] / RANGE));}/* set speed values */wb_motor_set_velocity(left_motor, speed[0]);wb_motor_set_velocity(right_motor, speed[1]);}wb_robot_cleanup();return 0;
}

这篇关于E-puck2-webots下的仿真实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/185691

相关文章

分布式锁在Spring Boot应用中的实现过程

《分布式锁在SpringBoot应用中的实现过程》文章介绍在SpringBoot中通过自定义Lock注解、LockAspect切面和RedisLockUtils工具类实现分布式锁,确保多实例并发操作... 目录Lock注解LockASPect切面RedisLockUtils工具类总结在现代微服务架构中,分布

Java使用Thumbnailator库实现图片处理与压缩功能

《Java使用Thumbnailator库实现图片处理与压缩功能》Thumbnailator是高性能Java图像处理库,支持缩放、旋转、水印添加、裁剪及格式转换,提供易用API和性能优化,适合Web应... 目录1. 图片处理库Thumbnailator介绍2. 基本和指定大小图片缩放功能2.1 图片缩放的

Python使用Tenacity一行代码实现自动重试详解

《Python使用Tenacity一行代码实现自动重试详解》tenacity是一个专为Python设计的通用重试库,它的核心理念就是用简单、清晰的方式,为任何可能失败的操作添加重试能力,下面我们就来看... 目录一切始于一个简单的 API 调用Tenacity 入门:一行代码实现优雅重试精细控制:让重试按我

Redis客户端连接机制的实现方案

《Redis客户端连接机制的实现方案》本文主要介绍了Redis客户端连接机制的实现方案,包括事件驱动模型、非阻塞I/O处理、连接池应用及配置优化,具有一定的参考价值,感兴趣的可以了解一下... 目录1. Redis连接模型概述2. 连接建立过程详解2.1 连php接初始化流程2.2 关键配置参数3. 最大连

Python实现网格交易策略的过程

《Python实现网格交易策略的过程》本文讲解Python网格交易策略,利用ccxt获取加密货币数据及backtrader回测,通过设定网格节点,低买高卖获利,适合震荡行情,下面跟我一起看看我们的第一... 网格交易是一种经典的量化交易策略,其核心思想是在价格上下预设多个“网格”,当价格触发特定网格时执行买

python设置环境变量路径实现过程

《python设置环境变量路径实现过程》本文介绍设置Python路径的多种方法:临时设置(Windows用`set`,Linux/macOS用`export`)、永久设置(系统属性或shell配置文件... 目录设置python路径的方法临时设置环境变量(适用于当前会话)永久设置环境变量(Windows系统

Python对接支付宝支付之使用AliPay实现的详细操作指南

《Python对接支付宝支付之使用AliPay实现的详细操作指南》支付宝没有提供PythonSDK,但是强大的github就有提供python-alipay-sdk,封装里很多复杂操作,使用这个我们就... 目录一、引言二、准备工作2.1 支付宝开放平台入驻与应用创建2.2 密钥生成与配置2.3 安装ali

Spring Security 单点登录与自动登录机制的实现原理

《SpringSecurity单点登录与自动登录机制的实现原理》本文探讨SpringSecurity实现单点登录(SSO)与自动登录机制,涵盖JWT跨系统认证、RememberMe持久化Token... 目录一、核心概念解析1.1 单点登录(SSO)1.2 自动登录(Remember Me)二、代码分析三、

PyCharm中配置PyQt的实现步骤

《PyCharm中配置PyQt的实现步骤》PyCharm是JetBrains推出的一款强大的PythonIDE,结合PyQt可以进行pythion高效开发桌面GUI应用程序,本文就来介绍一下PyCha... 目录1. 安装China编程PyQt1.PyQt 核心组件2. 基础 PyQt 应用程序结构3. 使用 Q

Python实现批量提取BLF文件时间戳

《Python实现批量提取BLF文件时间戳》BLF(BinaryLoggingFormat)作为Vector公司推出的CAN总线数据记录格式,被广泛用于存储车辆通信数据,本文将使用Python轻松提取... 目录一、为什么需要批量处理 BLF 文件二、核心代码解析:从文件遍历到数据导出1. 环境准备与依赖库