Skip to content

Commit c4593a8

Browse files
committed
Merge branch 'dev' into 'Readme'.
1 parent 1353f35 commit c4593a8

File tree

15 files changed

+114
-292
lines changed

15 files changed

+114
-292
lines changed

rm_chassis_controllers/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ include_directories(
6060
## Declare cpp executables
6161
add_library(${PROJECT_NAME}
6262
src/chassis_base.cpp
63-
src/mecanum.cpp
6463
src/omni.cpp
6564
src/sentry.cpp
6665
src/swerve.cpp

rm_chassis_controllers/include/rm_chassis_controllers/chassis_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class ChassisBase : public controller_interface::MultiInterfaceController<T...>
114114
*/
115115
void gyro();
116116
virtual void moveJoint(const ros::Time& time, const ros::Duration& period) = 0;
117-
virtual geometry_msgs::Twist forwardKinematics() = 0;
117+
virtual geometry_msgs::Twist odometry() = 0;
118118
/** @brief Init frame on base_link. Integral vel to pos and angle.
119119
*
120120
* @param time The current time.

rm_chassis_controllers/include/rm_chassis_controllers/mecanum.h

Lines changed: 0 additions & 77 deletions
This file was deleted.
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//
2-
// Created by yezi on 2021/12/3.
2+
// Created by qiayuan on 2022/7/29.
33
//
44

55
#pragma once
66

7-
#include <rm_chassis_controllers/chassis_base.h>
7+
#include <Eigen/Dense>
8+
9+
#include "rm_chassis_controllers/chassis_base.h"
810

911
namespace rm_chassis_controllers
1012
{
@@ -16,9 +18,10 @@ class OmniController : public ChassisBase<rm_control::RobotStateInterface, hardw
1618

1719
private:
1820
void moveJoint(const ros::Time& time, const ros::Duration& period) override;
19-
geometry_msgs::Twist forwardKinematics() override;
21+
geometry_msgs::Twist odometry() override;
2022

21-
double chassis_radius_;
22-
effort_controllers::JointVelocityController ctrl_lf_, ctrl_rf_, ctrl_lb_, ctrl_rb_;
23+
std::vector<std::shared_ptr<effort_controllers::JointVelocityController>> joints_;
24+
Eigen::MatrixXd chassis2joints_;
2325
};
26+
2427
} // namespace rm_chassis_controllers

rm_chassis_controllers/include/rm_chassis_controllers/sentry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class SentryController : public ChassisBase<rm_control::RobotStateInterface, har
7171
*
7272
* @return Calculated vel_data included linear_x.
7373
*/
74-
geometry_msgs::Twist forwardKinematics() override;
74+
geometry_msgs::Twist odometry() override;
7575

7676
effort_controllers::JointVelocityController ctrl_wheel_;
7777
effort_controllers::JointPositionController ctrl_catapult_joint_;

rm_chassis_controllers/include/rm_chassis_controllers/swerve.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class SwerveController : public ChassisBase<rm_control::RobotStateInterface, har
6060

6161
private:
6262
void moveJoint(const ros::Time& time, const ros::Duration& period) override;
63-
geometry_msgs::Twist forwardKinematics() override;
63+
geometry_msgs::Twist odometry() override;
6464
std::vector<Module> modules_;
6565
};
6666

rm_chassis_controllers/rm_chassis_controllers_plugins.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
<library path="lib/librm_chassis_controllers">
22

3-
<class name="rm_chassis_controllers/MecanumController"
4-
type="rm_chassis_controllers::MecanumController"
5-
base_class_type="controller_interface::ControllerBase">
6-
<description>
7-
The StandardController is RoboMaster mecanum wheel Chassis controller. It expects a EffortJointInterface
8-
type of hardware interface.
9-
</description>
10-
</class>
113
<class name="rm_chassis_controllers/OmniController"
124
type="rm_chassis_controllers::OmniController"
135
base_class_type="controller_interface::ControllerBase">

rm_chassis_controllers/src/chassis_base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ void ChassisBase<T...>::raw()
274274
template <typename... T>
275275
void ChassisBase<T...>::updateOdom(const ros::Time& time, const ros::Duration& period)
276276
{
277-
geometry_msgs::Twist vel_base = forwardKinematics(); // on base_link frame
277+
geometry_msgs::Twist vel_base = odometry(); // on base_link frame
278278
if (enable_odom_tf_)
279279
{
280280
geometry_msgs::Vector3 linear_vel_odom, angular_vel_odom;

rm_chassis_controllers/src/mecanum.cpp

Lines changed: 0 additions & 89 deletions
This file was deleted.

rm_chassis_controllers/src/omni.cpp

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,80 @@
11
//
2-
// Created by yezi on 2021/12/3.
2+
// Created by qiayuan on 2022/7/29.
33
//
44

5-
#include <rm_chassis_controllers/omni.h>
6-
#include <rm_common/ros_utilities.h>
75
#include <string>
6+
#include <Eigen/QR>
7+
8+
#include <rm_common/ros_utilities.h>
89
#include <pluginlib/class_list_macros.hpp>
910

11+
#include "rm_chassis_controllers/omni.h"
12+
1013
namespace rm_chassis_controllers
1114
{
1215
bool OmniController::init(hardware_interface::RobotHW* robot_hw, ros::NodeHandle& root_nh,
1316
ros::NodeHandle& controller_nh)
1417
{
1518
ChassisBase::init(robot_hw, root_nh, controller_nh);
16-
if (!controller_nh.getParam("chassis_radius", chassis_radius_))
19+
20+
XmlRpc::XmlRpcValue wheels;
21+
controller_nh.getParam("wheels", wheels);
22+
chassis2joints_.resize(wheels.size(), 3);
23+
24+
size_t i = 0;
25+
for (const auto& wheel : wheels)
1726
{
18-
ROS_ERROR("chassis_radius is not set");
19-
return false;
27+
ROS_ASSERT(wheel.second.hasMember("pose"));
28+
ROS_ASSERT(wheel.second["pose"].getType() == XmlRpc::XmlRpcValue::TypeArray);
29+
ROS_ASSERT(wheel.second["pose"].size() == 3);
30+
ROS_ASSERT(wheel.second.hasMember("roller_angle"));
31+
ROS_ASSERT(wheel.second.hasMember("radius"));
32+
33+
// Ref: Modern Robotics, Chapter 13.2: Omnidirectional Wheeled Mobile Robots
34+
Eigen::MatrixXd direction(1, 2), in_wheel(2, 2), in_chassis(2, 3);
35+
double beta = (double)wheel.second["pose"][2];
36+
double roller_angle = (double)wheel.second["roller_angle"];
37+
direction << 1, tan(roller_angle);
38+
in_wheel << cos(beta), sin(beta), -sin(beta), cos(beta);
39+
in_chassis << -(double)wheel.second["pose"][1], 1., 0., (double)wheel.second["pose"][0], 0., 1.;
40+
Eigen::MatrixXd chassis2joint = 1. / (double)wheel.second["radius"] * direction * in_wheel * in_chassis;
41+
chassis2joints_.block<1, 3>(i, 0) = chassis2joint;
42+
43+
ros::NodeHandle nh_wheel = ros::NodeHandle(controller_nh, "wheels/" + wheel.first);
44+
joints_.push_back(std::make_shared<effort_controllers::JointVelocityController>());
45+
if (!joints_.back()->init(effort_joint_interface_, nh_wheel))
46+
return false;
47+
48+
i++;
2049
}
21-
ros::NodeHandle nh_lf = ros::NodeHandle(controller_nh, "left_front");
22-
ros::NodeHandle nh_rf = ros::NodeHandle(controller_nh, "right_front");
23-
ros::NodeHandle nh_lb = ros::NodeHandle(controller_nh, "left_back");
24-
ros::NodeHandle nh_rb = ros::NodeHandle(controller_nh, "right_back");
25-
if (!ctrl_lf_.init(effort_joint_interface_, nh_lf) || !ctrl_rf_.init(effort_joint_interface_, nh_rf) ||
26-
!ctrl_lb_.init(effort_joint_interface_, nh_lb) || !ctrl_rb_.init(effort_joint_interface_, nh_rb))
27-
return false;
28-
joint_handles_.push_back(ctrl_lf_.joint_);
29-
joint_handles_.push_back(ctrl_rf_.joint_);
30-
joint_handles_.push_back(ctrl_lb_.joint_);
31-
joint_handles_.push_back(ctrl_rb_.joint_);
3250
return true;
3351
}
3452

3553
void OmniController::moveJoint(const ros::Time& time, const ros::Duration& period)
3654
{
37-
ctrl_rf_.setCommand(((vel_cmd_.x + vel_cmd_.y + sqrt(2) * vel_cmd_.z * chassis_radius_) / sqrt(2)) / wheel_radius_);
38-
ctrl_lf_.setCommand(((-vel_cmd_.x + vel_cmd_.y + sqrt(2) * vel_cmd_.z * chassis_radius_) / sqrt(2)) / wheel_radius_);
39-
ctrl_lb_.setCommand(((-vel_cmd_.x - vel_cmd_.y + sqrt(2) * vel_cmd_.z * chassis_radius_) / sqrt(2)) / wheel_radius_);
40-
ctrl_rb_.setCommand(((vel_cmd_.x - vel_cmd_.y + sqrt(2) * vel_cmd_.z * chassis_radius_) / sqrt(2)) / wheel_radius_);
41-
ctrl_lf_.update(time, period);
42-
ctrl_rf_.update(time, period);
43-
ctrl_lb_.update(time, period);
44-
ctrl_rb_.update(time, period);
55+
Eigen::Vector3d vel_chassis;
56+
vel_chassis << vel_cmd_.z, vel_cmd_.x, vel_cmd_.y;
57+
Eigen::VectorXd vel_joints = chassis2joints_ * vel_chassis;
58+
for (size_t i = 0; i < joints_.size(); i++)
59+
{
60+
joints_[i]->setCommand(vel_joints(i));
61+
joints_[i]->update(time, period);
62+
}
4563
}
4664

47-
geometry_msgs::Twist OmniController::forwardKinematics()
65+
geometry_msgs::Twist OmniController::odometry()
4866
{
49-
geometry_msgs::Twist vel_data;
50-
double k = wheel_radius_ / 2;
51-
double lf_velocity = ctrl_lf_.joint_.getVelocity();
52-
double rf_velocity = ctrl_rf_.joint_.getVelocity();
53-
double lb_velocity = ctrl_lb_.joint_.getVelocity();
54-
double rb_velocity = ctrl_rb_.joint_.getVelocity();
55-
vel_data.linear.x = k * (-lf_velocity + rf_velocity - lb_velocity + rb_velocity) / sqrt(2);
56-
vel_data.linear.y = k * (lf_velocity + rf_velocity - lb_velocity - rb_velocity) / sqrt(2);
57-
vel_data.angular.z = k * (lf_velocity + rf_velocity + lb_velocity + rb_velocity) / (2 * chassis_radius_);
58-
return vel_data;
67+
Eigen::VectorXd vel_joints(joints_.size());
68+
for (size_t i = 0; i < joints_.size(); i++)
69+
vel_joints[i] = joints_[i]->joint_.getVelocity();
70+
Eigen::Vector3d vel_chassis =
71+
(chassis2joints_.transpose() * chassis2joints_).inverse() * chassis2joints_.transpose() * vel_joints;
72+
geometry_msgs::Twist twist;
73+
twist.angular.z = vel_chassis(0);
74+
twist.linear.x = vel_chassis(1);
75+
twist.linear.y = vel_chassis(2);
76+
return twist;
5977
}
78+
6079
} // namespace rm_chassis_controllers
6180
PLUGINLIB_EXPORT_CLASS(rm_chassis_controllers::OmniController, controller_interface::ControllerBase)

0 commit comments

Comments
 (0)