Skip to content

Commit 597b9f3

Browse files
committed
agv chassis strange bug
1 parent f0a9d24 commit 597b9f3

File tree

7 files changed

+87
-21
lines changed

7 files changed

+87
-21
lines changed

decomposition/meta_chassis_controller/include/meta_chassis_controller/agv_chassis_controller.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class AgvChassisController : public controller_interface::ChainableControllerInt
6868

6969
std::shared_ptr<control_toolbox::PidROS> follow_pid_;
7070

71+
std::shared_ptr<control_toolbox::PidROS> steer_pos2vel_pid_;
72+
std::shared_ptr<control_toolbox::PidROS> steer_vel2eff_pid_;
73+
7174
rclcpp::Duration ref_timeout_ = rclcpp::Duration(0, 0);
7275
rclcpp::Subscription<ControllerReferenceMsgUnstamped>::SharedPtr twist_sub_;
7376
realtime_tools::RealtimeBuffer<std::shared_ptr<ControllerReferenceMsg>> ref_buf_;

decomposition/meta_chassis_controller/src/agv_chassis_controller.cpp

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ AgvChassisController::on_configure(const rclcpp_lifecycle::State & /*previous_st
6868
std::fill(wheels_vel_.begin(), wheels_vel_.end(), 0);
6969
std::fill(wheels_pos_.begin(), wheels_pos_.end(), 0);
7070

71+
// Initialize PIDs
72+
steer_pos2vel_pid_ = std::make_shared<control_toolbox::PidROS>(
73+
get_node(), "steer_pos2vel_gains", true);
74+
75+
if (!steer_pos2vel_pid_->initPid()) {
76+
RCLCPP_ERROR(get_node()->get_logger(), "Failed to initialize PID for pos2vel");
77+
return controller_interface::CallbackReturn::FAILURE;
78+
}
79+
80+
steer_vel2eff_pid_ = std::make_shared<control_toolbox::PidROS>(
81+
get_node(), "steer_vel2eff_gains", true);
82+
83+
if (!steer_vel2eff_pid_->initPid()) {
84+
RCLCPP_ERROR(get_node()->get_logger(), "Failed to initialize PID for vel2eff");
85+
return controller_interface::CallbackReturn::FAILURE;
86+
}
87+
7188
// topics QoS
7289
auto subscribers_qos = rclcpp::SystemDefaultsQoS();
7390
subscribers_qos.keep_last(1);
@@ -142,6 +159,7 @@ AgvChassisController::command_interface_configuration() const {
142159
}
143160
for (const auto &joint : params_.agv_pos_joints) {
144161
command_interfaces_config.names.push_back(joint + "/" + HW_IF_EFFORT);
162+
std::cout << "command interfaces: " << params_.agv_vel_joints.size() + params_.agv_pos_joints.size() << std::endl;
145163
}
146164

147165
return command_interfaces_config;
@@ -154,10 +172,22 @@ AgvChassisController::state_interface_configuration() const {
154172
controller_interface::interface_configuration_type::INDIVIDUAL;
155173

156174
// Joint position state of yaw gimbal is required
157-
state_interfaces_config.names.reserve(1);
175+
state_interfaces_config.names.reserve(9);
158176
state_interfaces_config.names.push_back(params_.yaw_gimbal_joint + "/" +
159177
HW_IF_POSITION);
160178

179+
for(const auto &joint : params_.agv_pos_joints){
180+
state_interfaces_config.names.push_back(joint + "/" +
181+
HW_IF_POSITION);
182+
}
183+
184+
for(const auto &joint : params_.agv_pos_joints){
185+
state_interfaces_config.names.push_back(joint + "/" +
186+
HW_IF_VELOCITY);
187+
std::cout <<"state interfaces: " << joint << std::endl;
188+
}
189+
190+
161191
return state_interfaces_config;
162192
}
163193

@@ -268,11 +298,22 @@ AgvChassisController::update_and_write_commands(const rclcpp::Time &time,
268298
return controller_interface::return_type::ERROR;
269299
}
270300

271-
agv_wheel_kinematics_->inverse(twist, wheels_pos_, wheels_vel_);
301+
// agv_wheel_kinematics_->inverse(twist, wheels_pos_, wheels_vel_);
302+
303+
for(int i = 0; i < params_.agv_pos_joints.size(); i++){ // FIXME: Magical Number
304+
double steer_pos_ref = wheels_pos_[static_cast<Eigen::Index>(i)];
305+
double steer_pos_fb = state_interfaces_[1 + i].get_value();
306+
double steer_vel_fb = state_interfaces_[1 + i + params_.agv_pos_joints.size()].get_value();
307+
double steer_pos_err = angles::shortest_angular_distance(steer_pos_fb, steer_pos_ref);
308+
double steer_vel_ref = steer_pos2vel_pid_->computeCommand(steer_pos_err, period);
309+
double steer_vel_err = steer_vel_ref - steer_vel_fb;
310+
double steer_eff_cmd = steer_vel2eff_pid_->computeCommand(steer_vel_err, period);
311+
command_interfaces_[i + params_.agv_vel_joints.size()].set_value(steer_eff_cmd);
312+
}
272313

273-
for (size_t i = 0; i < 4; i++) {
314+
for (size_t i = 0; i < params_.agv_pos_joints.size(); i++) {
274315
command_interfaces_[i].set_value(wheels_vel_[static_cast<Eigen::Index>(i)]);
275-
command_interfaces_[i + 4].set_value(wheels_pos_[static_cast<Eigen::Index>(i)]);
316+
276317
}
277318
}
278319

decomposition/meta_chassis_controller/src/agv_chassis_controller.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,17 @@ agv_chassis_controller:
5050
default_value: 0.0,
5151
description: "Specifies target of the follow PID controller. Setting 0.0 meaning the car is always moving towards the front. Usually 0.7853981634(45 degree) gives the maximum speed.",
5252
}
53+
steer_pos2vel_gains:
54+
{
55+
type: double,
56+
default_value: 0.0,
57+
description: "Specifies target of the follow PID controller. Setting 0.0 meaning the car is always moving towards the front. Usually 0.7853981634(45 degree) gives the maximum speed.",
58+
}
59+
steer_vel2eff_gains:
60+
{
61+
type: double,
62+
default_value: 0.0,
63+
description: "Specifies target of the follow PID controller. Setting 0.0 meaning the car is always moving towards the front. Usually 0.7853981634(45 degree) gives the maximum speed.",
64+
}
5365
reference_timeout:
5466
{ type: double, default_value: 0.1, description: "Specifies timeout for the reference." }

decomposition/metav_description/urdf/common/steer_wheel.xacro

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@
6363

6464
</xacro:macro>
6565

66-
<xacro:macro name="wheel_transmission" params="prefix mechanical_reduction motor_id">
66+
<xacro:macro name="wheel_transmission" params="prefix mechanical_reduction vel_motor_id pos_motor_id pos_offset">
6767
<joint name="${prefix}_vel_joint">
6868
<command_interface name="effort">
6969
</command_interface>
7070
<state_interface name="position" />
7171
<state_interface name="velocity" />
7272
<state_interface name="effort" />
7373
<param name="motor_model">M3508</param>
74-
<param name="motor_id">${motor_id}</param>
74+
<param name="motor_id">${vel_motor_id}</param>
7575
<param name="mechanical_reduction">${mechanical_reduction}</param>
7676
<param name="offset">0.0</param>
7777
</joint>
@@ -82,9 +82,9 @@
8282
<state_interface name="velocity" />
8383
<state_interface name="effort" />
8484
<param name="motor_model">GM6020</param>
85-
<param name="motor_id">${motor_id}</param>
86-
<param name="mechanical_reduction">${mechanical_reduction}</param>
87-
<param name="offset">0.0</param>
85+
<param name="motor_id">${pos_motor_id}</param>
86+
<param name="mechanical_reduction">1</param>
87+
<param name="offset">${pos_offset}</param>
8888
</joint>
8989
</xacro:macro>
9090
</robot>

decomposition/metav_description/urdf/sentry25/sentry.xacro

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@
3939
<ros2_control name="dji_motors" type="system">
4040
<hardware>
4141
<plugin>meta_hardware/MetaRobotDjiMotorNetwork</plugin>
42-
<param name="can_network_name">can1</param>
42+
<param name="can_network_name">can0</param>
4343
</hardware>
44-
<xacro:wheel_transmission prefix="left_forward" mechanical_reduction="20.0" motor_id="1" />
45-
<xacro:wheel_transmission prefix="left_back" mechanical_reduction="20.0" motor_id="3" />
46-
<xacro:wheel_transmission prefix="right_forward" mechanical_reduction="20.0" motor_id="4" />
47-
<xacro:wheel_transmission prefix="right_back" mechanical_reduction="20.0" motor_id="2" />
44+
<xacro:wheel_transmission prefix="left_forward" mechanical_reduction="20.0" vel_motor_id="3" pos_motor_id="3" pos_offset="-0.0609"/>
45+
<xacro:wheel_transmission prefix="left_back" mechanical_reduction="20.0" vel_motor_id="2" pos_motor_id = "1" pos_offset="0.1227"/>
46+
<xacro:wheel_transmission prefix="right_forward" mechanical_reduction="20.0" vel_motor_id="4" pos_motor_id = "2" pos_offset="-0.0356"/>
47+
<xacro:wheel_transmission prefix="right_back" mechanical_reduction="20.0" vel_motor_id="1" pos_motor_id = "4" pos_offset="-0.0694"/>
4848
<xacro:gimbal_transmission prefix="yaw" mechanical_reduction="1.0" offset="0.25"
4949
motor_id="5" />
5050
<xacro:gimbal_transmission prefix="pitch" mechanical_reduction="-1.0" offset="0.0"
5151
motor_id="6" />
52-
<xacro:shooter_transmission prefix="fric1" mechanical_reduction="1.0" offset="0.25"
52+
<!-- <xacro:shooter_transmission prefix="fric1" mechanical_reduction="1.0" offset="0.25"
5353
motor_id="5" />
5454
<xacro:shooter_transmission prefix="fric2" mechanical_reduction="-1.0" offset="0.0"
5555
motor_id="6" />
5656
<xacro:shooter_transmission prefix="loader" mechanical_reduction="36.0" offset="0.0"
57-
motor_id="7" />
57+
motor_id="7" /> -->
5858
</ros2_control>
5959
</xacro:unless>
6060

meta_bringup/config/sentry25.yaml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,20 @@ agv_chassis_controller:
5454

5555
follow_pid_target: 0.7853981634
5656

57-
steer_pos_pos2vel_gains:
58-
{ p: 4.0, i: 2.0e-1, d: 0.0, i_clamp_max: 3.0, i_clamp_min: -3.0, antiwindup: true }
59-
steer_pos_vel2eff_gains:
60-
{ p: 4.0, i: 2.0e-1, d: 0.0, i_clamp_max: 3.0, i_clamp_min: -3.0, antiwindup: true }
57+
# steer_pos2vel_gains:
58+
# { p: 45.0, i: 5.5, d: 1.0E4, i_clamp_max: 3.0, i_clamp_min: -3.0, antiwindup: true }
59+
# steer_vel2eff_gains:
60+
# { p: 1.0, i: 35.0, d: 0.0, i_clamp_max: 3.0, i_clamp_min: -3.0, antiwindup: true }
61+
62+
steer_pos2vel_gains:
63+
# { p: 7.0, i: 0.0, d: 0.0, i_clamp_max: 3.0, i_clamp_min: -3.0, antiwindup: true }
64+
{ p: 0.0, i: 0.0, d: 0.0 }
65+
steer_vel2eff_gains:
66+
{ p: 1.0e-2, i: 2.5e-1, d: 0.0, i_clamp_max: 1.0, i_clamp_min: -1.0, antiwindup: true }
67+
# steer_pos2vel_gains:
68+
# { p: 0.0, i: 0.0, d: 0.0, i_clamp_max: 3.0, i_clamp_min: -3.0, antiwindup: true }
69+
# steer_vel2eff_gains:
70+
# { p: 1.0, i: 0.0, d: 0.0, i_clamp_max: 3.0, i_clamp_min: -3.0, antiwindup: true }
6171

6272

6373
reference_timeout: 0.2

meta_bringup/launch/sentry25.launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def generate_launch_description():
9393
# Order in this list is IMPORTANT
9494
load_controllers = [
9595
load_controller('wheels_pid_controller'),
96-
load_controller('steer_pos2vel_pid_controller'),
96+
# load_controller('steer_pos2vel_pid_controller'),
9797
# load_controller('steer_vel2eff_pid_controller'),
9898

9999
# load_controller('gimbal_controller'),

0 commit comments

Comments
 (0)