Skip to content

Commit da3b341

Browse files
committed
2 parents 6462c1e + 9b1ffeb commit da3b341

File tree

7 files changed

+866
-198
lines changed

7 files changed

+866
-198
lines changed

external/dynamixel-workbench/dynamixel_workbench_controllers/include/dynamixel_workbench_controllers/position_control.h

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,24 @@
2424
#include "message_header.h"
2525

2626
#include <sensor_msgs/JointState.h>
27+
// #include <std_msgs/Bool.h>
28+
#include <std_msgs/Empty.h>
29+
#include <std_msgs/Float64.h>
2730

2831
#include <dynamixel_workbench_toolbox/dynamixel_workbench.h>
2932
#include <dynamixel_workbench_msgs/DynamixelStateList.h>
3033
#include <dynamixel_workbench_msgs/JointCommand.h>
3134

35+
// Probably should make these constexpr
36+
#define GRIPPER_OPEN_MOTOR_POS -1.147412
37+
#define GRIPPER_CLOSE_MOTOR_POS 0.84368409
38+
#define GRIPPER_OPEN_MOVEIT -0.025
39+
#define GRIPPER_CLOSE_MOVEIT -0.002
40+
#define GRIPPER_OPEN_VALUE 2800
41+
#define GRIPPER_CLOSE_VALUE 1800
42+
#define GRIPPER_MAX_LOAD 500
43+
#define GRIPPER_PWM 500
44+
3245
class PositionControl
3346
{
3447
private:
@@ -37,40 +50,89 @@ class PositionControl
3750

3851
// ROS Parameters
3952

40-
// ROS Topic Publisher
53+
// ROS Topic Publishers
4154
ros::Publisher dynamixel_state_list_pub_;
4255
ros::Publisher joint_states_pub_;
56+
// ros::Publisher status_pub_;
57+
ros::Publisher pan_state_pub_;
58+
ros::Publisher tilt_state_pub_;
4359

4460
// ROS Topic Subscriber
4561
ros::Subscriber joint_command_sub_;
62+
ros::Subscriber gripper_open_sub_;
63+
ros::Subscriber gripper_close_sub_;
64+
ros::Subscriber pan_command_sub_;
65+
ros::Subscriber tilt_command_sub_;
4666

4767
// ROS Service Server
4868
ros::ServiceServer joint_command_server_;
4969

5070
// ROS Service Client
5171

52-
// Dynamixel Workbench Parameters
53-
DynamixelWorkbench *dxl_wb_;
54-
uint8_t dxl_id_[16];
55-
uint8_t dxl_cnt_;
72+
// Dynamixel Workbench (old)
73+
// DynamixelWorkbench *dxl_wb_;
74+
// uint8_t dxl_id_[16];
75+
// uint8_t dxl_cnt_;
76+
77+
// Dynamixel Workbench for arm
78+
DynamixelWorkbench *dxl_wb_arm_;
79+
uint8_t dxl_id_arm_[6];
80+
uint8_t dxl_cnt_arm_;
81+
82+
// Dynamixel Workbench for gripper
83+
DynamixelWorkbench *dxl_wb_gripper_;
84+
uint8_t dxl_id_gripper_[1];
85+
uint8_t dxl_cnt_gripper_;
86+
uint8_t gripper_state_;
87+
uint8_t prev_gripper_state_;
88+
uint8_t prev_gripper_load_;
89+
90+
// Dynamixel Workbench for camera
91+
DynamixelWorkbench *dxl_wb_camera_;
92+
uint8_t dxl_id_camera_[2];
93+
uint8_t dxl_cnt_camera_;
94+
95+
// Platforn configuration
96+
bool use_arm_;
97+
bool use_camera_;
98+
99+
// Controller parameters
100+
std::string device_name_;
101+
uint32_t dxl_baud_rate_;
102+
uint32_t profile_velocity_;
103+
uint32_t profile_acceleration_;
56104

57105
public:
58106
PositionControl();
59107
~PositionControl();
60108
void controlLoop(void);
109+
bool initLoCoBot();
61110

62111
private:
63-
void initMsg();
112+
bool initArm();
113+
bool initGripper();
114+
bool initCamera();
64115

65116
void initPublisher();
66117
void initSubscriber();
67118
void dynamixelStatePublish();
68119
void jointStatePublish();
120+
sensor_msgs::JointState getCurrentJointStates();
121+
float getCurrentMotorPosition(DynamixelWorkbench *dxl_wb, uint8_t id);
122+
float getCurrentMotorVelocity(DynamixelWorkbench *dxl_wb, uint8_t id);
123+
void getCurrentPV(std::vector<std::string>& jntNames,
124+
std::vector<float>& jntPos, std::vector<float>& jntVel, int index);
125+
void cameraStatePublish();
126+
void gripperController();
69127

70128
void initServer();
71-
bool jointCommandMsgCallback(dynamixel_workbench_msgs::JointCommand::Request &req,
72-
dynamixel_workbench_msgs::JointCommand::Response &res);
129+
// bool jointCommandMsgCallback(dynamixel_workbench_msgs::JointCommand::Request &req,
130+
// dynamixel_workbench_msgs::JointCommand::Response &res);
73131
void goalJointPositionCallback(const sensor_msgs::JointState::ConstPtr &msg);
132+
void gripperCloseCallback(const std_msgs::Empty::ConstPtr &msg);
133+
void gripperOpenCallback(const std_msgs::Empty::ConstPtr &msg);
134+
void panCommandCallback(const std_msgs::Float64::ConstPtr &msg);
135+
void tiltCommandCallback(const std_msgs::Float64::ConstPtr &msg);
74136
};
75137

76138
#endif //DYNAMIXEL_WORKBENCH_POSITION_CONTROL_H

0 commit comments

Comments
 (0)