35 #ifndef KHI_ROBOT_DRIVER_H 36 #define KHI_ROBOT_DRIVER_H 39 #include <khi_robot_msgs/KhiRobotCmd.h> 43 #define KHI_MAX_CONTROLLER 8 45 #define KHI_MAX_JOINT 18 46 #define KHI_MAX_SIG_SIZE 512 130 cont_info[cno].state =
INIT;
131 cont_info[cno].state_trigger =
NONE;
132 cont_info[cno].ip_address =
"127.0.0.1";
135 driver_name = __func__;
141 else {
return cont_info[cont_no].state; }
147 std::string
name =
"";
149 state = getState( cont_no );
152 name = KhiRobotStateName[state];
158 bool setState(
const int& cont_no,
const int& state )
168 if ( cont_info[cont_no].state != state )
170 infoPrint(
"State %d: %s -> %s", cont_no, KhiRobotStateName[cont_info[cont_no].state].c_str(), KhiRobotStateName[state].c_str() );
171 cont_info[cont_no].state = state;
181 state = getState( cont_no );
199 state_trigger = cont_info[cont_no].state_trigger;
200 cont_info[cont_no].state_trigger =
NONE;
201 return state_trigger;
215 if ( cont_info[cont_no].state_trigger !=
NONE )
217 warnPrint(
"State Trigger is already done %d: %s", cont_no, KhiRobotStateTriggerName[state_trigger].c_str() );
219 infoPrint(
"State Trigger %d: %s", cont_no, KhiRobotStateTriggerName[state_trigger].c_str() );
220 cont_info[cont_no].state_trigger = state_trigger;
229 errorPrint(
"contLimitCheck ERROR!" );
240 char msg[512] = { 0 };
243 va_start( ap, format );
244 vsnprintf( msg,
sizeof(msg), format, ap );
246 ROS_INFO(
"[%s] %s", driver_name.c_str(), msg );
251 char msg[512] = { 0 };
254 va_start( ap, format );
255 vsnprintf( msg,
sizeof(msg), format, ap );
257 ROS_WARN(
"[%s] %s", driver_name.c_str(), msg );
262 char msg[512] = { 0 };
265 va_start( ap, format );
266 vsnprintf( msg,
sizeof(msg), format, ap );
268 ROS_ERROR(
"[%s] %s", driver_name.c_str(), msg );
273 char msg[512] = { 0 };
274 char jt_val[16] = { 0 };
277 snprintf( msg,
sizeof(msg),
"[%s]\t", name.c_str() );
280 if ( name == std::string(
"write") ) { value = data.
arm[ano].
cmd; }
281 else { value = data.
arm[ano].
pos; }
282 for (
int jt = 0; jt < data.
arm[ano].
jt_num; jt++ )
284 snprintf( jt_val,
sizeof(jt_val),
"%.3lf\t", value[jt] );
285 strcat( msg, jt_val );
288 infoPrint(
"[SIM]%s", msg );
292 virtual bool initialize(
const int& cont_no,
const double& period,
KhiRobotData&
data,
const bool in_simulation =
false ) = 0;
293 virtual bool open(
const int& cont_no,
const std::string& ip_address,
KhiRobotData& data ) = 0;
294 virtual bool close(
const int& cont_no ) = 0;
296 virtual bool hold(
const int& cont_no,
const KhiRobotData& data ) = 0;
297 virtual bool deactivate(
const int& cont_no,
const KhiRobotData& data ) = 0;
298 virtual bool readData(
const int& cont_no,
KhiRobotData& data ) = 0;
299 virtual bool writeData(
const int& cont_no,
const KhiRobotData& data ) = 0;
300 virtual bool updateState(
const int& cont_no,
const KhiRobotData& data ) = 0;
301 virtual bool getPeriodDiff(
const int& cont_no,
double& diff ) = 0;
302 virtual bool commandHandler( khi_robot_msgs::KhiRobotCmd::Request& req, khi_robot_msgs::KhiRobotCmd::Response& res ) = 0;
314 #endif // KHI_ROBOT_DRIVER_H
void errorPrint(const char *format,...)
int getStateTrigger(const int &cont_no)
ROSCONSOLE_DECL void initialize()
#define KHI_MAX_CONTROLLER
double pos[KHI_MAX_JOINT]
KhiRobotArmData arm[KHI_MAX_ARM]
bool isTransitionState(const int &cont_no)
static const std::string KhiRobotStateTriggerName[TRIGGER_MAX]
int getState(const int &cont_no)
bool setStateTrigger(const int &cont_no, const int &state_trigger)
std::string getStateName(const int &cont_no)
void jointPrint(std::string name, const KhiRobotData &data)
bool activate(khi_robot_control::KhiRobotHardwareInterface &robot, struct timespec *tick)
std::string name[KHI_MAX_JOINT]
double eff[KHI_MAX_JOINT]
double vel[KHI_MAX_JOINT]
bool setState(const int &cont_no, const int &state)
void infoPrint(const char *format,...)
double home[KHI_MAX_JOINT]
virtual ~KhiRobotDriver()
double cmd[KHI_MAX_JOINT]
void warnPrint(const char *format,...)
static const std::string KhiRobotStateName[STATE_MAX]
bool contLimitCheck(const int &cont_no, const int &limit)