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  1.0, // coefficient
50  9.8406837e-02, // mass
51  math::inertiaMatrix(3.4543422e-05, -1.6031095e-08, -3.8375155e-07,
52  3.2689329e-05, 2.8511935e-08,
53  1.8850320e-05), // inertial tensor
54  math::vector3(-3.0184870e-04, 5.4043684e-04, 0.018 + 2.9433464e-02) // COM
55  );
56 
57  addJoint("joint2", // my name
58  "joint1", // parent name
59  "joint3", // child name
60  math::vector3(0.0, 0.0, 0.0595), // relative position
61  math::convertRPYToRotationMatrix(0.0, 0.0, 0.0), // relative orientation
62  Y_AXIS, // axis of rotation
63  12, // actuator id
64  M_PI_2, // max joint limit (1.67 rad)
65  -2.05, // min joint limit (-2.05 rad)
66  1.0, // coefficient
67  1.3850917e-01, // mass
68  math::inertiaMatrix(3.3055381e-04, 9.7940978e-08, -3.8505711e-05,
69  3.4290447e-04, -1.5717516e-06,
70  6.0346498e-05), // inertial tensor
71  math::vector3(1.0308393e-02, 3.7743363e-04, 1.0170197e-01) // COM
72  );
73 
74  addJoint("joint3", // my name
75  "joint2", // parent name
76  "joint4", // child name
77  math::vector3(0.024, 0.0, 0.128), // relative position
78  math::convertRPYToRotationMatrix(0.0, 0.0, 0.0), // relative orientation
79  Y_AXIS, // axis of rotation
80  13, // actuator id
81  1.53, // max joint limit (1.53 rad)
82  -M_PI_2, // min joint limit (-1.67 rad)
83  1.0, // coefficient
84  1.3274562e-01, // mass
85  math::inertiaMatrix(3.0654178e-05, -1.2764155e-06, -2.6874417e-07,
86  2.4230292e-04, 1.1559550e-08,
87  2.5155057e-04), // inertial tensor
88  math::vector3(9.0909590e-02, 3.8929816e-04, 2.2413279e-04) // COM
89  );
90 
91  addJoint("joint4", // my name
92  "joint3", // parent name
93  "gripper", // child name
94  math::vector3(0.124, 0.0, 0.0), // relative position
95  math::convertRPYToRotationMatrix(0.0, 0.0, 0.0), // relative orientation
96  Y_AXIS, // axis of rotation
97  14, // actuator id
98  2.0, // max joint limit (2.0 rad)
99  -1.8, // min joint limit (-1.8 rad)
100  1.0, // coefficient
101  1.4327573e-01, // mass
102  math::inertiaMatrix(8.0870749e-05, 0.0, -1.0157896e-06,
103  7.5980465e-05, 0.0,
104  9.3127351e-05), // inertial tensor
105  math::vector3(4.4206755e-02, 3.6839985e-07, 8.9142216e-03) // COM
106  );
107 
108  addTool("gripper", // my name
109  "joint4", // parent name
110  math::vector3(0.126, 0.0, 0.0), // relative position
111  math::convertRPYToRotationMatrix(0.0, 0.0, 0.0), // relative orientation
112  15, // actuator id
113  0.010, // max gripper limit (0.01 m)
114  -0.010, // min gripper limit (-0.01 m)
115  -0.015, // Change unit from `meter` to `radian`
116  3.2218127e-02 * 2, // mass
117  math::inertiaMatrix(9.5568826e-06, 2.8424644e-06, -3.2829197e-10,
118  2.2552871e-05, -3.1463634e-10,
119  1.7605306e-05), // inertial tensor
120  math::vector3(0.028 + 8.3720668e-03, 0.0246, -4.2836895e-07) // COM
121  );
122 
123  /*****************************************************************************
124  ** Initialize Kinematics
125  *****************************************************************************/
127 // kinematics_ = new kinematics::SolverUsingCRAndSRPositionOnlyJacobian();
129 
130  if(using_actual_robot_state)
131  {
132  /*****************************************************************************
133  ** Initialize Joint Actuator
134  *****************************************************************************/
135  // actuator_ = new dynamixel::JointDynamixel();
136  actuator_ = new dynamixel::JointDynamixelProfileControl(control_loop_time);
137 
138  // Set communication arguments
139  STRING dxl_comm_arg[2] = {usb_port, baud_rate};
140  void *p_dxl_comm_arg = &dxl_comm_arg;
141 
142  // Set joint actuator id
143  std::vector<uint8_t> jointDxlId;
144  jointDxlId.push_back(11);
145  jointDxlId.push_back(12);
146  jointDxlId.push_back(13);
147  jointDxlId.push_back(14);
148  addJointActuator(JOINT_DYNAMIXEL, actuator_, jointDxlId, p_dxl_comm_arg);
149 
150  // Set joint actuator control mode
151  STRING joint_dxl_mode_arg = "position_mode";
152  void *p_joint_dxl_mode_arg = &joint_dxl_mode_arg;
153  setJointActuatorMode(JOINT_DYNAMIXEL, jointDxlId, p_joint_dxl_mode_arg);
154 
155 
156  /*****************************************************************************
157  ** Initialize Tool Actuator
158  *****************************************************************************/
160 
161  uint8_t gripperDxlId = 15;
162  addToolActuator(TOOL_DYNAMIXEL, tool_, gripperDxlId, p_dxl_comm_arg);
163 
164  // Set gripper actuator control mode
165  STRING gripper_dxl_mode_arg = "current_based_position_mode";
166  void *p_gripper_dxl_mode_arg = &gripper_dxl_mode_arg;
167  setToolActuatorMode(TOOL_DYNAMIXEL, p_gripper_dxl_mode_arg);
168 
169  // Set gripper actuator parameter
170  STRING gripper_dxl_opt_arg[2];
171  void *p_gripper_dxl_opt_arg = &gripper_dxl_opt_arg;
172  gripper_dxl_opt_arg[0] = "Profile_Acceleration";
173  gripper_dxl_opt_arg[1] = "20";
174  setToolActuatorMode(TOOL_DYNAMIXEL, p_gripper_dxl_opt_arg);
175 
176  gripper_dxl_opt_arg[0] = "Profile_Velocity";
177  gripper_dxl_opt_arg[1] = "200";
178  setToolActuatorMode(TOOL_DYNAMIXEL, p_gripper_dxl_opt_arg);
179 
180  // Enable All Actuators
182 
183  // Receive current angles from all actuators
186  }
187 
188  /*****************************************************************************
189  ** Initialize Custom Trajectory
190  *****************************************************************************/
195 
200 }
201 
203 {
204  // Planning (ik)
205  JointWaypoint goal_joint_value = getJointGoalValueFromTrajectory(present_time);
206  JointWaypoint goal_tool_value = getToolGoalValue();
207 
208  // Control (motor)
211 
212  if(goal_joint_value.size() != 0) sendAllJointActuatorValue(goal_joint_value);
213  if(goal_tool_value.size() != 0) sendAllToolActuatorValue(goal_tool_value);
214 
215  // Perception (fk)
217 }
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 object_mass=0.0, Eigen::Matrix3d object_inertia_tensor=Eigen::Matrix3d::Identity(), Eigen::Vector3d object_center_of_mass=Eigen::Vector3d::Zero())
std::vector< JointValue > getToolGoalValue()
std::vector< JointValue > receiveAllToolActuatorValue()
std::vector< JointValue > getJointGoalValueFromTrajectory(double present_time, int option=DYNAMICS_ALL_SOVING)
#define CUSTOM_TRAJECTORY_CIRCLE
void processOpenManipulator(double present_time)
robotis_manipulator::ToolActuator * tool_
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(), double torque_coefficient=1.0)
#define Y_AXIS
robotis_manipulator::JointActuator * actuator_
std::vector< JointValue > JointWaypoint
#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)
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 Feb 28 2022 23:02:19