10 #include <geometry_msgs/Twist.h> 20 if ( ros::isStarted() ) {
22 ros::waitForShutdown();
35 if ( ros::master::check() ) {
52 cmd_publisher = nh.advertise<geometry_msgs::Twist>(
"vel_cmd", 10);
65 const ros::Time& t = odom->header.stamp;
66 const double date = t.sec + 1E-9 * t.nsec;
67 static const double initial_date = date;
68 const geometry_msgs::Pose& pose = odom->pose.pose;
69 const geometry_msgs::Point& point = pose.position;
70 const geometry_msgs::Quaternion& orient = pose.orientation;
71 const tf::Quaternion tfQuat(orient.x, orient.y, orient.z, orient.w);
72 const tf::Matrix3x3 tfMatrix(tfQuat);
73 const geometry_msgs::Twist& twist = odom->twist.twist;
74 double roll, pitch, yaw;
75 tfMatrix.getRPY(roll, pitch, yaw);
77 state(date - initial_date,
78 iSeeML::rob::OrPtConfig(iSeeML::geom::Point(point.x, point.y),
79 yaw), twist.linear.x, twist.angular.z);
93 ros::Rate loop_rate(loop_frequ);
94 geometry_msgs::Twist vel;
98 std::ostringstream log_msg;
101 log( Info, log_msg.str() );
119 const std::string &host_url,
Controller& ctrl) {
120 std::map<std::string,std::string> remappings;
121 remappings[
"__master"] = master_url;
122 remappings[
"__hostname"] = host_url;
123 ros::init(remappings,
"qt_ctrl");
136 static const char* levelName[Count] =
137 {
"DEBUG",
"INFO",
"WARN",
"ERROR",
"FATAL"};
138 std::stringstream log_model_msg;
140 if (
connected() && (level < Count) && ( !msg.empty() ) ) {
142 ROS_LOG_STREAM(level, ROSCONSOLE_DEFAULT_NAME, msg);
146 log_model_msg <<
"[" << levelName[(int)(level)] <<
"] [" 147 << ros::Time::now() <<
"]: " << msg;
149 QVariant new_row( QString( log_model_msg.str().c_str() ) );
ros::Subscriber odom_subscriber
ROS object used to get the odometry.
void stopMotion()
Stops the robot (i.e. sets both velocities to zero).
Controller is the abstract class inherited by all the implemented controllers.
::ros::console::Level LogLevel
Log severity levels, comming from ROS::console.
void init(Controller &ctrl)
Connects to ROS server with main arguments.
void loggingUpdated()
Signals the GUI for log's update.
QStringListModel log_model
Qt object used to show the logs in the GUI.
void newOdometry(const nav_msgs::Odometry::ConstPtr &odom)
Sends the odometry data to the controller.
virtual void newState(const State &state)
Handles new state of the robot.
const double & timeStep() const
Stops the robot (i.e. sets both velocities to zero).
This class defines a state, i.e. a configuration and its (translation and rotation) velocities...
Controller * motion_ctrl
A pointer to the controller of the motion.
bool connected() const
Indicates whether the node is connected to ROS.
void ROSsetup(Controller &ctrl)
Common part of the two initialisation methods.
virtual void chooseVelocities(double &trans_vel, double &rot_vel, std::ostream &log_str)=0
Computes new velocities for ROS node.
void log(const LogLevel &level, const std::string &msg)
Writes a message at given level in the log.
void run()
Main loop of the process (on a separate thread).
ros::Publisher cmd_publisher
ROS object used to send the velocities.
void end()
Stops ROS if it has been started.