18 #include <geometry_msgs/Twist.h> 19 #include <nav_msgs/Odometry.h> 20 #include <sensor_msgs/JointState.h> 30 bool all_parameters_set =
true;
35 all_parameters_set =
false;
40 all_parameters_set =
false;
45 all_parameters_set =
false;
48 if (!all_parameters_set)
50 throw std::runtime_error(
"At least one parameter is missing.");
58 controller_ = std::make_shared<cob_mecanum_controller::MecanumController>(lx, ly, r);
76 std::shared_ptr<cob_mecanum_controller::MecanumController>
controller_;
83 Eigen::Vector3d twist;
84 twist << msg.linear.x, msg.linear.y, msg.angular.z;
85 Eigen::Vector4d wheel_velocities = controller_->twistToWheel(twist);
86 sensor_msgs::JointState joint_command;
87 joint_command.velocity = std::vector<double>(
88 wheel_velocities.data(), wheel_velocities.data() + wheel_velocities.rows() * wheel_velocities.cols());
89 joint_cmd_pub_.
publish(joint_command);
94 Eigen::Vector4d wheel_velocities(msg.velocity.data());
95 Eigen::Vector3d twist = controller_->wheelToTwist(wheel_velocities);
96 nav_msgs::Odometry odom_msg;
100 odom_msg.twist.twist.linear.x = twist.x();
101 odom_msg.twist.twist.linear.y = twist.y();
102 odom_msg.twist.twist.angular.z = twist.z();
107 int main(
int argc,
char* argv[])
109 ros::init(argc, argv,
"mecanum_controller");
void jointStateCallback(const sensor_msgs::JointState msg)
void twistCallback(const geometry_msgs::Twist msg)
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::Subscriber twist_sub_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::Publisher joint_cmd_pub_
std::string static_frame_
std::shared_ptr< cob_mecanum_controller::MecanumController > controller_
ros::Subscriber joint_state_sub_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool getParam(const std::string &key, std::string &s) const
int main(int argc, char *argv[])
#define ROS_ERROR_STREAM(args)