@@ -55,6 +55,7 @@ ODriverNode::ODriverNode(rclcpp::NodeOptions options)
55
55
56
56
targetRate_(40 ),
57
57
maxAcc_(0.5 ),
58
+ maxDec_(-0.5 ),
58
59
59
60
bias_(0 ),
60
61
wheel_diameter_(0 ),
@@ -95,6 +96,7 @@ ODriverNode::ODriverNode(rclcpp::NodeOptions options)
95
96
imuSub = create_subscription<sensor_msgs::msg::Imu>(" /imu" , rclcpp::SensorDataQoS (), std::bind (&ODriverNode::imuCallback, this , _1));
96
97
97
98
maxAcc_ = declare_parameter (" max_acc" , maxAcc_);
99
+ maxDec_ = declare_parameter (" max_dec" , maxDec_);
98
100
targetRate_ = declare_parameter (" target_rate" , targetRate_);
99
101
motorOutput_ = declare_parameter (" motor_topic" , motorOutput_);
100
102
@@ -125,23 +127,35 @@ void ODriverNode::cmdVelLoop(int publishRate)
125
127
126
128
motorPub = create_publisher<odriver_msgs::msg::MotorTarget>(motorOutput_, 10 );
127
129
128
- double minimumStep = maxAcc_ / publishRate;
130
+ double maxAccStep = maxAcc_ / publishRate;
131
+ double maxDecStep = maxDec_ / publishRate;
129
132
130
133
while (rclcpp::ok ()) {
131
134
odriver_msgs::msg::MotorTarget target;
132
135
133
136
double targetL = targetSpdLinear_;
134
137
double targetT = targetSpdTurn_;
135
138
136
- // change linear speed by maximum acc rate
137
- double lDiff = targetL - currentSpdLinear_;
138
- if (fabs (lDiff) < minimumStep) {
139
- currentSpdLinear_ = targetL;
139
+ if (targetL == 0.0 ) {
140
+ // change linear speed by maximum dec rate, if the control is zero (maybe not specified)
141
+ double lDiff = targetL - currentSpdLinear_;
142
+ if (fabs (lDiff) < fabs (maxDecStep)) {
143
+ currentSpdLinear_ = targetL;
144
+ } else {
145
+ currentSpdLinear_ -= maxDecStep * lDiff / fabs (lDiff);
146
+ }
140
147
} else {
141
- currentSpdLinear_ += minimumStep * lDiff / fabs (lDiff);
148
+ // change linear speed by maximum acc rate
149
+ double lDiff = targetL - currentSpdLinear_;
150
+ if (fabs (lDiff) < maxAccStep) {
151
+ currentSpdLinear_ = targetL;
152
+ } else {
153
+ currentSpdLinear_ += maxAccStep * lDiff / fabs (lDiff);
154
+ }
142
155
}
143
156
144
157
// adjust angular speed
158
+ target.header .stamp = get_clock ()->now ();
145
159
target.spd_left = currentSpdLinear_ - targetT;
146
160
target.spd_right = currentSpdLinear_ + targetT;
147
161
@@ -188,10 +202,10 @@ void ODriverNode::cmdVelLoop(int publishRate)
188
202
} else {
189
203
// reduce current speed to zero at maximum acc rate when feedback is disabled
190
204
double lDiff = 0.0 - currentSpdLinear_;
191
- if (fabs (lDiff) < minimumStep ) {
205
+ if (fabs (lDiff) < fabs (maxDecStep) ) {
192
206
currentSpdLinear_ = 0.0 ;
193
207
} else {
194
- currentSpdLinear_ += minimumStep * lDiff / fabs (lDiff);
208
+ currentSpdLinear_ -= maxDecStep * lDiff / fabs (lDiff);
195
209
}
196
210
197
211
// reset integrator when feedback is disabled
0 commit comments