23 #include <boost/thread/recursive_mutex.hpp> 26 #include <geometry_msgs/Twist.h> 27 #include <sensor_msgs/Imu.h> 28 #include <sensor_msgs/LaserScan.h> 29 #include <nav_msgs/Odometry.h> 32 #define PI 3.14159265359 88 nh.
param<
double>(
"base_controller/track_width", odom, 0.37476);
89 nh.
param<
double>(
"imu/gyro/scale", imu, 0.001221729);
92 double odom_scale = 0.0;
93 double imu_scale = 0.0;
96 for (
size_t i = 0; i <
scan_.size(); ++i)
102 odom_scale /=
scan_.size();
103 imu_scale /=
scan_.size();
105 std::stringstream ss;
106 ss <<
"odom: " << odom * (1.0 + odom_scale) << std::endl;
107 ss <<
"imu: " << imu * (1.0 + imu_scale) << std::endl;
120 std::cout <<
"aligning..." << std::endl;
151 std::cout <<
"...done" << std::endl;
164 std::cout <<
"spin..." << std::endl;
189 std::cout <<
"...done" << std::endl;
211 boost::recursive_mutex::scoped_lock lock(
data_mutex_);
221 boost::recursive_mutex::scoped_lock lock(
data_mutex_);
231 boost::recursive_mutex::scoped_lock lock(
data_mutex_);
233 double angle = scan->angle_min;
234 double mean_x, mean_y, n;
235 mean_x = mean_y = n = 0;
237 for (
size_t i = 0; i < scan->ranges.size(); ++i, angle += scan->angle_increment)
244 if (std::isnan(scan->ranges[i]))
255 double px =
sin(angle) * scan->ranges[i];
256 double py =
cos(angle) * scan->ranges[i];
271 angle = scan->angle_min + start * scan->angle_increment;
272 double x,
y, xx, xy, yy;
273 x = y = xx = xy = yy = n = 0;
274 for (
size_t i = start; i < scan->ranges.size(); ++i, angle += scan->angle_increment)
281 if (std::isnan(scan->ranges[i]))
287 double px =
sin(angle) * scan->ranges[i] - mean_x;
288 double py =
cos(angle) * scan->ranges[i] - mean_y;
308 geometry_msgs::Twist twist;
309 twist.angular.z = vel;
315 boost::recursive_mutex::scoped_lock lock(
data_mutex_);
ros::Subscriber odom_subscriber_
void odometryCallback(const nav_msgs::Odometry::Ptr &odom)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
boost::recursive_mutex data_mutex_
BaseCalibration(ros::NodeHandle &n)
Create a base calibration instance.
std::vector< double > odom_
void sendVelocityCommand(double vel)
Send a rotational velocity command.
std::string print()
Print out current calibration state.
void imuCallback(const sensor_msgs::Imu::Ptr &imu)
ros::Time last_imu_stamp_
ros::Subscriber imu_subscriber_
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
void resetInternal()
Reset the odom/imu counters.
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void publish(const boost::shared_ptr< M > &message) const
std::vector< double > scan_
bool align(double angle, bool verbose=false)
Align to the wall.
ros::Time last_scan_stamp_
bool spin(double velocity, int rotations, bool verbose=false)
Spin and record imu, odom, scan.
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
Calibration code lives under this namespace.
ros::Time last_odom_stamp_
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
std::vector< double > imu_
void laserCallback(const sensor_msgs::LaserScan::Ptr &scan)
void clearMessages()
Clear any received messages.
ros::Subscriber scan_subscriber_
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
std::string printCalibrationData()
Print out the calibration data.
ROSCPP_DECL void spinOnce()
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)