6 #include <sys/socket.h> 10 #define DEFAULT_SERVER_IP_ADDRESS "133.11.216.196" 11 #define DEFAULT_SERVER_PORT_NUM 5007 12 #define DEFAULT_UDP_TIMEOUT (10 * 1000) 14 #define CONTROL_PRIO 0 15 #include <boost/thread.hpp> 18 std::ostream& operator<< (std::ostream& out, const std::vector<T>& v) {
21 std::copy (v.begin(), v.end(), std::ostream_iterator<T>(out,
", "));
74 ROS_INFO(
"clearError %02x %02x", hr, lResult);
159 var_types_.insert(std::map<std::string, u_short>::value_type(
"ERROR_CODE",
VT_I4));
160 var_types_.insert(std::map<std::string, u_short>::value_type(
"MODE",
VT_I4));
161 var_types_.insert(std::map<std::string, u_short>::value_type(
"ERROR_DESCRIPTION",
VT_BSTR));
162 var_types_.insert(std::map<std::string, u_short>::value_type(
"VERSION",
VT_BSTR));
163 var_types_.insert(std::map<std::string, u_short>::value_type(
"SPEED",
VT_R4));
164 var_types_.insert(std::map<std::string, u_short>::value_type(
"ACCEL",
VT_R4));
165 var_types_.insert(std::map<std::string, u_short>::value_type(
"DECEL",
VT_R4));
166 var_types_.insert(std::map<std::string, u_short>::value_type(
"JSPEED",
VT_R4));
167 var_types_.insert(std::map<std::string, u_short>::value_type(
"JACCEL",
VT_R4));
168 var_types_.insert(std::map<std::string, u_short>::value_type(
"JDECEL",
VT_R4));
169 var_types_.insert(std::map<std::string, u_short>::value_type(
"EXTSPEED",
VT_R4));
170 var_types_.insert(std::map<std::string, u_short>::value_type(
"EXTACCEL",
VT_R4));
171 var_types_.insert(std::map<std::string, u_short>::value_type(
"EXTDECEL",
VT_R4));
172 var_types_.insert(std::map<std::string, u_short>::value_type(
"BUSY_STATUS",
VT_BOOL));
173 var_types_.insert(std::map<std::string, u_short>::value_type(
"CURRENT_TIME",
VT_DATE));
175 var_types_.insert(std::map<std::string, u_short>::value_type(
"EMERGENCY_STOP",
VT_BOOL));
184 ROS_WARN(
"failed to controller get variable '%s' hr:%02x result:%02x", varname.c_str(), hr, varresult);
195 ROS_WARN(
"failed to controller get variable '%s' hr:%02x result:%02x", varname.c_str(), hr, varresult);
206 ROS_WARN(
"Failed to get %s, return 0 instead.", var_name.c_str());
211 ROS_WARN(
"No handler for %s, return 0 instead.", var_name.c_str());
221 ROS_WARN(
"Failed to get %s, return 0 instead.", var_name.c_str());
226 ROS_WARN(
"No handler for %s, return 0 instead.", var_name.c_str());
238 ROS_WARN(
"Failed to get ERROR_CODE, return %02x instead.", hr);
243 ROS_WARN(
"ERROR_CODE is not in variable handlers");
281 ROS_WARN(
"ERROR_DESCRIPTION is not in variable handlers");
331 slvchangeparam.
Arrays = 1;
345 struct timespec tick, before;
347 clock_gettime(CLOCK_MONOTONIC, &tick);
351 ROS_WARN(
"failed to slvmove, errorcode: %02x", hr);
354 clock_gettime(CLOCK_MONOTONIC, &before);
355 static const int NSEC_PER_SECOND = 1e+9;
357 double roundtrip = (before.tv_sec + double(before.tv_nsec) / NSEC_PER_SECOND)
358 - (tick.tv_sec +
double(tick.tv_nsec) / NSEC_PER_SECOND);
362 if (failed_to_send_packet)
364 ROS_WARN(
" roundtrip: %f", roundtrip);
375 std::vector<double> cur_jnt;
377 for (
int i = 0; i < 3; i++) {
388 for (
int i = num_joints_; i < 8; i++) {
393 for (
int i = 0; i < 4; i++) {
427 boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
435 ROS_WARN(
"failed to change slave mode");
466 ROS_WARN(
"failed to release the robot");
470 ROS_INFO(
"successed to release the robot");
475 ROS_WARN(
"failed to disconnect from the controller");
479 ROS_INFO(
"successed to disconnect from the controller");
485 ROS_WARN(
"failed to stop the service");
489 ROS_INFO(
"successed to stop the service");
491 boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
499 ROS_INFO(
"successed to close bCap");
505 bool read(std::vector<double>& pos) {
521 bool write(
const std::vector<double>& cmd, std::vector<double>& pos)
536 for (
int i = 0; i < cmd.size(); i++) {
559 if (hr == 0x83500121)
561 ROS_INFO(
"robot is not in slavemode, try to change it");
565 ROS_WARN(
"failed to clear error, cannot recover");
575 ROS_WARN(
"failed to change slvmode, cannot recover");
580 ROS_WARN(
"failed to fill buffer in slave mode");
591 for (
int i = 0; i < pos.size(); i++) {
1004 #ifdef BCAP_CONNECTION_UDP 1008 if (setsockopt(
iSockFD_, SOL_SOCKET, SO_SNDTIMEO, &tv,
sizeof(tv)) < 0)
1010 ROS_WARN(
"Failed to set send timeout");
1012 if (setsockopt(
iSockFD_, SOL_SOCKET, SO_RCVTIMEO, &tv,
sizeof(tv)) < 0)
1014 ROS_WARN(
"Failed to set recv timeout");
1036 ROS_WARN(
"running with loopback mode");
1073 ROS_FATAL(
"failed to open bCap socket. Exitting...");
1082 ROS_FATAL(
"failed to start bCap server. Exitting...");
1089 ROS_FATAL(
"failed to connect bCap controller. Exitting...");
1096 ROS_FATAL(
"failed to clear bCap error. Exitting...");
1103 ROS_FATAL(
"failed to get bCap robot. Exitting...");
1110 ROS_FATAL(
"failed to take bCap arm. Exitting...");
1117 ROS_FATAL(
"failed to set external speed. Exitting...");
1129 std::string errormsg;
1132 ROS_INFO(
"errormsg: %s", errormsg.c_str());
1133 ROS_WARN(
"failed to motor on, errorcode: %02x, errormsg: %s", errorcode, errormsg.c_str());
1144 ROS_FATAL(
"failed to enable logging mode");
1162 ROS_FATAL(
"failed to change slave mode");
1166 ROS_INFO(
"initialize bCap slave connection");
1170 ROS_FATAL(
"failed to fill bcap buffer");
1173 ROS_INFO(
"bCap slave initialization done");
b-CAP client library header
BCAP_HRESULT bCapCurJnt(std::vector< double > &jointvalues)
BCAP_HRESULT bCapFillBuffer()
u_int bCapGetIntegerVariable(const std::string &var_name)
BCAP_HRESULT bCapRobotExecute(char *command, char *arg)
bool write(const std::vector< double > &cmd, std::vector< double > &pos)
BCAP_HRESULT bCap_ControllerGetVariable(int iSockFd, u_int lhController, char *pVarName, char *pstrOption, u_int *plhVar)
BCAP_HRESULT bCapGetRobot()
BCAP_HRESULT bCap_ServiceStart(int iSockFd)
#define DEFAULT_UDP_TIMEOUT
BCAP_HRESULT
BCAP_HRESULT values.
bool initialize(ros::NodeHandle &node, int num_joints)
BCAP_HRESULT bCapMotor(bool command)
virtual void finalizeHW()
BCAP_HRESULT bCap_RobotGetVariable(int iSockFd, u_int lhRobot, char *pVarName, char *pStrOption, u_int *lhVarCurJnt)
BCAP_HRESULT bCap_ControllerConnect(int iSockFd, char *pStrCtrlname, char *pStrProvName, char *pStrPcName, char *pStrOption, u_int *plhController)
int failed_to_send_packet
u_int bCapRobotGetVariable(const std::string &varname)
BCAP_HRESULT bCapClearError()
BCAP_HRESULT bCap_ControllerExecute(int iSockFd, u_int lhController, char *pStrCommand, char *pStrOption, void *plResult)
std::map< std::string, u_short > var_types_
#define DEFAULT_SERVER_PORT_NUM
BCAP_HRESULT bCap_VariableGetValue(int iSockFd, u_int lhVar, void *pVntValue)
union BCAP_VARIANT::@0 Value
bool read(std::vector< double > &pos)
BCAP_HRESULT bCap_RobotExecute(int iSockFd, u_int lhRobot, char *pStrCommand, char *pStrOption, void *plResult)
char errdesc_buffer_[2048]
BCAP_HRESULT bCap_RobotExecute2(int iSockFd, u_int lhRobot, char *pStrCommand, BCAP_VARIANT *pVntOption, BCAP_VARIANT *pvntResult)
BCAP_HRESULT bCapSetExternalSpeed(float arg)
BCAP_HRESULT bCap_ControllerDisconnect(int iSockFd, u_int lhController)
BCAP_HRESULT bCap_ControllerGetRobot(int iSockFd, u_int lhController, char *pStrRobotName, char *pStrOption, u_int *lhRobot)
BCAP_HRESULT bCap_RobotRelease(int iSockFd, u_int lhRobot)
BCAP_HRESULT bCapRobotSlvMove(BCAP_VARIANT *pose, BCAP_VARIANT *result)
BCAP_HRESULT bCapControllerDisConnect()
BCAP_HRESULT bCapSlvChangeMode(u_int arg)
struct timespec prev_time_
BCAP_HRESULT bCapServerStop()
#define ROS_DEBUG_STREAM(args)
void bCapInitializeVariableHandlers()
BCAP_HRESULT bCapReleaseRobot()
std::string server_ip_address_
std::map< std::string, u_int > var_handlers_
BCAP_HRESULT bCapTakearm()
BCAP_HRESULT bCapGiveArm()
u_int bCapControllerGetVariable(const std::string &varname)
bool getParam(const std::string &key, std::string &s) const
#define DEFAULT_SERVER_IP_ADDRESS
bool bCapGetEmergencyStop()
bool bCapGetBoolVariable(const std::string &var_name)
BCAP_HRESULT bCapServerStart()
BCAP_HRESULT bCap_Open(const char *pIPStr, int iPort, int *piSockFd)
void setUDPTimeout(long sec, long usec)
std::vector< double > jntvalues_
BCAP_HRESULT bCap_ServiceStop(int iSockFd)
BCAP_HRESULT bCapControllerConnect()
u_int bCapErrorDescription(std::string &errormsg)
BCAP_HRESULT bCap_Close(int iSockFd)