Torque or force mode: in this mode, the joint is simulated by the dynamics module, if and only if it is dynamically enabled. When dynamically enabled, a joint can be free or controlled in Force/torque, in velocity or in position.

  The differentiation comes from the fact that a joint that operates in force/torque mode will be handled by the physics engine. And the physics engine will perform by default 10 times more calculation steps than the simulation loop: the simulation loop runs at 20Hz (in simulation time), while the physics engine runs at 200Hz (also in simulation time). That default behaviour can entirely be configured if required。If the joint is not in force/torque mode: if the joint is not in force/torque mode, then you can directly (and instantaneously) set its position via the simSetJointPosition API function.

  建立如下图所示的旋转模型:

  在转动关节的Joint Dynamic Properties对话框中勾选Control loop enable选项可以进行关节的位置控制(默认使用内置的PID控制器)。Target position为设定的目标位置(角度),Upper velocity limit为关节运动过程中允许的最大角速度,如果超过这个角速度则被限制为该值。

  PID控制器将比例、积分、微分通过线性组合构成控制量,动态方程为:

  PID控制器的离散化表达式为:

$$u(k)=K_pe(k)+K_iTe(k)+\frac{K_d}{T}[e(k)-e(k-1)]$$

  式中,T为采样周期,k为采样序号,Kp为比例系数,Ki为积分系数,Kd为微分系数

  比例控制能提高系统的动态响应速度,迅速反应误差,从而减小误差,但比例控制不能消除稳态误差。$K_p$的加大,会引起系统的不稳定;积分控制的作用是消除稳态误差,因为系统只要存在误差,积分作用就不断地积累,输出控制量,直到偏差为零,积分作用才会停止。但积分作用太强会使系统超调加大,甚至使系统出现振荡。微分作用可以在产生误差之前一发现有产生误差的趋势就开始调节,提前进行控制,所以及时性更好,可以最大限度地减少动态误差。但微分作用只能作为比例和积分控制的一种补充,不能起主导作用,微分作用太强也会使系统出现不稳定,微分作用只能在P和I调好后再由小往大调,一点一点试着加上去。

  下面设10°为期望位置,PID参数设为0.1, 2, 0,仿真1s关节角度曲线如下图所示:

  可以试着改变参数看看不同的效果,下图是使用默认参数0.1,0,0,即只使用比例控制的结果。可以看出增大积分项确实会引起超调

  将比例系数设为1后结果如下图,可以看出到达目标位置的时间比Kp=0.1时要快很多,可以看出增大比例系数可以加快响应速度。


  如果勾选Custom control选项,关节就会按照joint control callback script中用户编写的控制规律进行控制。This allows the user to write very specific joint controllers, that will be executed at each physics engine simulation step.

  callback script脚本通常用于一些底层控制,VREP中分为3种:

  • the contact callback script: the contact callback script lets you handle in a customized way each dynamic contact generated by the physics engine when two respondable objects collide.
  • joint control callback scripts: a joint control callback script lets you write customized low-level controllers for joints that are dynamically enabled.
  • the general callback script: each scene can have a general callback script that will be in charge of handling multi-purpose callback calls.

  这些脚本有如下特点:

  • a callback script always runs non-threaded.
  • a callback script might be called more than once for each simulation step.
  • a callback script handles low-level control items that the user wishes to customize. They should execute as quickly as possible, to avoid slowing down a simulation (this is particularly true for the contact callback script).

  Joint control callback scripts, which are simulation scripts, can be enabled via the joint dynamics properties dialog. When enabled for a given joint (that must be dynamically enabled), then the physics engine will call the callback script with appropriate arguments, allowing the user to customize the control loop of the related joint in order to write low-level control algorithms for specific joints. The joint control callback script might be called quite often, normally 10 times per simulation step for a given joint (remember that the physics engine time step, by default, is 10 times smaller that the simulation time step). For that reason, keep things simple, in order to avoid slowing down the simulation. Following represents a simple PID joint control callback script:

  打开关节控制脚本,默认进行PID控制,我们可以根据需要进行修改。代码中pidCumulativeErrorForIntegralParam变量用于存储积分项的累加值,如果是第一次调用控制脚本(init值为true)则将其初始化为0;dynStepSize与上面公式中的采样周期T意义相同;用于计算控制量的误差errorValue=targetPos-currentPos,那么与PID参数相乘后得到的控制量ctrl为位置量,如果要控制速度来使关节达到目标位置,则应施加的速度控制量为:velocityToApply=ctrl/dynStepSize

-- This example script performs a PID control
-- Be very careful when calling V-REP API functions from here:
-- 1. This routine gets called often, so it might slow down simulation (this is called at each dynamic simulation step, by default 10x more often than a child script)
-- 2. Some API functions are not meant to be called from here -- Following data is handed over from V-REP:
init,revolute,cyclic,jointHandle,passCnt,totalPasses,currentPos,targetPos,errorValue,effort,dynStepSize,lowLimit,highLimit,targetVel,maxForceTorque,velUpperLimit=... -- init: true when this callback is called for the first time (if the joint is dynamically reset during the simulation, this might be true more often)
-- revolute: true if the joint is revolute
-- cyclic: true if the joint is revolute and cyclic (i.e. no lower/upper limits)
-- passCnt: the current dynamics calculation pass. 0-9 by default. See next item for details.
-- totalPasses: the number of dynamics calculation passes for each "regular" simulation pass. 10 by default (i.e. 10*5ms=50ms which is the default simulation time step)
-- currentPos: the current position of the joint
-- targetPos: the desired position of the joint
-- errorValue: targetPos-currentPos (with revolute cyclic joints we take the shortest cyclic distance)
-- effort: the last force or torque that acted on this joint along/around its axis. With Bullet, torques from joint limits are not taken into account
-- dynStepSize: the step size used for the dynamics calculations (by default 5ms)
-- lowLimit: the joint lower limit
-- highLimit: the joint upper limit
-- targetVel: the joint target velocity (as set in the user interface)
-- maxForceTorque: the joint maximum force/torque (as set in the user interface)
-- velUpperLimit: the joint velocity upper limit (as set in the user interface) -- The control happens here:
-- 1. PID parameter def:
if not PID_P then
PID_P=0.1
PID_I=
PID_D=
end
-- 2. Clear some values when the dynamic joint calls this the first time (this can happen several times, if the joint is reset dynamically):
if init then
pidCumulativeErrorForIntegralParam=
end
-- 3. Proportional part:
ctrl=errorValue*PID_P
-- 4. Integral part:
if PID_I~= then
pidCumulativeErrorForIntegralParam=pidCumulativeErrorForIntegralParam+errorValue*dynStepSize
else
pidCumulativeErrorForIntegralParam=
end
ctrl=ctrl+pidCumulativeErrorForIntegralParam*PID_I
-- 5. Derivative part:
if not init then
ctrl=ctrl+(errorValue-pidLastErrorForDerivativeParam)*PID_D/dynStepSize
end
pidLastErrorForDerivativeParam=errorValue
-- 6. Calculate the velocity needed to reach the position in one dynamic time step:
velocityToApply=ctrl/dynStepSize
if (velocityToApply>velUpperLimit) then
velocityToApply=velUpperLimit
end
if (velocityToApply<-velUpperLimit) then
velocityToApply=-velUpperLimit
end
forceOrTorqueToApply=maxForceTorque -- Following data must be returned to V-REP:
return forceOrTorqueToApply,velocityToApply -- forceOrTorqueToApply: the maximum force/torque that the joint will be able to exert
-- velocityToApply: the velocity to apply to the joint.

  注意Lua函数可以接受可变数目的参数,在函数参数列表中使用三点(...)表示函数有可变的参数。

V-rep学习笔记:转动关节2的更多相关文章

  1. R语言与机器学习学习笔记

    人工神经网络(ANN),简称神经网络,是一种模仿生物神经网络的结构和功能的数学模型或计算模型.神经网络由大量的人工神经元联结进行计算.大多数情况下人工神经网络能在外界信息的基础上改变内部结构,是一种自 ...

  2. 蒟蒻的长链剖分学习笔记(例题:HOTEL加强版、重建计划)

    长链剖分学习笔记 说到树的链剖,大多数人都会首先想到重链剖分.的确,目前重链剖分在OI中有更加多样化的应用,但它大多时候是替代不了长链剖分的. 重链剖分是把size最大的儿子当成重儿子,顾名思义长链剖 ...

  3. KD-Tree 学习笔记

    这是一篇又长又烂的学习笔记,请做好及时退出的准备. KD-Tree 的复杂度大概是 \(O(n^{1-\frac{1}{k}})\) \(k\) 是维度 由于网上找不到靠谱的证明,咕了. 会证明之后再 ...

  4. 「学习笔记」FFT 快速傅里叶变换

    目录 「学习笔记」FFT 快速傅里叶变换 啥是 FFT 呀?它可以干什么? 必备芝士 点值表示 复数 傅立叶正变换 傅里叶逆变换 FFT 的代码实现 还会有的 NTT 和三模数 NTT... 「学习笔 ...

  5. CF1147F Zigzag Game & 稳定婚姻问题学习笔记

    CF1147F Zigzag Game 这题太神仙了,不得不记录一下. 我网络流做不动了,DS做不动了,DP做不动了,特别自闭.于是博弈论之神(就是随手切3500博弈的那种) \(\color{bla ...

  6. DirectX Graphics Infrastructure(DXGI):最佳范例 学习笔记

    今天要学习的这篇文章写的算是比较早的了,大概在DX11时代就写好了,当时龙书11版看得很潦草,并没有注意这篇文章,现在看12,觉得是跳不过去的一篇文章,地址如下: https://msdn.micro ...

  7. Sass学习笔记之入门篇

    Sass又名SCSS,是CSS预处理器之一,,它能用来清晰地.结构化地描述文件样式,有着比普通 CSS 更加强大的功能. Sass 能够提供更简洁.更优雅的语法,同时提供多种功能来创建可维护和管理的样 ...

  8. react-native学习笔记--史上最详细Windows版本搭建安装React Native环境配置

    参考:http://www.lcode.org/react-native/ React native中文网:http://reactnative.cn/docs/0.23/android-setup. ...

  9. swift学习笔记5——其它部分(自动引用计数、错误处理、泛型...)

    之前学习swift时的个人笔记,根据github:the-swift-programming-language-in-chinese学习.总结,将重要的内容提取,加以理解后整理为学习笔记,方便以后查询 ...

  10. Oracle学习笔记三 SQL命令

    SQL简介 SQL 支持下列类别的命令: 1.数据定义语言(DDL) 2.数据操纵语言(DML) 3.事务控制语言(TCL) 4.数据控制语言(DCL)  

随机推荐

  1. 步步为营-71-asp.net的简单练习(图片处理)

    1 原有图片添加水印 1.1 封装一个类,用于获取文件路径 using System; using System.Collections.Generic; using System.IO; using ...

  2. CentOS6.8安装360 pika

    1.安装依赖包 yum install snappy-devel bz2 libzip-dev libsnappy-dev libprotobuf-dev libevent-dev protobuf- ...

  3. Python contains

    一.__contains__ 判断字符串中是否包含相应的字符.

  4. 【Java】 剑指offer(61) 扑克牌的顺子

      本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集   题目 从扑克牌中随机抽5张牌,判断是不是一个顺子,即这5张牌是不是连 ...

  5. 098实战 Job的调度

    一:介绍 1.job调度 容量调度:Apache Hadoop的默认方式 公平调度:CDH版本的Hadoop的默认方式 2.公平调度 是一种资源分配方式,在yarn的整个生命周期中,所有的applic ...

  6. AngularJS表格神器“ui-grid”的应用

    HTML:  (代码仅用于解释得更清楚,并未完全展示) <!doctype html> <html ng-app="app"> <head> & ...

  7. FSMN结构快速解读

    参考文献如下: (1) Feedforward Sequential Memory Neural Networks without Recurrent Feedback (2) Feedforward ...

  8. js类型判断-丰富加好用

    一, 自己有时候写一些东西,要做类型判断,还有测试的时候,对于原生的和jQuery中的类型判断,实在不敢恭维,所以就写了一个好用的类型判断,一般情况都够用的. function test(type) ...

  9. anaconda3下配置python-3.5+tensorflow-gpu-1.9.0人脸识别项目环境

    https://www.cnblogs.com/31415926535x/p/10620732.html 之前为了配置tensorflow-gpu的环境又是装cuda,又是装cudnn,还有tenso ...

  10. Struts2 架构图

    Struts2架构图 请求首先通过Filter chain,Filter主要包括ActionContextCleanUp,它主要清理当前线程的ActionContext和Dispatcher:Filt ...