// Copyright SJTU
// author Li Wang 05liwang@sjtu.edu.cn 935342669@qq.com
// this file is used to wrap the legacy remote API of CoppeliaSim
#include "pch.h"
#include "Coppelia.h"
Coppelia::Coppelia() {}
Coppelia::~Coppelia() {}
/***************************************************************************************
Starts a communication thread with the server (i.e. CoppeliaSim). A same
client may start several communication threads (but only one communication
thread for a given IP and port). This should be the very first remote API
function called on the client side. Make sure to start an appropriate remote
API server service on the server side, that will wait for a connection.
port_number: the port number where to connect. Specify a negative port number
in order to use shared memory, instead of socket communication.
wait_until_connected: if different from zero, then the function blocks until
connected (or timed out).
doNotReconnectOnceDisconnected: if different from zero, then the
communication thread will not attempt a second connection if a connection was
lost. timeOutInMs: if positive: the connection time-out in milliseconds for
the first connection attempt. In that case, the time-out for blocking function
calls is 5000 milliseconds. if negative: its positive value is the time-out
for blocking function calls. In that case, the connection time-out for the
first connection attempt is 5000 milliseconds. commThreadCycleInMs: indicates
how often data packets are sent back and forth. Reducing this number improves
responsiveness, and a default value of 5 is recommended. return value the
client ID, or -1 if the connection to the server was not possible (i.e. a
timeout was reached). A call to simxStart should always be followed at the end
with a call to simxFinish if simxStart didn't return -1
****************************************************************************************/
int Coppelia::ConnectCoppeliaSim(int port_number, bool wait_until_connected,
bool do_not_reconnect_once_disconnected,
int time_out_in_ms,
int commthread_cycle_in_ms) {
this->client_ID_ = simxStart("127.0.0.1", port_number, wait_until_connected,
do_not_reconnect_once_disconnected,
time_out_in_ms, commthread_cycle_in_ms);
return this->client_ID_;
}
/***************************************************************************************
Ends the communication thread. This should be the very last remote API
function called on the client side. simxFinish should only be called after a
successfull call to simxStart.
****************************************************************************************/
void Coppelia::DisconnectCoppeliasSim() { simxFinish(this->client_ID_); }
/***************************************************************************************
Requests a start of a simulation (or a resume of a paused simulation). This
function is only executed by continuous remote API server services. See also
simxPauseSimulation and simxStopSimulation.
Parameters operationMode: a remote API function operation mode. Recommended
operation mode for this function is simx_opmode_oneshot (Non-blocking mode).
return value a remote API function
****************************************************************************************/
int Coppelia::StartSimulation(int operation_mode) {
if (this->client_ID_ == -1) {
return -1;
}
return simxStartSimulation(client_ID_, operation_mode);
}
int Coppelia::StopSimulation(int operation_mode) {
if (this->client_ID_ == -1) {
return -1;
}
return simxStartSimulation(client_ID_, operation_mode);
}
/***************************************************************************************
Retrieves an object handle based on its name. If the client application is
launched from a child script, then you could also let the child script figure
out what handle correspond to what objects, and send the handles as additional
arguments to the client application during its launch. See also
simxGetObjectGroupData.
objectName: name of the object. If possibe, don't rely on the automatic name
adjustment mechanism, and always specify the full object name handle: pointer
to a value that will receive the handle operationMode: a remote API function
operation mode. Recommended operation mode for this function is
simx_opmode_blocking
****************************************************************************************/
int Coppelia::GetObjectHandle(const char *object_name, int operation_mode,
int *handle) {
return simxGetObjectHandle(this->client_ID_, object_name, handle,
operation_mode);
}
/***************************************************************************************
Retrieves the intrinsic position of a joint. This function cannot be used with
spherical joints (use simxGetJointMatrix instead). See also simxSetJointPosition
and simxGetObjectGroupData. C parameters jointHandle: handle of the joint
operationMode: a remote API function operation mode. Recommended operation modes
for this function are simx_opmode_streaming (the first call) and
simx_opmode_buffer (the following calls)
****************************************************************************************/
int Coppelia::GetJointPosition(int joint_handle, int operation_mode,
float *position) {
return simxGetJointPosition(this->client_ID_, joint_handle, position,
operation_mode);
}
/***************************************************************************************
Retrieves the position of an object. See also simxSetObjectPosition,
simxGetObjectOrientation, simxGetObjectQuaternion and simxGetObjectGroupData.
relativeToObjectHandle: indicates relative to which reference frame we want the
position. Specify -1 to retrieve the absolute position, sim_handle_parent to
retrieve the position relative to the object's parent, or an object handle
relative to whose reference frame you want the position position: pointer to 3
values receiving the position operationMode: a remote API function operation
mode. Recommended operation modes for this function are simx_opmode_streaming
(the first call) and simx_opmode_buffer (the following calls)
****************************************************************************************/
int Coppelia::GetObjectPosition(int object_handle,
int relative_to_object_handle,
int operation_mode, float *position) {
return simxGetObjectPosition(this->client_ID_, object_handle,
relative_to_object_handle, position,
operation_mode);
}
/***************************************************************************************
Retrieves the orientation (Euler angles) of an object.
bjectHandle: handle of the object relativeToObjectHandle:
indicates relative to which reference frame we want the orientation. Specify -1
to retrieve the absolute orientation, sim_handle_parent to retrieve the
orientation relative to the object's parent, or an object handle relative to
whose reference frame you want the orientation eulerAngles: pointer to 3 values
receiving the Euler angles (alpha, beta and gamma) operationMode: a remote API
function operation mode. Recommended operation modes for this function are
simx_opmode_streaming (the first call) and simx_opmode_buffer (the following
calls)
****************************************************************************************/
int Coppelia::GetObjectOrientation(int object_handle,
int relative_to_obj
CoppeliaSIm.rar
需积分: 41 154 浏览量
2020-02-26
11:12:19
上传
评论
收藏 5KB RAR 举报
qq_29696095
- 粉丝: 7
- 资源: 1
最新资源
- Ruby语言教程.docx
- auditory perception of sound sources-2007
- SAP 安装步骤详情/创建方法
- 4906-VB一款2个N-Channel沟道SOP8的MOSFET晶体管参数介绍与应用说明
- 4900W-VB一款2个N-Channel沟道SOP8的MOSFET晶体管参数介绍与应用说明
- 4599W-VB一款SOP8封装N+P-Channel场效应MOS管
- 4599-VB一款N+P-Channel沟道SOP8的MOSFET晶体管参数介绍与应用说明
- 4578M-VB一款SOP8封装N+P-Channel场效应MOS管
- 4578GM-VB一款N+P-Channel沟道SOP8的MOSFET晶体管参数介绍与应用说明
- 4578GM-HF-VB一款N+P-Channel沟道SOP8的MOSFET晶体管参数介绍与应用说明
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈