8 #include <geometry_msgs/Twist.h> 9 #include <std_msgs/Int16.h> 10 #include <sensor_msgs/Imu.h> 13 #include <nav_msgs/Odometry.h> 14 #include <tf/transform_broadcaster.h> 57 "/uc_bridge/set_steering_level_msg";
60 "/uc_bridge/set_motor_level_msg";
74 if (nh->hasParam(
"odom_sim/wheel_base"))
76 nh->getParam(
"odom_sim/wheel_base", wheelBase);
91 if (nh->hasParam(
"odom_sim/initial_x_coordinate"))
93 nh->getParam(
"odom_sim/initial_x_coordinate", initialX);
108 if (nh->hasParam(
"odom_sim/initial_y_coordinate"))
110 nh->getParam(
"odom_sim/initial_y_coordinate", initialY);
125 if (nh->hasParam(
"odom_sim/initial_yaw"))
127 nh->getParam(
"odom_sim/initial_yaw", initialYaw);
142 if (nh->hasParam(
"odom_sim/loop_rate_control"))
144 nh->getParam(
"odom_sim/loop_rate_control", loopRate);
158 if (nh->hasParam(
"odom_sim/odom_frame_id"))
160 nh->getParam(
"odom_sim/odom_frame_id", odomFrameID);
175 if (nh->hasParam(
"odom_sim/odom_child_frame_id"))
177 nh->getParam(
"odom_sim/odom_child_frame_id", odomChildFrameID);
191 std::string& motionCommandTopic)
193 if (nh->hasParam(
"odom_sim/motion_command_topic"))
195 nh->getParam(
"odom_sim/motion_command_topic", motionCommandTopic);
209 std::string& steeringCommandTopic)
211 if (nh->hasParam(
"odom_sim/steering_command_topic"))
213 nh->getParam(
"odom_sim/steering_command_topic", steeringCommandTopic);
228 if (nh->hasParam(
"odom_sim/motor_command_topic"))
230 nh->getParam(
"odom_sim/motor_command_topic", motorCommandTopic);
244 if (nh->hasParam(
"odom_sim/odom_topic"))
246 nh->getParam(
"odom_sim/odom_topic", odomTopic);
260 if (nh->hasParam(
"odom_sim/imu_topic"))
262 nh->getParam(
"odom_sim/imu_topic", imuTopic);
292 *cmdOut = cmdIn->data;
305 *cmdOut = cmdIn->data;
314 int main(
int argc,
char** argv)
317 ros::init(argc, argv,
"simulation_control");
320 double loopRate, wheelBase, initialX, initialY, initialYaw;
321 std::string motionCmdTopic, steeringCmdTopic, motorCmdTopic, odomTopic,
322 odomFrameID, odomChildFrameID, imuTopic;
337 std::vector<double> initialPose;
338 initialPose.push_back(-initialY);
339 initialPose.push_back(initialX);
340 initialPose.push_back(initialYaw);
342 ros::Time currentTime = ros::Time::now();
343 CarModel car(wheelBase, currentTime, initialPose);
345 std::vector<double> simPose;
347 int steeringCmd = 0, motorCmd = 0;
348 bool isTwistCmd =
true;
349 tf::TransformBroadcaster odom_broadcaster;
350 geometry_msgs::TransformStamped odom_trans;
354 ros::Subscriber motionControl = nh.subscribe<
twist_msg>(
357 ros::Subscriber steeringControl = nh.subscribe<
int16_msg>(
360 ros::Subscriber motorControl = nh.subscribe<
int16_msg>(
361 motorCmdTopic, 1, boost::bind(
motorCommand, _1, &motorCmd, &isTwistCmd));
362 ros::Publisher odomPub = nh.advertise<
odom_msg>(odomTopic, 10);
363 ros::Publisher imuPub = nh.advertise<
imu_msg>(imuTopic, 10);
366 ros::Rate loop_rate(loopRate);
369 currentTime = ros::Time::now();
370 if (isTwistCmd ==
false)
372 simPose = *car.
getUpdate(-steeringCmd / 20, motorCmd / 50, currentTime);
379 geometry_msgs::Quaternion odom_quat =
380 tf::createQuaternionMsgFromYaw(simPose[2]);
384 odom_trans.header.stamp = currentTime;
385 odom_trans.header.frame_id = odomFrameID;
386 odom_trans.child_frame_id = odomChildFrameID;
388 odom_trans.transform.translation.x = simPose[1];
389 odom_trans.transform.translation.y = -simPose[0];
390 odom_trans.transform.translation.z = 0.0;
391 odom_trans.transform.rotation = odom_quat;
393 odom_broadcaster.sendTransform(odom_trans);
396 odom.header.stamp = currentTime;
397 odom.header.frame_id = odomFrameID;
399 odom.pose.pose.position.x = simPose[1];
400 odom.pose.pose.position.y = -simPose[0];
401 odom.pose.pose.position.z = 0.0;
402 odom.pose.pose.orientation = odom_quat;
404 odom.child_frame_id = odomChildFrameID;
405 odom.twist.twist.linear.x = car.
getVx();
406 odom.twist.twist.linear.y = car.
getVy();
410 imu.header.stamp = currentTime;
411 imu.header.frame_id =
"robot_simulation";
413 imu.linear_acceleration.x = car.
getAx();
414 imu.linear_acceleration.y = car.
getAy();
417 odomPub.publish(odom);
void fetchLoopRate(ros::NodeHandle *nh, double &loopRate)
Get loop rate launch parameter.
static const double DEFAULT_CAR_Y_COORDINATE
const pose_ptr getUpdate(const int newSteering, const int newSpeed, const ros::Time &time)
Update the simulation with current control settings and time.
void motionCommand(const twist_msg::ConstPtr &cmdIn, twist_msg *cmdOut, bool *isTwistCmd)
Motion command topic callback.
static const std::string DEFAULT_ODOM_CHILD_FRAME_ID
nav_msgs::Odometry odom_msg
shortcut for a pointer to a Odometry message
void fetchSteeringCommandTopic(ros::NodeHandle *nh, std::string &steeringCommandTopic)
Get steering command topic launch parameter.
const double getVy() const
Get current velocity in y direction of the mobile plattform relative to the global coordinate system...
static const std::string DEFAULT_MOTOR_COMMAND_TOPIC
static const double DEFAULT_CAR_WHEELBASE
const double getAy() const
Get current acceleration in y direction of the mobile plattform relative to the robot coordinate syst...
static const std::string DEFAULT_MOTION_COMMAND_TOPIC
The CarModel class simulates kinematic behavoir of a car like mobile platform, by using the ForwardKi...
static const std::string DEFAULT_STEERING_COMMAND_TOPIC
void fetchMotionCommandTopic(ros::NodeHandle *nh, std::string &motionCommandTopic)
Get motion command topic launch parameter.
void fetchMotorCommandTopic(ros::NodeHandle *nh, std::string &motorCommandTopic)
Get motor command topic launch parameter.
static const std::string DEFAULT_ODOM_FRAME_ID
void fetchInitialX(ros::NodeHandle *nh, double &initialX)
Get the initial x-coordinate of the robot.
Header file for the CarModel class.
void fetchWheelBase(ros::NodeHandle *nh, double &wheelBase)
Get wheel base launch parameter.
void fetchImuTopic(ros::NodeHandle *nh, std::string &imuTopic)
Get imu topic launch parameter.
void fetchInitialY(ros::NodeHandle *nh, double &initialY)
Get the initial y-coordinate of the robot.
void fetchOdomTopic(ros::NodeHandle *nh, std::string &odomTopic)
Get odometry topic launch parameter.
sensor_msgs::Imu imu_msg
shortcut for a pointer to a IMU message
static const std::string DEFAULT_IMU_TOPIC
const double getAngularVelocity() const
Get current angular velocity of the mobile plattform.
void fetchOdomChildFrameID(ros::NodeHandle *nh, std::string &odomChildFrameID)
Get odom child frame id launch parameter.
const double getAx() const
Get current acceleration in x direction of the mobile plattform relative to the robot coordinate syst...
void fetchInitialYaw(ros::NodeHandle *nh, double &initialYaw)
Get the initial yaw of the robot. (in radians).
void fetchOdomFrameID(ros::NodeHandle *nh, std::string &odomFrameID)
Get odom frame id launch parameter.
int main(int argc, char **argv)
Main function of this ros node.
static const std::string DEFAULT_ODOM_TOPIC
geometry_msgs::Twist twist_msg
shortcut for a pointer to a twist message
std_msgs::Int16 int16_msg
shortcut for a pointer to a int16 message
static const double DEFAULT_LOOP_RATE
static const double DEFAULT_CAR_X_COORDINATE
const double getVx() const
Get current velocity in x direction of the mobile plattform relative to the global coordinate system...
void motorCommand(const int16_msg::ConstPtr &cmdIn, int *cmdOut, bool *isTwistCmd)
Motor command topic callback.
This namespace groups all typedefs, utility functions and parameter getter used in the simulation_odo...
void steeringCommand(const int16_msg::ConstPtr &cmdIn, int *cmdOut, bool *isTwistCmd)
Steering command topic callback.
const pose_ptr getUpdateTwist(const twist_msg cmd_vel, const ros::Time &time)
Update the simulation with current motion parameters and time.
static const double DEFAULT_CAR_YAW
geometry_msgs::Twist twist_msg
shortcut for the twist message