webots学习记录8:R2023b如何在某个零件上添加一个恒定的力(矩)

news/2024/9/25 13:21:03/


webots安装路径下,从include\controller\c\webots\supervisor.h中可以看到如下定义:

void wb_supervisor_node_add_force(WbNodeRef node, const double force[3], bool relative);
void wb_supervisor_node_add_force_with_offset(WbNodeRef node, const double force[3], const double offset[3], bool relative);
void wb_supervisor_node_add_torque(WbNodeRef node, const double torque[3], bool relative);

然而在include\controller\cpp\webots\Supervisor.hpp中却没有类似的定义,
在include\controller\cpp\webots\Node.hpp中才有类似定义:

void addForce(const double force[3], bool relative);
void addForceWithOffset(const double force[3], const double offset[3], bool relative);
void addTorque(const double torque[3], bool relative);

从include\controller\c\webots\types.h可以看到WbNodeRef的定义:

typedef struct WbNodeStructPrivate *WbNodeRef;

在https://github.com/cyberbotics/webots/blob/master/src/controller/c/supervisor.c中可以找到WbNodeStructPrivate的定义:

typedef struct WbNodeStructPrivate {int id;WbNodeType type;char *model_name;char *def_name;char *content;int parent_id;double *position;                                  // double[3]double *orientation;                               // double[9]double *center_of_mass;                            // double[3]WbNodeWbContactPointListStruct contact_points[2];  // 0 -> without descendants, 1 -> with descendantsbool contact_points_include_descendants;           // TODO: Delete with `wb_supervisor_node_get_contact_point`bool static_balance;double *solid_velocity;  // double[6] (linear[3] + angular[3])bool is_proto;bool is_proto_internal;  // FALSE if the node is visible in the scene tree, otherwise TRUEWbNodeRef parent_proto;int tag;WbNodeRef next;
} WbNodeStruct;

根据https://github.com/cyberbotics/webots/blob/master/docs/reference/supervisor.md中的说明:

The wb_supervisor_node_add_force function adds a force to the Solid node at its center of mass, the relative argument defines if the force is expressed in world coordinate system (relative set to false) or relatively to the node (relative set to true). The wb_supervisor_node_add_force_with_offset function adds a force to the Solid node at the location (expressed in the node coordinate system) defined by the offset argument. The wb_supervisor_node_add_torque function adds a torque to the Solid node.

注意要把Robot节点下面的Supervisor项由FALSE改为TRUE. 在某个零件上添加一个恒定的的示例代码如下:

webots::Supervisor* robot = webots::Supervisor::getSupervisorInstance();
webots::Node* BaseNode = robot->getFromDef("Base_link_00");
const double RopeForce[3] = { 500.0, 500.0, 500 };
const double RopeForceOffset[3] = { -30.0, 0.0, 0.0 };
//BaseNode->addForce(RopeForce, false);
BaseNode->addForceWithOffset(RopeForce, RopeForceOffset, false);

下面顺便提供用代码修改Robot的translation和rotation的方法,

webots::Supervisor* robot = webots::Supervisor::getSupervisorInstance();
webots::Node* robotNode = robot->getSelf();
webots::Field* translationField = robotNode->getField("translation");
webots::Field* rotationField = robotNode->getField("rotation");
const double translationArray[3] = {-39, 0, 0.9};
translationField->setSFVec3f(translationArray);
robot->step(32);
const double rotationArray[4] = {0.0, 1.0, 0.0, pi/2.0};
rotationField->setSFRotation(rotationArray);
robot->step(32);

参考链接:
https://stackoverflow.com/questions/66787530/apply-a-user-defined-force-on-a-solid-node-in-webots?


http://www.ppmy.cn/news/1427345.html

相关文章

2024第八届图像、信号处理和通信国际会议 (ICISPC 2024)即将召开!

2024第八届图像、信号处理和通信国际会议 (ICISPC 2024)将于2024年7月19-21日在日本福冈举行。启迪思维,引领未来,ICISPC 2024的召开,旨在全球专家学者共襄盛举,聚焦图像信号,在图像中寻找美&am…

【WPF】取色器-Color Extractor

【WPF】取色器 序实现HookScreen Colorlayout.CS预览下载序 取色器是一个非常实用的小工具,网上也很多可供下载使用。为什么已有却还是想要自己去实现一个呢?一方面是因为工具虽小但毕竟涉及到操作系统 API 的使用。另一方面想要在技术上精进一些。 实现 实现思路测试通过 Ho…

TypeScript中的模块是什么?

TypeScript中的模块是什么? 1. 模块的基本概念1.1 使用模块 2. 默认导出 vs 命名导出2.1 默认导出2.2 命名导出 3. 模块的作用域4. 模块的声明与引用 在现代软件开发中,模块化是构建大型、可维护应用程序的关键概念。TypeScript,作为JavaScri…

Matlab|【复现】主动配电网故障定位方法研究

目录 1 主要内容 算例模型 期望故障电流状态函数 评价函数(膨胀率函数) 算例验证方法 详实的文档说明 2 部分程序 3 程序结果 4 下载链接 1 主要内容 该程序方法复现了《基于改进多元宇宙算法的主动配电网故障定位方法研究》_郑聪,建…

【GitBlit】Windows搭建Git服务器详细教程

前言 如果公司或个人想在 Windows 环境下搭建私有的 Git 服务器,那么这个开源的 GitBlit 是一个不错的选择。 Gitblit 是一个开源纯 Java 的用于管理、查看和服务 Git 存储库。它是一个小型的托管集中式存储库工具。支持 SSH、HTTP 和 GIT 协议,开箱即…

【Redis】Hash数据类型

文章目录 常用命令hset & hgethexists & hdelhkeys & hvals & hgetallhlen & hmgethsetnxhincrby & hincrbyfloat 内部编码 Hash 相比于 string 而言可以节省很多个 key ,一个 key 里面又可以包含了多个 key-value 常用命令 hset & hg…

设计模式:状态模式示例

状态模式可以应用于多种场景,下面是一些示例及其代码实现: 1. 交通信号灯 交通信号灯(红灯、绿灯、黄灯)根据当前状态切换到下一个状态。 // 状态接口 interface TrafficLightState {void change(TrafficLight trafficLight); …

20240417,友元 FRIEND

本来要学习的吃瓜吃了一下午 目录 3.1 全局函数做友元 3.2 友元类 3.3 成员函数做友元 三&#xff0c;友元 3.1 全局函数做友元 #include<iostream> using namespace std; class Building {friend void goodGay(Building* building);//好朋友&#xff0c;可以访问…