当前位置:网站首页>【CoppeliaSim4.3】C#调用 remoteApi控制场景中UR5
【CoppeliaSim4.3】C#调用 remoteApi控制场景中UR5
2022-07-03 07:23:00 【十年一梦实验室】

截图
视频演示
笔记:
一、场景脚本中添加代码,开启服务器:
function sysCall_init()
-- Start remote API server
local port=3000
simRemoteApi.start(port)
corout=coroutine.create(coroutineMain)
end二、C#客户度连接服务器,并获取关节句柄
_id = Api.Connect(textBoxAddress.Text, (int)numericUpDownPort.Value);
if (Api.IsConnected(_id))
{
for (int i = 0; i < _jointHandle.Length; i++)
{
_jointHandle[i] = Api.GetObjectHandle(_id, _jointPrefix + (i + 1));
}
}三、从安装目录拷贝include和remoteApi到C#项目,生成dll、lib

目录源位置

目录目标位置


生成的库拷贝到C#项目编译输出目录
四、C#调用C++库
using System;
using System.Runtime.InteropServices;
namespace CoppeliaSimCSharpAPI.TestForm
{
internal class Api
{
[DllImport("CoppeliaSimCSharpAPI.dll")]
public static extern int Connect(string address, int port);
[DllImport("CoppeliaSimCSharpAPI.dll")]
public static extern int Disconnect(int id);
[DllImport("CoppeliaSimCSharpAPI.dll")]
public static extern bool IsConnected(int id);
[DllImport("CoppeliaSimCSharpAPI.dll")]
public static extern int GetJointPosition(int id, int[] jointHandle, float[] position, int jointCount);
[DllImport("CoppeliaSimCSharpAPI.dll")]
public static extern int GetObjectHandle(int id, string objectName);
[DllImport("CoppeliaSimCSharpAPI.dll")]
public static extern int MoveJoint(int id, int[] jointHandle, float[] position, bool inTorqueForceMode, int jointCount);
[DllImport("CoppeliaSimCSharpAPI.dll")]
public static extern int SendInfo(int id, string message, bool blocking);
}
}五、移动机械臂和获取位置
private void buttonMove_Click(object sender, EventArgs e)
{
var position = new float[]
{
(float)numericUpDownJ1.Value,
(float)numericUpDownJ2.Value,
(float)numericUpDownJ3.Value,
(float)numericUpDownJ4.Value,
(float)numericUpDownJ5.Value,
(float)numericUpDownJ6.Value
};
Api.MoveJoint(_id, _jointHandle, position, true, _jointHandle.Length);
}
private void buttonGetPosition_Click(object sender, EventArgs e)
{
var position = new float[6];
Api.GetJointPosition(_id, _jointHandle, position, _jointHandle.Length);
MessageBox.Show($"{position[0]}\r\n" +
$"{position[1]}\r\n" +
$"{position[2]}\r\n" +
$"{position[3]}\r\n" +
$"{position[4]}\r\n" +
$"{position[5]}",
"Now position");
}The End
边栏推荐
- [untitled]
- Jeecg data button permission settings
- MySQL mistakenly deleted the root account and failed to log in
- High concurrency memory pool
- Spa single page application
- Sorting, dichotomy
- Arduino 软串口通信 的几点体会
- Common APIs
- Final, override, polymorphism, abstraction, interface
- Common analysis with criteria method
猜你喜欢

Store WordPress media content on 4everland to complete decentralized storage

Arduino Serial系列函数 有关print read 的总结

Final, override, polymorphism, abstraction, interface

【已解决】Unknown error 1146

Flask Foundation
![[solved] sqlexception: invalid value for getint() - 'Tian Peng‘](/img/bf/f6310304d58d964b3d09a9d011ddb5.png)
[solved] sqlexception: invalid value for getint() - 'Tian Peng‘

Discussion on some problems of array
![[set theory] partition (partition | partition example | partition and equivalence relationship)](/img/f0/c3c82de52d563f3b81d731ba74e3a2.jpg)
[set theory] partition (partition | partition example | partition and equivalence relationship)

Circuit, packet and message exchange

Use of file class
随机推荐
HISAT2 - StringTie - DESeq2 pipeline 进行bulk RNA-seq
Selenium key knowledge explanation
Some basic operations of reflection
twenty million two hundred and twenty thousand three hundred and nineteen
Distributed ID
Common analysis with criteria method
Advanced API (UDP connection & map set & collection set)
Advanced APL (realize group chat room)
《指環王:力量之戒》新劇照 力量之戒鑄造者亮相
"Moss ma not found" solution
4everland: the Web3 Developer Center on IPFs has deployed more than 30000 dapps!
Sorting, dichotomy
Common architectures of IO streams
High concurrency memory pool
[cmake] cmake link SQLite Library
691. Cube IV
Custom generic structure
Understanding of class
C代码生产YUV420 planar格式文件
树莓派更新工具链