Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Commit de174e5

Browse files
committed
add gripper control in the mra_basic package
1 parent 6409f35 commit de174e5

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CMakeLists.txt.user
2+
qtbuild/
3+
.idea
4+
.idea/
5+
sender
6+
libIKOptimalHandler.so
7+
.DS_Store

mra_basic/include/mra_basic/config.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace mra_basic_config {
88
//const std::string DEFAULT_NODE = "/dev/pcanusb32"; //use:DEFAULT_NODE.c_str()
99
#define DEFAULT_NODE "/dev/pcanusb32"
1010
const std::vector<int> jointID{21,22,23,24,25,26,27};
11+
const int GRIPPER_ID = 18;
1112
const std::vector<std::string> joint_names{"Joint1","Joint2","Joint3","Joint4","Joint5","Joint6","Joint7"};
1213

1314
#define CONTROL_RATE 100 //100HZ
@@ -18,7 +19,7 @@ const std::vector<std::string> joint_names{"Joint1","Joint2","Joint3","Joint4","
1819
#define JOINT_COMMAND_TOPIC "/mra/joint_command" //-->sub joint control command
1920
#define JOINT_POSITION_COMMAND_TOPIC "/moveJ" //-->sub joint control command
2021
#define RESET_MRA_API_TOPIC "/mra/reset_MRA_API" //-->sub, When canbus interrupts, we need to reset MRA_API after reconnecting the usb-can.
21-
22+
#define GRIPPER_COMMAND "/mra/gripper_command"
2223

2324
/*Position controll topic*/
2425
#define JOINT1_POSITION_CONTROLLER "/mra7a/joint1_position_controller/command"

mra_basic/src/joint_control/joint_control.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@
4242
#include <mra_core_msgs/AssemblyState.h>
4343
#include <mra_core_msgs/JointCommand.h>
4444
#include <std_msgs/Bool.h>
45+
#include <std_msgs/Int8.h>
4546

4647
using namespace mra_basic_config;
4748
using namespace std;
4849

4950
UserControlOnCan *userControlOnCan;
51+
Gripper *gripper;
5052
mra_core_msgs::AssemblyState mra_state;
5153

5254
void show_ID_in_current_canbus()
@@ -103,6 +105,14 @@ void moveJ_callback(const std_msgs::Float32MultiArray::ConstPtr &msg)
103105
}
104106
}
105107

108+
void gripper_command_callback(const std_msgs::Int8ConstPtr &msg){
109+
if(gripper != NULL){
110+
ROS_INFO("Gripper work on %d", msg->data);
111+
gripper->setFingerTagOpenStatus(msg->data);
112+
}
113+
114+
}
115+
106116
void MRA_API_INIT(const std_msgs::Bool &reset) {
107117

108118
userControlOnCan = new UserControlOnCan();
@@ -118,6 +128,9 @@ void MRA_API_INIT(const std_msgs::Bool &reset) {
118128
userControlOnCan->controller.GetErrorText(s);
119129
ROS_ERROR("Can't Open the pcanusb32:%s",s.c_str());
120130
}
131+
if(userControlOnCan->controller.allGripper.size() != 0){
132+
gripper = userControlOnCan->findGripperID(mra_basic_config::GRIPPER_ID);
133+
}
121134
}
122135

123136
int main(int argc, char **argv)
@@ -149,6 +162,8 @@ int main(int argc, char **argv)
149162
ros::Publisher state_pub = n.advertise<mra_core_msgs::AssemblyState> (STATE_TOPIC, 1);
150163
/*sub reset */
151164
ros::Subscriber sub_reset_MRA_API = n.subscribe(RESET_MRA_API_TOPIC, 10, &MRA_API_INIT);
165+
/*sub gripper command*/
166+
ros::Subscriber sub_gripper_command = n.subscribe(GRIPPER_COMMAND, 1, &gripper_command_callback);
152167

153168

154169
sensor_msgs::JointState joint_state;

0 commit comments

Comments
 (0)