23 double mapd(
double x,
double in_min,
double in_max,
double out_min,
double out_max)
25 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
30 priv_node_handle_(
"~")
60 ROS_INFO(
"open_manipulator_dynamixel_controller : Init OK!");
65 for (uint8_t num = 0; num <
JOINT_NUM; num++)
86 uint16_t get_model_number;
87 for (uint8_t index = 0; index <
JOINT_NUM; index++)
92 ROS_ERROR(
"Not found Joints, Please check id and baud rate");
101 ROS_ERROR(
"Not found Grippers, Please check id and baud rate");
115 for (uint8_t num = 0; num <
JOINT_NUM; num++)
120 for (uint8_t num = 0; num <
JOINT_NUM; num++)
125 for (uint8_t num = 0; num <
JOINT_NUM; num++)
150 int32_t* get_joint_present_position = NULL;
156 for (
int index = 0; index <
JOINT_NUM; index++)
161 int32_t present_position[
DXL_NUM] = {0, };
163 for (
int index = 0; index <
JOINT_NUM; index++)
164 present_position[index] = get_joint_present_position[index];
166 present_position[
DXL_NUM-1] = get_gripper_present_position;
168 for (
int index = 0; index <
JOINT_NUM; index++)
178 int32_t* get_joint_present_velocity = NULL;
184 for (
int index = 0; index <
JOINT_NUM; index++)
189 int32_t present_velocity[
DXL_NUM] = {0, };
191 for (
int index = 0; index <
JOINT_NUM; index++)
192 present_velocity[index] = get_joint_present_velocity[index];
194 present_velocity[
DXL_NUM-1] = get_gripper_present_velocity;
196 for (
int index = 0; index <
JOINT_NUM; index++)
206 sensor_msgs::JointState joint_state;
218 joint_state.header.frame_id =
"world";
221 joint_state.name.push_back(
"joint1");
222 joint_state.name.push_back(
"joint2");
223 joint_state.name.push_back(
"joint3");
224 joint_state.name.push_back(
"joint4");
225 joint_state.name.push_back(
"grip_joint");
226 joint_state.name.push_back(
"grip_joint_sub");
228 joint_states_pos[0] = get_joint_position[0];
229 joint_states_pos[1] = get_joint_position[1];
230 joint_states_pos[2] = get_joint_position[2];
231 joint_states_pos[3] = get_joint_position[3];
232 joint_states_pos[4] =
mapd(get_joint_position[4], 0.90, -0.80, -0.01, 0.01);
233 joint_states_pos[5] = joint_states_pos[4];
235 joint_states_vel[0] = get_joint_velocity[0];
236 joint_states_vel[1] = get_joint_velocity[1];
237 joint_states_vel[2] = get_joint_velocity[2];
238 joint_states_vel[3] = get_joint_velocity[3];
239 joint_states_vel[4] = get_joint_velocity[4];
240 joint_states_vel[5] = joint_states_vel[4];
244 joint_state.position.push_back(joint_states_pos[index]);
245 joint_state.velocity.push_back(joint_states_vel[index]);
246 joint_state.effort.push_back(joint_states_eff[index]);
254 double goal_joint_position[
JOINT_NUM] = {0.0, 0.0, 0.0, 0.0};
256 for (
int index = 0; index <
JOINT_NUM; index++)
257 goal_joint_position[index] = msg->position.at(index);
259 int32_t goal_position[
JOINT_NUM] = {0, };
261 for (
int index = 0; index <
JOINT_NUM; index++)
271 double goal_gripper_position = msg->position[0];
272 goal_gripper_position =
mapd(goal_gripper_position, -0.01, 0.01, 0.90, -0.80);
283 int main(
int argc,
char **argv)
286 ros::init(argc, argv,
"open_manipulator_dynamixel_controller");
bool ping(uint8_t id, uint16_t *get_model_number=0)
ros::NodeHandle priv_node_handle_
double mapd(double x, double in_min, double in_max, double out_min, double out_max)
bool currentMode(uint8_t id, uint8_t cur=50)
bool syncWrite(const char *item_name, int32_t *value)
void publish(const boost::shared_ptr< M > &message) const
std::vector< uint8_t > joint_id_
std::string gripper_mode_
void readVelocity(double *value)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void addSyncRead(const char *item_name)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int32_t convertRadian2Value(uint8_t id, float radian)
int32_t itemRead(uint8_t id, const char *item_name)
#define ITERATION_FREQUENCY
bool itemWrite(uint8_t id, const char *item_name, int32_t value)
ros::Subscriber goal_joint_states_sub_
void goalGripperPositionCallback(const sensor_msgs::JointState::ConstPtr &msg)
ros::NodeHandle node_handle_
bool begin(const char *device_name="/dev/ttyUSB0", uint32_t baud_rate=57600)
int main(int argc, char **argv)
ros::Publisher joint_states_pub_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
float convertValue2Radian(uint8_t id, int32_t value)
bool jointMode(uint8_t id, uint16_t vel=0, uint16_t acc=0)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
DynamixelWorkbench * joint_controller_
ros::Subscriber goal_gripper_states_sub_
int32_t * syncRead(const char *item_name)
std::vector< uint8_t > gripper_id_
void readPosition(double *value)
ROSCPP_DECL void shutdown()
DynamixelWorkbench * gripper_controller_
void goalJointPositionCallback(const sensor_msgs::JointState::ConstPtr &msg)
ROSCPP_DECL void spinOnce()
float convertValue2Velocity(uint8_t id, int32_t value)
void addSyncWrite(const char *item_name)