Skip to content

Commit 7a7bf4a

Browse files
committed
M1 demo with ROS
1 parent b429ac5 commit 7a7bf4a

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

launch/m1_real.launch

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<launch>
3+
4+
<arg name="robot_name_1" default="m1_x"/>
5+
<arg name="name_spaces" default="[$(arg robot_name_1)]"/>
6+
7+
<!-- CORC M1_X -->
8+
<node name="$(arg robot_name_1)" pkg="CORC" type="MultiM1Machine_APP" output="screen" args="-can can0"/>
9+
10+
<!-- rqt -->
11+
<node name="rqt" pkg="CORC" type="rqt.sh">
12+
</node>
13+
14+
</launch>

src/apps/MultiM1Machine/states/MultiControllerState.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ void MultiControllerState::entry(void) {
4242
digitalInValue_ = 0;
4343
digitalOutValue_ = 0; //0
4444
robot_->setDigitalOut(digitalOutValue_);
45+
4546
}
47+
4648
void MultiControllerState::during(void) {
4749

4850
//Compute some basic time values
@@ -54,7 +56,6 @@ void MultiControllerState::during(void) {
5456
dt = now - lastTime;
5557
lastTime = now;
5658

57-
//
5859
tick_count = tick_count + 1;
5960
if(controller_mode_ == 0){ // Homing
6061
if(cali_stage == 1){
@@ -78,8 +79,7 @@ void MultiControllerState::during(void) {
7879
robot_->printJointStatus();
7980
}
8081
}
81-
else if(cali_stage == 2)
82-
{
82+
else if(cali_stage == 2){
8383
// set position control: 16 is vertical for #2; 45 is neutral position for random trajectory
8484
q(0) = 45; //16
8585
if(robot_->setJointPos(q) != SUCCESS){
@@ -106,7 +106,6 @@ void MultiControllerState::during(void) {
106106
}
107107
else if(controller_mode_ == 4){ // virtual spring - torque mode
108108
tau = robot_->getJointTor();
109-
//tau_s = (robot_->getJointTor_s()+tau_s)/2.0;
110109
dq = robot_->getJointVel();
111110

112111
// filter q
@@ -117,14 +116,13 @@ void MultiControllerState::during(void) {
117116
q = robot_->getJointPos();
118117
q_filtered = q(0);
119118

120-
// filter torque signal
119+
// filter torque signal
121120
tau_s = robot_->getJointTor_s();
122121
tau_raw = tau_s(0);
123122
alpha_tau = (2*M_PI*dt*cut_off)/(2*M_PI*dt*cut_off+1);
124123
robot_->filter_tau(alpha_tau);
125124
tau_s = robot_->getJointTor_s();
126125
tau_filtered = tau_s(0);
127-
// std::cout << "Pre :" << tau_raw << "; Post :" << tau_filtered << std::endl;
128126

129127
// get interaction torque from virtual spring
130128
spring_tor = -multiM1MachineRos_->interactionTorqueCommand_(0);
@@ -137,7 +135,6 @@ void MultiControllerState::during(void) {
137135
integral_error = integral_error + error/control_freq;
138136
tau_cmd(0) = error*kp_ + delta_error*kd_ + integral_error*ki_; // tau_cmd = P*error + D*delta_error; 1 and 0.001
139137
torque_error_last_time_step = error;
140-
// std::cout << "spring_tor:" << spring_tor << "; sensor_tor: " << tau_s(0) << "; cmd_tor: " << tau_cmd(0) << "; motor_tor: " << tau(0) << std::endl;
141138
robot_->setJointTor_comp(tau_cmd, tau_s, ffRatio_);
142139

143140
// reset integral_error every 1 mins, to be decided
@@ -159,7 +156,7 @@ void MultiControllerState::during(void) {
159156
q = robot_->getJointPos();
160157
q_filtered = q(0);
161158

162-
// filter torque signal
159+
// filter torque signal
163160
tau_s = robot_->getJointTor_s();
164161
tau_raw = tau_s(0);
165162
alpha_tau = (2*M_PI*dt*cut_off)/(2*M_PI*dt*cut_off+1);
@@ -183,7 +180,6 @@ void MultiControllerState::during(void) {
183180
}
184181
else if (controller_mode_ == 11){ // SEND HIGH
185182
// std::cout<<"SET HIGH"<<std::endl;
186-
187183
double time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - time0).count()/1000.0;
188184

189185
if(robot_->getRobotName() == "m1_y"){
@@ -204,7 +200,6 @@ void MultiControllerState::during(void) {
204200
}
205201
else if (controller_mode_ == 12){ // SEND LOW
206202
// std::cout<<"SET LOW"<<std::endl;
207-
208203
double time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - time0).count()/1000.0;
209204

210205
if(robot_->getRobotName() == "m1_y"){
@@ -253,7 +248,7 @@ void MultiControllerState::dynReconfCallback(CORC::dynamic_paramsConfig &config,
253248
tick_count = 0;
254249
}
255250

256-
// controller_mode_ = config.controller_mode;
251+
// change controller mode
257252
if(controller_mode_!=config.controller_mode)
258253
{
259254
controller_mode_ = config.controller_mode;

0 commit comments

Comments
 (0)