自己把CoppeliaSim remote API 中的部分函数封装了类,可以完成机器人的关节空间控制,以及笛卡尔空间控制。
VS2017 和 CoppeliaSim/Vrep 的配置参见我的博客:
CoppeliaSim Remote API 实操
关节空间控制,需在CoppeliaSim/Vrep中关闭逆运动学,笛卡尔空间控制开启逆运动学。
下面是头文件,全部文件请在下方链接下载:(包括VS的永久配置文件,需按照自己文件的路径稍作修改)
https://download.csdn.net/download/qq_29696095/12192775
// Copyright SJTU
// author Li Wang 05liwang@sjtu.edu.cn 935342669@qq.com
// this file is used to wrap the legacy remote API of CoppeliaSim
// all the unit of data from coppeliasim is m or s or N or deg
// orientation is euler anles, alpha, beta and gamma
// T = rotx(a)*roty(b)*rotz(g)
#ifndef COPPELIA_H_
#define COPPELIA_H_
extern "C" {
#include "extApi.h"
#include "extApiPlatform.h"
}
#define M_PI 3.14159265358979323846 // pi
typedef unsigned char uchar;
// opmode explaination
// http://www.360doc.com/content/19/0720/09/32181961_849906173.shtml
const int NON_BLOCK_MODE = simx_opmode_oneshot;
const int BLOCK_MODE = simx_opmode_blocking;
const int STREAMING_MODE = simx_opmode_streaming;
// The function executed fine
const int SIM_RETRUN_OK = simx_return_ok;
// There is no command reply in the input buffer. This should not always be
// considered as an error, depending on the selected operation mode
const int SIM_RETRUN_NOVALUE_FLAG = simx_return_novalue_flag;
// The function timed out (probably the network is down or too slow)
const int SIM_RETRUN_TIMEOUT_FLAG = simx_return_timeout_flag;
// The specified operation mode is not supported for the given function
const int SIM_RETRUN_ILLEGAL_OPMODE_FLAG = simx_return_illegal_opmode_flag;
// The function caused an error on the server side (e.g. an invalid handle was
// specified)
const int SIM_RETRUN_REMOTE_ERROR_FALG = simx_return_remote_error_flag;
// The communication thread is still processing previous split command of the
// same type
const int SIM_RETRUN_SPLIT_PROCESS_FLAG = simx_return_split_progress_flag;
// The function caused an error on the client side
const int SIM_RETRUN_LOCAL_FLAG = simx_return_local_error_flag;
// simxStart was not yet called
const int SIM_RETRUN_INITIALIZE_ERROR_FLAG = simx_return_initialize_error_flag;
class Coppelia {
public:
Coppelia();
~Coppelia();
int ConnectCoppeliaSim(int port_number, bool wait_until_connected,
bool do_not_reconnect_once_disconnected,
int time_out_in_ms, int commthread_cycle_in_ms);
void DisconnectCoppeliasSim();
int StartSimulation(int operation_mode);
int StopSimulation(int operation_mode);
int GetObjectHandle(const char *object_name, int operation_mode, int *handle);
int GetJointPosition(int joint_handle, int operation_mode, float *position);
int GetObjectPosition(int object_handle, int relative_to_object_handle,
int operation_mode, float *position);
int GetObjectOrientation(int object_handle, int relative_to_object_handle,
int operation_mode, float *orientation);
int GetObjectPositionAndOrientation(int object_handle,
int relative_to_object_handle,
int operation_mode, float *Pos_Orient);
int SetJointPosition(int joint_handle, int operation_mode, float position);
int SetRobotJointPosition(int *joint_handle, int joint_number, int operation_mode,
float *position);
int SetJointTargetPosition(int joint_handle, int operation_mode,
float position);
int SetJointTargetVelocity(int joint_handle, int operation_mode,
float position);
int SetObjectPosition(int object_handle, int relative_to_object_handle,
int operation_mode, float *position);
int SetObjectOrientation(int object_handle, int relative_to_object_handle,
int operation_mode, float *orientation);
int SetObjectPositionAndOrientation(int object_handle,
int relative_to_object_handle,
int operation_mode, float *Pos_Orient);
int PauseCommunication(bool pause);
private:
int client_ID_ = -1;
int port_number_ = 0;
};
#endif // !COPPELIASIMCLIENT_H_
来源:CSDN
作者:qq_29696095
链接:https://blog.csdn.net/qq_29696095/article/details/104512768