open_manipulator.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2018 ROBOTIS CO., LTD.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16 
17 /* Authors: Darby Lim, Hye-Jong KIM, Ryan Shim, Yong-Ho Na */
18 
19 #include "../include/open_manipulator_libs/open_manipulator.h"
20 
22 {}
24 {
25  delete kinematics_;
26  delete actuator_;
27  delete tool_;
28  for(uint8_t index = 0; index < CUSTOM_TRAJECTORY_SIZE; index++)
29  delete custom_trajectory_[index];
30 }
31 
32 void OpenManipulator::initOpenManipulator(bool using_actual_robot_state, STRING usb_port, STRING baud_rate, float control_loop_time)
33 {
34  /*****************************************************************************
35  ** Initialize Manipulator Parameter
36  *****************************************************************************/
37  addWorld("world", // world name
38  "joint1"); // child name
39 
40  addJoint("joint1", // my name
41  "world", // parent name
42  "joint2", // child name
43  math::vector3(0.012, 0.0, 0.017), // relative position
44  math::convertRPYToRotationMatrix(0.0, 0.0, 0.0), // relative orientation
45  Z_AXIS, // axis of rotation
46  11, // actuator id
47  M_PI, // max joint limit (3.14 rad)
48  -M_PI); // min joint limit (-3.14 rad)
49 
50  addJoint("joint2", // my name
51  "joint1", // parent name
52  "joint3", // child name
53  math::vector3(0.0, 0.0, 0.0595), // relative position
54  math::convertRPYToRotationMatrix(0.0, 0.0, 0.0), // relative orientation
55  Y_AXIS, // axis of rotation
56  12, // actuator id
57  M_PI_2, // max joint limit (1.67 rad)
58  -2.05); // min joint limit (-2.05 rad)
59 
60  addJoint("joint3", // my name
61  "joint2", // parent name
62  "joint4", // child name
63  math::vector3(0.024, 0.0, 0.128), // relative position
64  math::convertRPYToRotationMatrix(0.0, 0.0, 0.0), // relative orientation
65  Y_AXIS, // axis of rotation
66  13, // actuator id
67  1.53, // max joint limit (1.53 rad)
68  -M_PI_2); // min joint limit (-1.67 rad)
69 
70  addJoint("joint4", // my name
71  "joint3", // parent name
72  "gripper", // child name
73  math::vector3(0.124, 0.0, 0.0), // relative position
74  math::convertRPYToRotationMatrix(0.0, 0.0, 0.0), // relative orientation
75  Y_AXIS, // axis of rotation
76  14, // actuator id
77  2.0, // max joint limit (2.0 rad)
78  -1.8); // min joint limit (-1.8 rad)
79 
80  addTool("gripper", // my name
81  "joint4", // parent name
82  math::vector3(0.126, 0.0, 0.0), // relative position
83  math::convertRPYToRotationMatrix(0.0, 0.0, 0.0), // relative orientation
84  15, // actuator id
85  0.010, // max gripper limit (0.01 m)
86  -0.010, // min gripper limit (-0.01 m)
87  -0.015); // Change unit from `meter` to `radian`
88 
89 
90  /*****************************************************************************
91  ** Initialize Kinematics
92  *****************************************************************************/
94 // kinematics_ = new kinematics::SolverUsingCRAndSRPositionOnlyJacobian();
96 
97  if(using_actual_robot_state)
98  {
99  /*****************************************************************************
100  ** Initialize Joint Actuator
101  *****************************************************************************/
102  // actuator_ = new dynamixel::JointDynamixel();
103  actuator_ = new dynamixel::JointDynamixelProfileControl(control_loop_time);
104 
105  // Set communication arguments
106  STRING dxl_comm_arg[2] = {usb_port, baud_rate};
107  void *p_dxl_comm_arg = &dxl_comm_arg;
108 
109  // Set joint actuator id
110  std::vector<uint8_t> jointDxlId;
111  jointDxlId.push_back(11);
112  jointDxlId.push_back(12);
113  jointDxlId.push_back(13);
114  jointDxlId.push_back(14);
115  addJointActuator(JOINT_DYNAMIXEL, actuator_, jointDxlId, p_dxl_comm_arg);
116 
117  // Set joint actuator control mode
118  STRING joint_dxl_mode_arg = "position_mode";
119  void *p_joint_dxl_mode_arg = &joint_dxl_mode_arg;
120  setJointActuatorMode(JOINT_DYNAMIXEL, jointDxlId, p_joint_dxl_mode_arg);
121 
122 
123  /*****************************************************************************
124  ** Initialize Tool Actuator
125  *****************************************************************************/
127 
128  uint8_t gripperDxlId = 15;
129  addToolActuator(TOOL_DYNAMIXEL, tool_, gripperDxlId, p_dxl_comm_arg);
130 
131  // Set gripper actuator control mode
132  STRING gripper_dxl_mode_arg = "current_based_position_mode";
133  void *p_gripper_dxl_mode_arg = &gripper_dxl_mode_arg;
134  setToolActuatorMode(TOOL_DYNAMIXEL, p_gripper_dxl_mode_arg);
135 
136  // Set gripper actuator parameter
137  STRING gripper_dxl_opt_arg[2];
138  void *p_gripper_dxl_opt_arg = &gripper_dxl_opt_arg;
139  gripper_dxl_opt_arg[0] = "Profile_Acceleration";
140  gripper_dxl_opt_arg[1] = "20";
141  setToolActuatorMode(TOOL_DYNAMIXEL, p_gripper_dxl_opt_arg);
142 
143  gripper_dxl_opt_arg[0] = "Profile_Velocity";
144  gripper_dxl_opt_arg[1] = "200";
145  setToolActuatorMode(TOOL_DYNAMIXEL, p_gripper_dxl_opt_arg);
146 
147  // Enable All Actuators
149 
150  // Receive current angles from all actuators
153  }
154 
155  /*****************************************************************************
156  ** Initialize Custom Trajectory
157  *****************************************************************************/
162 
167 }
168 
170 {
171  JointWaypoint goal_joint_value = getJointGoalValueFromTrajectory(present_time);
172  JointWaypoint goal_tool_value = getToolGoalValue();
173 
176  if(goal_joint_value.size() != 0) sendAllJointActuatorValue(goal_joint_value);
177  if(goal_tool_value.size() != 0) sendAllToolActuatorValue(goal_tool_value);
179 }
std::vector< JointValue > getToolGoalValue()
std::vector< JointValue > receiveAllToolActuatorValue()
#define CUSTOM_TRAJECTORY_CIRCLE
void addJoint(Name my_name, Name parent_name, Name child_name, Eigen::Vector3d relative_position, Eigen::Matrix3d relative_orientation, Eigen::Vector3d axis_of_rotation=Eigen::Vector3d::Zero(), int8_t joint_actuator_id=-1, double max_position_limit=M_PI, double min_position_limit=-M_PI, double coefficient=1.0, double mass=0.0, Eigen::Matrix3d inertia_tensor=Eigen::Matrix3d::Identity(), Eigen::Vector3d center_of_mass=Eigen::Vector3d::Zero())
void processOpenManipulator(double present_time)
robotis_manipulator::ToolActuator * tool_
#define Y_AXIS
robotis_manipulator::JointActuator * actuator_
std::vector< JointValue > JointWaypoint
void addTool(Name my_name, Name parent_name, Eigen::Vector3d relative_position, Eigen::Matrix3d relative_orientation, int8_t tool_id=-1, double max_position_limit=M_PI, double min_position_limit=-M_PI, double coefficient=1.0, double mass=0.0, Eigen::Matrix3d inertia_tensor=Eigen::Matrix3d::Identity(), Eigen::Vector3d center_of_mass=Eigen::Vector3d::Zero())
#define Z_AXIS
std::vector< JointValue > receiveAllJointActuatorValue()
void setToolActuatorMode(Name actuator_name, const void *arg)
#define CUSTOM_TRAJECTORY_HEART
virtual ~OpenManipulator()
#define JOINT_DYNAMIXEL
robotis_manipulator::Kinematics * kinematics_
bool sendAllToolActuatorValue(std::vector< JointValue > value_vector)
bool sendAllJointActuatorValue(std::vector< JointValue > value_vector)
std::vector< JointValue > getJointGoalValueFromTrajectory(double present_time)
void initOpenManipulator(bool using_actual_robot_state, STRING usb_port="/dev/ttyUSB0", STRING baud_rate="1000000", float control_loop_time=0.010)
#define TOOL_DYNAMIXEL
#define CUSTOM_TRAJECTORY_LINE
#define CUSTOM_TRAJECTORY_SIZE
#define CUSTOM_TRAJECTORY_RHOMBUS
void addCustomTrajectory(Name trajectory_name, CustomJointTrajectory *custom_trajectory)
void addKinematics(Kinematics *kinematics)
void addJointActuator(Name actuator_name, JointActuator *joint_actuator, std::vector< uint8_t > id_array, const void *arg)
void setJointActuatorMode(Name actuator_name, std::vector< uint8_t > id_array, const void *arg)
robotis_manipulator::CustomTaskTrajectory * custom_trajectory_[CUSTOM_TRAJECTORY_SIZE]
std::string STRING
void addWorld(Name world_name, Name child_name, Eigen::Vector3d world_position=Eigen::Vector3d::Zero(), Eigen::Matrix3d world_orientation=Eigen::Matrix3d::Identity())
void addToolActuator(Name tool_name, ToolActuator *tool_actuator, uint8_t id, const void *arg)


open_manipulator_libs
Author(s): Darby Lim , Hye-Jong KIM , Ryan Shim , Yong-Ho Na
autogenerated on Mon Jun 10 2019 14:12:00