25 priv_node_handle_(
"~"),
26 tool_ctrl_state_(false),
27 timer_thread_state_(false),
28 moveit_plan_state_(false),
29 using_platform_(false),
31 moveit_plan_only_(true),
32 control_period_(0.010
f),
33 moveit_sampling_time_(0.050
f)
46 if (using_moveit_ ==
true)
49 log::info(
"Ready to control " + planning_group_name +
" group");
57 log::info(
"Shutdown the OpenManipulator");
93 log::error(
"Creating timer thread failed!!", (
double)error);
102 static struct timespec next_time;
103 static struct timespec curr_time;
105 clock_gettime(CLOCK_MONOTONIC, &next_time);
109 next_time.tv_sec += (next_time.tv_nsec + ((int)(controller->
getControlPeriod() * 1000)) * 1000000) / 1000000000;
110 next_time.tv_nsec = (next_time.tv_nsec + ((int)(controller->
getControlPeriod() * 1000)) * 1000000) % 1000000000;
112 double time = next_time.tv_sec + (next_time.tv_nsec*0.000000001);
115 clock_gettime(CLOCK_MONOTONIC, &curr_time);
117 double delta_nsec = controller->
getControlPeriod() - ((next_time.tv_sec - curr_time.tv_sec) + ((
double)(next_time.tv_nsec - curr_time.tv_nsec)*0.000000001));
122 next_time = curr_time;
125 clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next_time, NULL);
136 for (
auto const& name:opm_tools_name)
151 gazebo_joints_name.reserve(gazebo_joints_name.size() + opm_tools_name.size());
152 gazebo_joints_name.insert(gazebo_joints_name.end(), opm_tools_name.begin(), opm_tools_name.end());
154 for (
auto const& name:gazebo_joints_name)
213 if(msg->data ==
"print_open_manipulator_setting")
219 trajectory_msgs::JointTrajectory joint_trajectory_planned = msg->trajectory[0].joint_trajectory;
224 log::println(
"[INFO] [OpenManipulator Controller] Execute Moveit planned path",
"GREEN");
228 log::println(
"[INFO] [OpenManipulator Controller] Get Moveit planned path",
"GREEN");
233 log::println(
"[INFO] [OpenManipulator Controller] Get Moveit plnning option",
"GREEN");
239 log::println(
"[INFO] [OpenManipulator Controller] Execute Moveit planned path",
"GREEN");
244 open_manipulator_msgs::SetJointPosition::Response &res)
246 std::vector <double> target_angle;
248 for(
int i = 0; i < req.joint_position.joint_name.size(); i ++)
249 target_angle.push_back(req.joint_position.position.at(i));
253 res.is_planned =
true;
258 open_manipulator_msgs::SetKinematicsPose::Response &res)
261 target_pose.
position[0] = req.kinematics_pose.pose.position.x;
262 target_pose.
position[1] = req.kinematics_pose.pose.position.y;
263 target_pose.
position[2] = req.kinematics_pose.pose.position.z;
265 Eigen::Quaterniond q(req.kinematics_pose.pose.orientation.w,
266 req.kinematics_pose.pose.orientation.x,
267 req.kinematics_pose.pose.orientation.y,
268 req.kinematics_pose.pose.orientation.z);
270 target_pose.
orientation = math::convertQuaternionToRotationMatrix(q);
274 res.is_planned =
true;
279 open_manipulator_msgs::SetKinematicsPose::Response &res)
282 target_pose.
position[0] = req.kinematics_pose.pose.position.x;
283 target_pose.
position[1] = req.kinematics_pose.pose.position.y;
284 target_pose.
position[2] = req.kinematics_pose.pose.position.z;
288 res.is_planned =
true;
293 open_manipulator_msgs::SetKinematicsPose::Response &res)
297 Eigen::Quaterniond q(req.kinematics_pose.pose.orientation.w,
298 req.kinematics_pose.pose.orientation.x,
299 req.kinematics_pose.pose.orientation.y,
300 req.kinematics_pose.pose.orientation.z);
302 target_pose.
orientation = math::convertQuaternionToRotationMatrix(q);
306 res.is_planned =
true;
311 open_manipulator_msgs::SetKinematicsPose::Response &res)
314 target_pose.
position[0] = req.kinematics_pose.pose.position.x;
315 target_pose.
position[1] = req.kinematics_pose.pose.position.y;
316 target_pose.
position[2] = req.kinematics_pose.pose.position.z;
318 Eigen::Quaterniond q(req.kinematics_pose.pose.orientation.w,
319 req.kinematics_pose.pose.orientation.x,
320 req.kinematics_pose.pose.orientation.y,
321 req.kinematics_pose.pose.orientation.z);
323 target_pose.
orientation = math::convertQuaternionToRotationMatrix(q);
326 res.is_planned =
true;
331 open_manipulator_msgs::SetKinematicsPose::Response &res)
333 Eigen::Vector3d position;
334 position[0] = req.kinematics_pose.pose.position.x;
335 position[1] = req.kinematics_pose.pose.position.y;
336 position[2] = req.kinematics_pose.pose.position.z;
340 res.is_planned =
true;
345 open_manipulator_msgs::SetKinematicsPose::Response &res)
347 Eigen::Quaterniond q(req.kinematics_pose.pose.orientation.w,
348 req.kinematics_pose.pose.orientation.x,
349 req.kinematics_pose.pose.orientation.y,
350 req.kinematics_pose.pose.orientation.z);
352 Eigen::Matrix3d orientation = math::convertQuaternionToRotationMatrix(q);
356 res.is_planned =
true;
361 open_manipulator_msgs::SetJointPosition::Response &res)
363 std::vector <double> target_angle;
365 for(
int i = 0; i < req.joint_position.joint_name.size(); i ++)
366 target_angle.push_back(req.joint_position.position.at(i));
370 res.is_planned =
true;
375 open_manipulator_msgs::SetKinematicsPose::Response &res)
378 target_pose.
position[0] = req.kinematics_pose.pose.position.x;
379 target_pose.
position[1] = req.kinematics_pose.pose.position.y;
380 target_pose.
position[2] = req.kinematics_pose.pose.position.z;
382 Eigen::Quaterniond q(req.kinematics_pose.pose.orientation.w,
383 req.kinematics_pose.pose.orientation.x,
384 req.kinematics_pose.pose.orientation.y,
385 req.kinematics_pose.pose.orientation.z);
387 target_pose.
orientation = math::convertQuaternionToRotationMatrix(q);
391 res.is_planned =
true;
396 open_manipulator_msgs::SetKinematicsPose::Response &res)
398 Eigen::Vector3d position;
399 position[0] = req.kinematics_pose.pose.position.x;
400 position[1] = req.kinematics_pose.pose.position.y;
401 position[2] = req.kinematics_pose.pose.position.z;
405 res.is_planned =
true;
410 open_manipulator_msgs::SetKinematicsPose::Response &res)
412 Eigen::Quaterniond q(req.kinematics_pose.pose.orientation.w,
413 req.kinematics_pose.pose.orientation.x,
414 req.kinematics_pose.pose.orientation.y,
415 req.kinematics_pose.pose.orientation.z);
417 Eigen::Matrix3d orientation = math::convertQuaternionToRotationMatrix(q);
421 res.is_planned =
true;
426 open_manipulator_msgs::SetJointPosition::Response &res)
428 for(
int i = 0; i < req.joint_position.joint_name.size(); i ++)
431 res.is_planned =
true;
436 open_manipulator_msgs::SetActuatorState::Response &res)
438 if(req.set_actuator_state ==
true)
440 log::println(
"Wait a second for actuator enable",
"GREEN");
448 log::println(
"Wait a second for actuator disable",
"GREEN");
455 res.is_planned =
true;
460 open_manipulator_msgs::SetDrawingTrajectory::Response &res)
464 if(req.drawing_trajectory_name ==
"circle")
466 double draw_circle_arg[3];
467 draw_circle_arg[0] = req.param[0];
468 draw_circle_arg[1] = req.param[1];
469 draw_circle_arg[2] = req.param[2];
470 void* p_draw_circle_arg = &draw_circle_arg;
474 else if(req.drawing_trajectory_name ==
"line")
480 void *p_draw_line_arg = &draw_line_arg;
484 else if(req.drawing_trajectory_name ==
"rhombus")
486 double draw_rhombus_arg[3];
487 draw_rhombus_arg[0] = req.param[0];
488 draw_rhombus_arg[1] = req.param[1];
489 draw_rhombus_arg[2] = req.param[2];
490 void* p_draw_rhombus_arg = &draw_rhombus_arg;
494 else if(req.drawing_trajectory_name ==
"heart")
496 double draw_heart_arg[3];
497 draw_heart_arg[0] = req.param[0];
498 draw_heart_arg[1] = req.param[1];
499 draw_heart_arg[2] = req.param[2];
500 void* p_draw_heart_arg = &draw_heart_arg;
504 res.is_planned =
true;
509 log::error(
"Creation the custom trajectory is failed!");
515 open_manipulator_msgs::GetJointPosition::Response &res)
523 for (std::size_t i = 0; i < joint_names.size(); i++)
525 res.joint_position.joint_name.push_back(joint_names[i]);
526 res.joint_position.position.push_back(joint_values[i]);
534 open_manipulator_msgs::GetKinematicsPose::Response &res)
541 res.header = current_pose.header;
542 res.kinematics_pose.pose = current_pose.pose;
549 open_manipulator_msgs::SetJointPosition::Response &res)
551 open_manipulator_msgs::JointPosition msg = req.joint_position;
558 open_manipulator_msgs::SetKinematicsPose::Response &res)
560 open_manipulator_msgs::KinematicsPose msg = req.kinematics_pose;
571 bool is_planned =
false;
572 geometry_msgs::Pose target_pose = msg.pose;
585 bool success = (
move_group_->
plan(my_plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
593 log::warn(
"Failed to Plan (task space goal)");
599 log::warn(
"Robot is Moving");
612 bool is_planned =
false;
618 std::vector<double> joint_group_positions;
619 current_state->copyJointGroupPositions(joint_model_group, joint_group_positions);
623 joint_group_positions[
index] = msg.position[
index];
635 bool success = (
move_group_->
plan(my_plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
643 log::warn(
"Failed to Plan (joint space goal)");
649 log::warn(
"Robot is moving");
659 open_manipulator_msgs::OpenManipulatorState msg;
661 msg.open_manipulator_moving_state = msg.IS_MOVING;
663 msg.open_manipulator_moving_state = msg.STOPPED;
666 msg.open_manipulator_actuator_state = msg.ACTUATOR_ENABLED;
668 msg.open_manipulator_actuator_state = msg.ACTUATOR_DISABLED;
675 open_manipulator_msgs::KinematicsPose msg;
679 for (
auto const& tools:opm_tools_name)
683 msg.pose.position.y = pose.
position[1];
684 msg.pose.position.z = pose.
position[2];
685 Eigen::Quaterniond orientation = math::convertRotationMatrixToQuaternion(pose.
orientation);
686 msg.pose.orientation.w = orientation.w();
687 msg.pose.orientation.x = orientation.x();
688 msg.pose.orientation.y = orientation.y();
689 msg.pose.orientation.z = orientation.z();
698 sensor_msgs::JointState msg;
707 for(uint8_t i = 0; i < joints_name.size(); i ++)
709 msg.name.push_back(joints_name.at(i));
711 msg.position.push_back(joint_value.at(i).position);
712 msg.velocity.push_back(joint_value.at(i).velocity);
713 msg.effort.push_back(joint_value.at(i).effort);
716 for(uint8_t i = 0; i < tool_name.size(); i ++)
718 msg.name.push_back(tool_name.at(i));
720 msg.position.push_back(tool_value.at(i).position);
721 msg.velocity.push_back(0.0
f);
722 msg.effort.push_back(0.0
f);
732 for(uint8_t i = 0; i < joint_value.size(); i ++)
734 std_msgs::Float64 msg;
735 msg.data = joint_value.at(i).position;
740 for(uint8_t i = 0; i < tool_value.size(); i ++)
742 std_msgs::Float64 msg;
743 msg.data = tool_value.at(i).position;
760 static double priv_time = 0.0f;
761 static uint32_t step_cnt = 0;
765 double path_time = present_time - priv_time;
777 target.push_back(temp);
782 priv_time = present_time;
784 if (step_cnt >= all_time_steps)
790 log::warn(
"Could not update the start state! Enable External Communications at the Moveit Plugin");
799 priv_time = present_time;
809 int main(
int argc,
char **argv)
811 ros::init(argc, argv,
"open_manipulator_controller");
814 std::string usb_port =
"/dev/ttyUSB0";
815 std::string baud_rate =
"1000000";
819 log::error(
"Please set '-port_name' and '-baud_rate' arguments for connected Dynamixels");
ros::Subscriber open_manipulator_option_sub_
ros::Subscriber display_planned_path_sub_
std::vector< Name > getAllToolComponentName()
ros::ServiceServer goal_task_space_path_orientation_only_server_
void publish(const boost::shared_ptr< M > &message) const
void executeTrajGoalCallback(const moveit_msgs::ExecuteTrajectoryActionGoal::ConstPtr &msg)
bool goalToolControlCallback(open_manipulator_msgs::SetJointPosition::Request &req, open_manipulator_msgs::SetJointPosition::Response &res)
ros::ServiceServer get_kinematics_pose_server_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool goalTaskSpacePathOrientationOnlyCallback(open_manipulator_msgs::SetKinematicsPose::Request &req, open_manipulator_msgs::SetKinematicsPose::Response &res)
std::vector< ros::Publisher > gazebo_goal_joint_position_pub_
bool setJointValueTarget(const std::vector< double > &group_variable_values)
ros::Subscriber move_group_goal_sub_
void process(double time)
void displayPlannedPathCallback(const moveit_msgs::DisplayTrajectory::ConstPtr &msg)
#define CUSTOM_TRAJECTORY_CIRCLE
std::vector< double > getCurrentJointValues()
ros::ServiceServer goal_joint_space_path_server_
std::vector< JointValue > getAllActiveJointValue()
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool goalTaskSpacePathCallback(open_manipulator_msgs::SetKinematicsPose::Request &req, open_manipulator_msgs::SetKinematicsPose::Response &res)
void makeCustomTrajectory(Name trajectory_name, Name tool_name, const void *arg, double move_time, std::vector< JointValue > present_joint_value={})
static void * timerThread(void *param)
bool getActuatorEnabledState(Name actuator_name)
ros::ServiceServer goal_joint_space_path_from_present_server_
void processOpenManipulator(double present_time)
void moveGroupGoalCallback(const moveit_msgs::MoveGroupActionGoal::ConstPtr &msg)
KinematicPose getKinematicPose(Name component_name)
bool setPoseTarget(const Eigen::Affine3d &end_effector_pose, const std::string &end_effector_link="")
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
bool goalTaskSpacePathFromPresentOrientationOnlyCallback(open_manipulator_msgs::SetKinematicsPose::Request &req, open_manipulator_msgs::SetKinematicsPose::Response &res)
ros::ServiceServer goal_joint_space_path_to_kinematics_orientation_server_
void publishJointStates()
ros::ServiceServer goal_drawing_trajectory_server_
bool goalTaskSpacePathPositionOnlyCallback(open_manipulator_msgs::SetKinematicsPose::Request &req, open_manipulator_msgs::SetKinematicsPose::Response &res)
std::vector< JointValue > JointWaypoint
void moveitTimer(double present_time)
void makeTaskTrajectoryFromPresentPose(Name tool_name, Eigen::Vector3d position_meter, double move_time, std::vector< JointValue > present_joint_value={})
ros::ServiceServer goal_task_space_path_position_only_server_
std::vector< Name > getAllActiveJointComponentName()
ros::ServiceServer set_actuator_state_server_
bool setActuatorStateCallback(open_manipulator_msgs::SetActuatorState::Request &req, open_manipulator_msgs::SetActuatorState::Response &res)
void publishGazeboCommand()
#define CUSTOM_TRAJECTORY_HEART
void openManipulatorOptionCallback(const std_msgs::String::ConstPtr &msg)
ros::NodeHandle node_handle_
ros::ServiceServer goal_task_space_path_from_present_server_
bool goalTaskSpacePathFromPresentCallback(open_manipulator_msgs::SetKinematicsPose::Request &req, open_manipulator_msgs::SetKinematicsPose::Response &res)
ros::ServiceServer set_kinematics_pose_server_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
ros::ServiceServer goal_joint_space_path_to_kinematics_position_server_
bool goalJointSpacePathFromPresentCallback(open_manipulator_msgs::SetJointPosition::Request &req, open_manipulator_msgs::SetJointPosition::Response &res)
double moveit_sampling_time_
robot_state::RobotStatePtr getCurrentState(double wait=1)
OpenManipulatorController(std::string usb_port, std::string baud_rate)
void setMaxVelocityScalingFactor(double max_velocity_scaling_factor)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
bool goalJointSpacePathCallback(open_manipulator_msgs::SetJointPosition::Request &req, open_manipulator_msgs::SetJointPosition::Response &res)
void printManipulatorSetting()
bool goalJointSpacePathToKinematicsPoseCallback(open_manipulator_msgs::SetKinematicsPose::Request &req, open_manipulator_msgs::SetKinematicsPose::Response &res)
void makeJointTrajectory(std::vector< double > goal_joint_position, double move_time, std::vector< JointValue > present_joint_value={})
const std::string & getNamespace() const
Manipulator * getManipulator()
ros::ServiceServer goal_task_space_path_server_
geometry_msgs::PoseStamped getCurrentPose(const std::string &end_effector_link="")
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::NodeHandle priv_node_handle_
MoveItErrorCode plan(Plan &plan)
bool setKinematicsPoseMsgCallback(open_manipulator_msgs::SetKinematicsPose::Request &req, open_manipulator_msgs::SetKinematicsPose::Response &res)
bool goalTaskSpacePathFromPresentPositionOnlyCallback(open_manipulator_msgs::SetKinematicsPose::Request &req, open_manipulator_msgs::SetKinematicsPose::Response &res)
ros::ServiceServer get_joint_position_server_
void makeTaskTrajectory(Name tool_name, Eigen::Vector3d goal_position, double move_time, std::vector< JointValue > present_joint_value={})
void publishCallback(const ros::TimerEvent &)
void disableAllActuator()
ros::Publisher open_manipulator_states_pub_
~OpenManipulatorController()
ros::ServiceServer goal_task_space_path_from_present_position_only_server_
void setGoalTolerance(double tolerance)
OpenManipulator open_manipulator_
ros::ServiceServer set_joint_position_server_
bool goalDrawingTrajectoryCallback(open_manipulator_msgs::SetDrawingTrajectory::Request &req, open_manipulator_msgs::SetDrawingTrajectory::Response &res)
bool calcPlannedPath(const std::string planning_group, open_manipulator_msgs::JointPosition msg)
uint32_t getNumSubscribers() const
void initOpenManipulator(bool using_actual_robot_state, STRING usb_port="/dev/ttyUSB0", STRING baud_rate="1000000", float control_loop_time=0.010)
ros::ServiceServer goal_tool_control_server_
ros::ServiceServer goal_joint_space_path_to_kinematics_pose_server_
std::vector< JointValue > getAllToolValue()
ros::Subscriber execute_traj_goal_sub_
bool goalJointSpacePathToKinematicsPositionCallback(open_manipulator_msgs::SetKinematicsPose::Request &req, open_manipulator_msgs::SetKinematicsPose::Response &res)
#define CUSTOM_TRAJECTORY_LINE
const std::vector< std::string > & getJointNames()
ros::Publisher open_manipulator_joint_states_pub_
void makeJointTrajectoryFromPresentPosition(std::vector< double > delta_goal_joint_position, double move_time, std::vector< JointValue > present_joint_value={})
ROSCPP_DECL void shutdown()
#define CUSTOM_TRAJECTORY_RHOMBUS
void publishOpenManipulatorStates()
double getControlPeriod(void)
moveit::planning_interface::MoveGroupInterface * move_group_
bool goalJointSpacePathToKinematicsOrientationCallback(open_manipulator_msgs::SetKinematicsPose::Request &req, open_manipulator_msgs::SetKinematicsPose::Response &res)
void setMaxAccelerationScalingFactor(double max_acceleration_scaling_factor)
ros::Publisher moveit_update_start_state_pub_
std::vector< ros::Publisher > open_manipulator_kinematics_pose_pub_
trajectory_msgs::JointTrajectory joint_trajectory_
ros::ServiceServer goal_task_space_path_from_present_orientation_only_server_
ROSCPP_DECL void spinOnce()
Eigen::Matrix3d orientation
bool setJointPositionMsgCallback(open_manipulator_msgs::SetJointPosition::Request &req, open_manipulator_msgs::SetJointPosition::Response &res)
bool getJointPositionMsgCallback(open_manipulator_msgs::GetJointPosition::Request &req, open_manipulator_msgs::GetJointPosition::Response &res)
int main(int argc, char **argv)
bool getKinematicsPoseMsgCallback(open_manipulator_msgs::GetKinematicsPose::Request &req, open_manipulator_msgs::GetKinematicsPose::Response &res)
void makeToolTrajectory(Name tool_name, double tool_goal_position)
void publishKinematicsPose()