1
1
//
2
- // Created by yuchen on 2023/4/3 .
2
+ // Created by kook on 9/28/24 .
3
3
//
4
4
5
5
#include " rm_manual/balance_manual.h"
@@ -10,21 +10,9 @@ BalanceManual::BalanceManual(ros::NodeHandle& nh, ros::NodeHandle& nh_referee)
10
10
: ChassisGimbalShooterCoverManual(nh, nh_referee)
11
11
{
12
12
ros::NodeHandle balance_nh (nh, " balance" );
13
- balance_cmd_sender_ = new rm_common::BalanceCommandSender (balance_nh);
14
- balance_cmd_sender_->setBalanceMode (rm_msgs::BalanceState::NORMAL);
15
-
16
- nh.param (" flank_frame" , flank_frame_, std::string (" flank_frame" ));
17
- nh.param (" reverse_frame" , reverse_frame_, std::string (" yaw_reverse_frame" ));
18
- nh.param (" balance_dangerous_angle" , balance_dangerous_angle_, 0.3 );
19
-
13
+ balance_nh.param (" flank_frame" , flank_frame_, std::string (" flank_frame" ));
14
+ balance_nh.param (" reverse_frame" , reverse_frame_, std::string (" yaw_reverse_frame" ));
20
15
is_balance_ = true ;
21
- state_sub_ = balance_nh.subscribe <rm_msgs::BalanceState>(" /state" , 1 , &BalanceManual::balanceStateCallback, this );
22
- x_event_.setRising (boost::bind (&BalanceManual::xPress, this ));
23
- g_event_.setRising (boost::bind (&BalanceManual::gPress , this ));
24
- v_event_.setRising (boost::bind (&BalanceManual::vPress, this ));
25
- auto_fallen_event_.setActiveHigh (boost::bind (&BalanceManual::modeFallen, this , _1));
26
- auto_fallen_event_.setDelayTriggered (boost::bind (&BalanceManual::modeNormalize, this ), 1.5 , true );
27
- ctrl_x_event_.setRising (boost::bind (&BalanceManual::ctrlXPress, this ));
28
16
}
29
17
30
18
void BalanceManual::sendCommand (const ros::Time& time)
@@ -49,14 +37,11 @@ void BalanceManual::sendCommand(const ros::Time& time)
49
37
50
38
ChassisGimbalShooterManual::sendCommand (time);
51
39
cover_command_sender_->sendCommand (time);
52
- balance_cmd_sender_->sendCommand (time);
53
40
}
54
41
55
42
void BalanceManual::checkKeyboard (const rm_msgs::DbusData::ConstPtr& dbus_data)
56
43
{
57
44
ChassisGimbalShooterCoverManual::checkKeyboard (dbus_data);
58
- v_event_.update (dbus_data->key_v && !dbus_data->key_ctrl );
59
- ctrl_x_event_.update (dbus_data->key_ctrl && dbus_data->key_x );
60
45
}
61
46
62
47
void BalanceManual::updateRc (const rm_msgs::DbusData::ConstPtr& dbus_data)
@@ -72,15 +57,13 @@ void BalanceManual::rightSwitchDownRise()
72
57
{
73
58
ChassisGimbalShooterCoverManual::rightSwitchDownRise ();
74
59
state_ = RC;
75
- balance_cmd_sender_->setBalanceMode (rm_msgs::BalanceState::FALLEN);
76
60
chassis_cmd_sender_->setMode (rm_msgs::ChassisCmd::FALLEN);
77
61
chassis_cmd_sender_->power_limit_ ->updateState (rm_common::PowerLimit::CHARGE);
78
62
}
79
63
80
64
void BalanceManual::rightSwitchMidRise ()
81
65
{
82
66
ChassisGimbalShooterCoverManual::rightSwitchMidRise ();
83
- balance_cmd_sender_->setBalanceMode (rm_msgs::BalanceState::NORMAL);
84
67
chassis_cmd_sender_->setMode (rm_msgs::ChassisCmd::FOLLOW);
85
68
chassis_cmd_sender_->power_limit_ ->updateState (rm_common::PowerLimit::BURST);
86
69
}
@@ -90,13 +73,11 @@ void BalanceManual::ctrlZPress()
90
73
ChassisGimbalShooterCoverManual::ctrlZPress ();
91
74
if (supply_)
92
75
{
93
- balance_cmd_sender_->setBalanceMode (rm_msgs::BalanceState::FALLEN);
94
76
chassis_cmd_sender_->setMode (rm_msgs::ChassisCmd::FALLEN);
95
77
chassis_cmd_sender_->power_limit_ ->updateState (rm_common::PowerLimit::CHARGE);
96
78
}
97
79
else
98
80
{
99
- balance_cmd_sender_->setBalanceMode (rm_msgs::BalanceState::NORMAL);
100
81
chassis_cmd_sender_->setMode (rm_msgs::ChassisCmd::FOLLOW);
101
82
chassis_cmd_sender_->power_limit_ ->updateState (rm_common::PowerLimit::BURST);
102
83
}
@@ -111,18 +92,7 @@ void BalanceManual::shiftPress()
111
92
{
112
93
ChassisGimbalShooterCoverManual::shiftPress ();
113
94
chassis_cmd_sender_->setMode (rm_msgs::ChassisCmd::UP_SLOPE);
114
- chassis_cmd_sender_->updateSafetyPower (60 );
115
- }
116
-
117
- void BalanceManual::vPress ()
118
- {
119
- chassis_cmd_sender_->updateSafetyPower (80 );
120
- }
121
-
122
- void BalanceManual::bPress ()
123
- {
124
- ChassisGimbalShooterCoverManual::bPress ();
125
- chassis_cmd_sender_->updateSafetyPower (100 );
95
+ chassis_cmd_sender_->updateSafetyPower (220 );
126
96
}
127
97
128
98
void BalanceManual::wPress ()
@@ -197,54 +167,13 @@ void BalanceManual::cPress()
197
167
{
198
168
if (is_gyro_)
199
169
{
200
- chassis_cmd_sender_->setMode (rm_msgs::ChassisCmd::FOLLOW);
201
- vel_cmd_sender_->setAngularZVel (0.0 );
202
- is_gyro_ = false ;
170
+ setChassisMode (rm_msgs::ChassisCmd::FOLLOW);
203
171
}
204
172
else
205
173
{
206
- chassis_cmd_sender_->setMode (rm_msgs::ChassisCmd::RAW);
207
- is_gyro_ = true ;
208
- if (x_scale_ != 0.0 || y_scale_ != 0.0 )
209
- vel_cmd_sender_->setAngularZVel (gyro_rotate_reduction_);
210
- else
211
- vel_cmd_sender_->setAngularZVel (1.0 );
174
+ setChassisMode (rm_msgs::ChassisCmd::RAW);
175
+ chassis_cmd_sender_->power_limit_ ->updateState (rm_common::PowerLimit::NORMAL);
212
176
}
213
177
}
214
178
215
- void BalanceManual::ctrlXPress ()
216
- {
217
- if (balance_cmd_sender_->getMsg ()->data == rm_msgs::BalanceState::NORMAL)
218
- balance_cmd_sender_->setBalanceMode (rm_msgs::BalanceState::FALLEN);
219
- else
220
- balance_cmd_sender_->setBalanceMode (rm_msgs::BalanceState::NORMAL);
221
- }
222
-
223
- void BalanceManual::balanceStateCallback (const rm_msgs::BalanceState::ConstPtr& msg)
224
- {
225
- if ((ros::Time::now () - msg->header .stamp ).toSec () < 0.2 )
226
- {
227
- if (std::abs (msg->theta ) > balance_dangerous_angle_)
228
- chassis_cmd_sender_->power_limit_ ->updateState (rm_common::PowerLimit::BURST);
229
- if (msg->mode == rm_msgs::BalanceState::NORMAL)
230
- auto_fallen_event_.update (std::abs (msg->theta ) > 0.42 && std::abs (msg->x_dot ) > 1.5 &&
231
- vel_cmd_sender_->getMsg ()->linear .x == 0 && vel_cmd_sender_->getMsg ()->linear .y == 0 &&
232
- vel_cmd_sender_->getMsg ()->angular .z == 0 );
233
- }
234
- }
235
-
236
- void BalanceManual::modeNormalize ()
237
- {
238
- balance_cmd_sender_->setBalanceMode (rm_msgs::BalanceState::NORMAL);
239
- ROS_INFO (" mode normalize" );
240
- }
241
-
242
- void BalanceManual::modeFallen (ros::Duration duration)
243
- {
244
- if (duration.toSec () > 0.3 )
245
- {
246
- balance_cmd_sender_->setBalanceMode (rm_msgs::BalanceState::FALLEN);
247
- ROS_INFO (" mode fallen" );
248
- }
249
- }
250
179
} // namespace rm_manual
0 commit comments