9 #define DELTAT(_nowtime,_thentime) ((_thentime>_nowtime)?((0xffffffff-_thentime)+_nowtime):(_nowtime-_thentime)) 24 #include <geometry_msgs/Twist.h> 25 #include <nav_msgs/Odometry.h> 42 #define NORMALIZE(_z) atan2(sin(_z), cos(_z)) 45 #include <geometry_msgs/Quaternion.h> 47 #include <geometry_msgs/TransformStamped.h> 48 #include <nav_msgs/Odometry.h> 50 #include <std_msgs/Float32.h> 51 #include <roboteq_diff_msgs/Duplex.h> 53 #ifdef _ODOM_COVAR_SERVER 54 #include "roboteq_diff_msgs/OdometryCovariances.h" 55 #include "rogoteq_diff_msgs/RequestOdometryCovariances.h" 62 ROS_INFO(
"Received SIGINT signal, shutting down...");
72 return (uint32_t)(walltime.
toNSec()/1000000);
101 #ifdef _ODOM_COVAR_SERVER 102 void odom_covar_callback(
const roboteq_diff_msgs::RequestOdometryCovariancesRequest& req, roboteq_diff_msgs::RequestOdometryCovariancesResponse& res);
229 ROS_INFO_STREAM(
"base_frame: " << base_frame);
231 ROS_INFO_STREAM(
"cmdvel_topic: " << cmdvel_topic);
233 ROS_INFO_STREAM(
"odom_topic: " << odom_topic);
234 nhLocal.
param<std::string>(
"port",
port,
"/dev/ttyACM0");
235 ROS_INFO_STREAM(
"port: " << port);
237 ROS_INFO_STREAM(
"baud: " <<
baud);
239 ROS_INFO_STREAM(
"open_loop: " <<
open_loop);
249 ROS_INFO_STREAM(
"max_amps: " <<
max_amps);
251 ROS_INFO_STREAM(
"max_rpm: " <<
max_rpm);
264 float right_speed = twist_msg.linear.x +
track_width * twist_msg.angular.z / 2.0;
265 float left_speed = twist_msg.linear.x -
track_width * twist_msg.angular.z / 2.0;
267 ROS_DEBUG_STREAM(
"cmdvel speed right: " << right_speed <<
" left: " << left_speed);
270 std::stringstream right_cmd;
271 std::stringstream left_cmd;
279 ROS_DEBUG_STREAM(
"cmdvel power right: " << right_power <<
" left: " << left_power);
281 right_cmd <<
"!G 1 " << right_power <<
"\r";
282 left_cmd <<
"!G 2 " << left_power <<
"\r";
290 ROS_DEBUG_STREAM(
"cmdvel rpm right: " << right_rpm <<
" left: " << left_rpm);
292 right_cmd <<
"!S 1 " << right_rpm <<
"\r";
293 left_cmd <<
"!S 2 " << left_rpm <<
"\r";
297 #ifndef _CMDVEL_FORCE_RUN 336 std::stringstream right_ampcmd;
337 std::stringstream left_ampcmd;
338 right_ampcmd <<
"^ALIM 1 " << (int)(
max_amps * 10) <<
"\r";
339 left_ampcmd <<
"^ALIM 2 " << (int)(
max_amps * 10) <<
"\r";
344 std::stringstream right_rpmcmd;
345 std::stringstream left_rpmcmd;
346 right_rpmcmd <<
"^MXRPM 1 " <<
max_rpm <<
"\r";
347 left_rpmcmd <<
"^MXRPM 2 " << max_rpm <<
"\r";
372 std::stringstream right_enccmd;
373 std::stringstream left_enccmd;
375 left_enccmd <<
"^EPPR 2 " << encoder_ppr <<
"\r";
392 #ifdef _CMDVEL_FORCE_RUN 400 std::stringstream right_cmd;
401 std::stringstream left_cmd;
402 right_cmd <<
"!S 1 " << (int)(
max_rpm * 0.1) <<
"\r";
403 left_cmd <<
"!S 2 " << (int)(
max_rpm * 0.1) <<
"\r";
416 #ifdef _ODOM_COVAR_SERVER 417 void MainNode::odom_covar_callback(
const roboteq_diff_msgs::RequestOdometryCovariancesRequest& req, roboteq_diff_msgs::RequestOdometryCovariancesResponse& res)
419 res.odometry_covariances.pose.pose.covariance[0] = 0.001;
420 res.odometry_covariances.pose.pose.covariance[7] = 0.001;
421 res.odometry_covariances.pose.pose.covariance[14] = 1000000;
422 res.odometry_covariances.pose.pose.covariance[21] = 1000000;
423 res.odometry_covariances.pose.pose.covariance[28] = 1000000;
424 res.odometry_covariances.pose.pose.covariance[35] = 1000;
426 res.odometry_covariances.twist.twist.covariance[0] = 0.001;
427 res.odometry_covariances.twist.twist.covariance[7] = 0.001;
428 res.odometry_covariances.twist.twist.covariance[14] = 1000000;
429 res.odometry_covariances.twist.twist.covariance[21] = 1000000;
430 res.odometry_covariances.twist.twist.covariance[28] = 1000000;
431 res.odometry_covariances.twist.twist.covariance[35] = 1000;
476 #ifdef _ODOM_COVAR_SERVER 477 ROS_INFO(
"Advertising service on roboteq/odom_covar_srv");
478 odom_covar_server =
nh.
advertiseService(
"roboteq/odom_covar_srv", &MainNode::odom_covar_callback,
this);
482 ROS_INFO(
"Publishing to topic roboteq/voltage");
484 ROS_INFO(
"Publishing to topic roboteq/current");
486 ROS_INFO(
"Publishing to topic roboteq/energy");
488 ROS_INFO(
"Publishing to topic roboteq/temperature");
501 odom_msg.pose.covariance[0] = 0.001;
502 odom_msg.pose.covariance[7] = 0.001;
503 odom_msg.pose.covariance[14] = 1000000;
504 odom_msg.pose.covariance[21] = 1000000;
505 odom_msg.pose.covariance[28] = 1000000;
506 odom_msg.pose.covariance[35] = 1000;
508 odom_msg.twist.covariance.assign(0);
509 odom_msg.twist.covariance[0] = 0.001;
510 odom_msg.twist.covariance[7] = 0.001;
511 odom_msg.twist.covariance[14] = 1000000;
512 odom_msg.twist.covariance[21] = 1000000;
513 odom_msg.twist.covariance[28] = 1000000;
514 odom_msg.twist.covariance[35] = 1000;
561 uint32_t nowtime =
millis();
586 for ( delim = 3; delim <
odom_idx; delim++ )
612 for (
int delim = 2; delim <=
odom_idx; delim++ )
648 for ( delim = 3; delim <
odom_idx; delim++ )
718 uint32_t nowtime =
millis();
786 tf_msg.transform.translation.z = 0.0;
787 tf_msg.transform.rotation = quat;
795 odom_msg.pose.pose.position.z = 0.0;
796 odom_msg.pose.pose.orientation = quat;
799 odom_msg.twist.twist.linear.z = 0.0;
800 odom_msg.twist.twist.angular.x = 0.0;
801 odom_msg.twist.twist.angular.y = 0.0;
802 odom_msg.twist.twist.angular.z = vyaw;
827 ROS_INFO(
"Successfully opened serial port");
835 ROS_WARN(
"Failed to open serial port");
857 uint32_t nowtime =
millis();
899 int main(
int argc,
char **argv)
ros::Publisher voltage_pub
#define DELTAT(_nowtime, _thentime)
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::Publisher energy_pub
void setTimeout(Timeout &timeout)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void setBaudrate(uint32_t baudrate)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
std_msgs::Float32 temperature_msg
geometry_msgs::TransformStamped tf_msg
int32_t odom_encoder_left
std_msgs::Float32 energy_msg
ros::Publisher temperature_pub
int main(int argc, char **argv)
void cmdvel_callback(const geometry_msgs::Twist &twist_msg)
nav_msgs::Odometry odom_msg
serial::Serial controller
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
std_msgs::Float32 voltage_msg
tf::TransformBroadcaster odom_broadcaster
uint32_t current_last_time
virtual const char * what() const
static Timeout simpleTimeout(uint32_t timeout)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::Subscriber cmdvel_sub
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
ros::Publisher current_pub
void setPort(const std::string &port)
void mySigintHandler(int sig)
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
#define ROS_INFO_STREAM(args)
size_t read(uint8_t *buffer, size_t size)
ROSCPP_DECL void shutdown()
int32_t odom_encoder_right
ROSCPP_DECL void spinOnce()
double wheel_circumference
roboteq_diff_msgs::Duplex current_msg
size_t write(const uint8_t *data, size_t size)