一、joint参数介绍
- Joint
图1
如图1所示:
- Pos.min:最小值,单位度。
- Pos.range:范围,单位度。
- Position:当期位置,单位度,范围为[Pos.min,Pos.min+Pos.range]。
- IK calculation weigit:
- Max.step size:
- Mode:
- length:joint的长度。
- Diameter:joint的直径。
- color:
- Common
图2
如图2所示:
- General properties(常规属性):
Selectable:可选
Invisible during selection:选择期间不可见
Select base of model instead:选择模型的基础
Ignored by depth pass:被深度传递忽略
Ignored by model bounding box:被模型边界框忽略
Ignored for view-fitting:忽略视图拟合
Cannot be deleted during simul:不能在模拟过程中删除
Cannot be deleted:无法删除 - Visibility(能见度):
Camera visibility layers:摄像头可见性层,第一层不打勾可以隐藏joint
Can be seen by: - Object special properties(对象特殊属性):
Collidable:可碰撞的
Measurable:可测量的
Detectable:可检测
Renderable:可渲染 - Model definition:
- Other:
- Joint dynamic properties
图3
打开方法:在图1中点击show dynamic properties dialog打开
如图3所示:
- Motor enabled:打开电机
- Target velocity:目标速度,电机最终将达到的速度。
- Maximum torque:扭矩,其越大,电机达到目标速度越快。
- Lock motor when target velocity is zero:如果目标速度为0,电机不能转动。
- Control loop enabled:可以控制转动
- Target position:目标角度,电机启动后将达到这个角度并维持。
- Upper velocity limit:速度上限
adww
- Model properties
图4
打开方法:在图二中选中Object is model base,点击Edit model properties打开
- Select model thumbnail:选择模型缩略图
- Override properties:覆盖参数
- Model is not visible:模型不可见
- Model is not collidable:模型不可碰撞
- Model is not measurable:模型不可测量
- Model is not renderable:模型不可渲染
- Model is not detectable:模型无法检测
- Model is not dynamic:模型不是动态的
- Model is not respondable:模型不响映
- Model scripts are inactive(child scripts and customization scripts):模型脚本处于非活动状态(子脚本和自定义脚本)
- Invisible to other model` s bounding boxes:对其他模型的边界框不可见
二、基块参数介绍
- Shape
图5
- Joint dynamic properties
图6
三、手臂控制
- 手臂关节
joint名称 | 作用 |
---|---|
LShoulderPitch3 | 大臂上下摆动 |
LShoulderRoll3 | 大臂左右摆动 |
LElbowYaw3 | 大臂旋转 |
LElbowRoll3 | 小臂摆动 |
Lwristyaw3 | 小臂旋转 |
- 控制函数
函数名称 | 作用 |
---|---|
sim.getObjectHandle | 获得joint的句柄(类似于文件句柄) |
sim.setJointTargetPosition | 设置joint的目标角度 |
详细的使用方法,参数,见官方文档
http://www.coppeliarobotics.com/helpFiles/en/apiFunctionListAlphabetical.htm
四、手指控制
- 参数调整
- 双击三个手指的第一个joint(即前面带的点符号的),打开图4所示的界面,取消它的dynamic和respondable选项,如果选中它们,手指就是静态的。
- 点击所有手指joint的show dynamic properties dialog按钮,打开图3所示的界面,设置Target velocity为0,设置Maximum torque为100,太小不能抵消重力的影响,选中Lock motor when target velocity is zero。
- 双击joint下面的正方体图标,打开所有手指的基块(即指节),如图5所示,单击show dynamic properties dialog按钮,打开图6所示的界面,点击M=M*2,将Mass值调大,最好是-2次方级别。
- 注意响应掩码的设置,相邻两个指节不能用相同的响应掩码,最好每个手指的所有指节选一个且都不同。
- 控制函数
函数名称 | 作用 |
---|---|
sim.getObjectHandle | 获得joint的句柄(类似于文件句柄) |
sim.setJointTargetVelocity | 设置joint的目标速度 |
详细的使用方法,参数,见官方文档
http://www.coppeliarobotics.com/helpFiles/en/apiFunctionListAlphabetical.htm
五、UI编写及设置
详细的使用方法,参数,见官方文档
UI控制函数:
http://www.coppeliarobotics.com/helpFiles/en/customUIPluginApi.htm
UI控制参数:
http://www.coppeliarobotics.com/helpFiles/en/customUIPluginXMLSyntax.htm
六、代码
在粘贴代码时,要删掉汉语注释,Vrep的lua不支持汉语。
lua语言的注释符,有两种,单行注释:–;多行注释:–[[…]]–
function sysCall_init()
nao=sim.getObjectHandle("NAO")
--Set deg
//每个关节的角度范围
minDeg={0,-math.pi,-math.pi/2,0}
maxDeg={math.pi/2,math.pi,math.pi/2,math.pi/2}
--left arm
lShoulderPitch3=sim.getObjectHandle("LShoulderPitch3")
lShoulderRoll3=sim.getObjectHandle("LShoulderRoll3")
lElbowYaw3=sim.getObjectHandle("LElbowYaw3")
lElbowRoll3=sim.getObjectHandle("LElbowRoll3")
--finger in left arm
--fist
//获取指节joint的句柄
lThumbBase=sim.getObjectHandle("NAO_LThumbBase")
lLFingerBase=sim.getObjectHandle("NAO_LLFingerBase")
lRFingerBase=sim.getObjectHandle("NAO_LRFingerBase")
--second
revolute_joint8=sim.getObjectHandle("Revolute_joint8")
revolute_joint12=sim.getObjectHandle("Revolute_joint12")
revolute_joint11=sim.getObjectHandle("Revolute_joint11")
--third
revolute_joint14=sim.getObjectHandle("Revolute_joint14")
revolute_joint13=sim.getObjectHandle("Revolute_joint13")
--right arm
rShoulderPitch3=sim.getObjectHandle("RShoulderPitch3")
rShoulderRoll3=sim.getObjectHandle("RShoulderRoll3")
rElbowYaw3=sim.getObjectHandle("RElbowYaw3")
rElbowRoll3=sim.getObjectHandle("RElbowRoll3")
naoName=sim.getObjectName(nao) //获得机器人的名字
// .. 是lua的链接字符串的语句;group是在一个界面内建立一块区域;label是设置名字;hslider是创建滑动条;button是设置按钮,参数text设置按钮上的提示文字,参数onclick可以指定button的运行函数。
//xml是成对存在的。
xml='<ui title="'..naoName..' Control Grasp" closeable="true" resizable="true" layout="vbox" >'..
[[
<group>
<label text="LElbowRoll3" wordwrap="true" />
<hslider minimum="0" maximum="100" id="1"/>
</group>
<group>
<label text="LElbowYaw3" wordwrap="true" />
<hslider minimum="0" maximum="100" id="2"/>
</group>
<group>
<label text="LShoulderPitch3" wordwrap="true" />
<hslider minimum="0" maximum="100" id="3"/>
</group>
<group>
<label text="LShoulderRoll3" wordwrap="true" />
<hslider tick-position="below" minimum="0" maximum="100" id="4"/>
</group>
<group>
<button text="grasp" onclick = "grasp" id="5"/>
</group>
<group>
<button text="release" onclick = "release" id="6"/>
</group>
</ui>
]]
ui=simUI.create(xml)//创建UI
simUI.setSliderValue(ui,1,0)//设置滑动条的初值,范围[0,100]
simUI.setSliderValue(ui,2,50)
simUI.setSliderValue(ui,3,50)-- 50=(100-0)/2
simUI.setSliderValue(ui,4,0)
end
function grasp(h)// button的外部函数,抓
grasp_flag=1
end
function release(h)// button的外部函数,放
grasp_flag=0
end
function sysCall_actuation()
--grasping=simUI.getWidgetVisibility(ui,5)
--[[if(grasping) then
sim.setJointTargetPosition(lThumbBase,0)
sim.setJointTargetPosition(lLFingerBase,20)
sim.setJointTargetPosition(lRFingerBase,30)
else
sim.setJointTargetPosition(lThumbBase,0)
sim.setJointTargetPosition(lLFingerBase,0)
sim.setJointTargetPosition(lRFingerBase,0)
end--]]
if(grasp_flag==1) then // 如果抓的按钮为真,我们给手指所有的joint传一个正目标速度,手指聚拢。
sim.setJointTargetVelocity(lThumbBase,0.2)
sim.setJointTargetVelocity(lLFingerBase,0.2)
sim.setJointTargetVelocity(lRFingerBase,0.2)
sim.setJointTargetVelocity(revolute_joint8,0.35)
sim.setJointTargetVelocity(revolute_joint12,0.2)
sim.setJointTargetVelocity(revolute_joint11,0.2)
sim.setJointTargetVelocity(revolute_joint14,0.2)
sim.setJointTargetVelocity(revolute_joint13,0.2)
elseif(grasp_flag==0) then // 如果放的按钮为真,我们给手指所有的joint传一个负目标速度,手指展开。
sim.setJointTargetVelocity(lThumbBase,-0.3)
sim.setJointTargetVelocity(lLFingerBase,-0.3)
sim.setJointTargetVelocity(lRFingerBase,-0.3)
sim.setJointTargetVelocity(revolute_joint8,-0.3)
sim.setJointTargetVelocity(revolute_joint12,-0.6)
sim.setJointTargetVelocity(revolute_joint11,-0.6)
sim.setJointTargetVelocity(revolute_joint14,-0.3)
sim.setJointTargetVelocity(revolute_joint13,-0.3)
else // 否则,手指速度设置为0,锁住。
sim.setJointTargetVelocity(lThumbBase,0)
sim.setJointTargetVelocity(lLFingerBase,0)
sim.setJointTargetVelocity(lRFingerBase,0)
sim.setJointTargetVelocity(revolute_joint8,0)
sim.setJointTargetVelocity(revolute_joint12,0)
sim.setJointTargetVelocity(revolute_joint11,0)
sim.setJointTargetVelocity(revolute_joint14,0)
sim.setJointTargetVelocity(revolute_joint13,0)
end
position=minDeg[1]+simUI.getSliderValue(ui,1)/100*(maxDeg[1]-minDeg[1]) // 获得滑动条的值,加以计算,求得对应的目标角度值。
sim.setJointTargetPosition(lElbowRoll3,-position)
position=minDeg[2]+simUI.getSliderValue(ui,2)/100*(maxDeg[2]-minDeg[2])
sim.setJointTargetPosition(lElbowYaw3,-position)
position=minDeg[3]+simUI.getSliderValue(ui,3)/100*(maxDeg[3]-minDeg[3])
sim.setJointTargetPosition(lShoulderPitch3,position)
position=minDeg[4]+simUI.getSliderValue(ui,4)/100*(maxDeg[4]-minDeg[4])
sim.setJointTargetPosition(lShoulderRoll3,position)
--if(simUI.getWidgetVisibility(ui,5)) then
--sim.setJointTargetVelocity(lThumbBase,1)
--end
end