当前位置:网站首页>[coppeliasim4.3] C calls UR5 in the remoteapi control scenario
[coppeliasim4.3] C calls UR5 in the remoteapi control scenario
2022-07-03 07:28:00 【Ten year dream laboratory】

Screenshot
Video demo
note :
One 、 Add code to the scenario script , Turn on the server :
function sysCall_init()
-- Start remote API server
local port=3000
simRemoteApi.start(port)
corout=coroutine.create(coroutineMain)
end Two 、C# The client connects to the server , And get the joint handle
_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));
}
}3、 ... and 、 Copy from the installation directory include and remoteApi To C# project , Generate dll、lib

Directory source location

Directory target location


Copy the generated library to C# Project compilation output directory
Four 、C# call C++ library
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);
}
} 5、 ... and 、 Move the manipulator and get the position
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
边栏推荐
- 不出网上线CS的各种姿势
- Common methods of file class
- The embodiment of generics in inheritance and wildcards
- Arduino 软串口通信 的几点体会
- [most detailed] latest and complete redis interview book (50)
- 带你全流程,全方位的了解属于测试的软件事故
- [solved] sqlexception: invalid value for getint() - 'Tian Peng‘
- PAT甲级真题1166
- Circuit, packet and message exchange
- 691. Cube IV
猜你喜欢
随机推荐
Advanced API (multithreading 02)
Logging log configuration of vertx
20220319
Advanced API (serialization & deserialization)
[set theory] order relation (partial order relation | partial order set | example of partial order set)
SecureCRT password to cancel session recording
IO stream system and FileReader, filewriter
Interview questions about producers and consumers (important)
SQL create temporary table
Lombok -- simplify code
docker建立mysql:5.7版本指定路径挂载不上。
II. D3.js draw a simple figure -- circle
Store WordPress media content on 4everland to complete decentralized storage
Warehouse database fields_ Summary of SQL problems in kingbase8 migration of Jincang database
OSI knowledge sorting
带你全流程,全方位的了解属于测试的软件事故
Summary of Arduino serial functions related to print read
Vertx's responsive redis client
How long is the fastest time you can develop data API? One minute is enough for me
Jeecg data button permission settings








