22 #include <boost/thread/recursive_mutex.hpp> 25 #include <geometry_msgs/Twist.h> 26 #include <sensor_msgs/Imu.h> 27 #include <sensor_msgs/LaserScan.h> 28 #include <nav_msgs/Odometry.h> 30 #define PI 3.14159265359 79 nh.
param<
double>(
"base_controller/track_width", odom, 0.37476);
80 nh.
param<
double>(
"imu/gyro/scale", imu, 0.001221729);
83 double odom_scale = 0.0;
84 double imu_scale = 0.0;
87 for (
size_t i = 0; i <
scan_.size(); ++i)
93 odom_scale /=
scan_.size();
94 imu_scale /=
scan_.size();
97 ss <<
"odom: " << odom * (1.0 + odom_scale) << std::endl;
98 ss <<
"imu: " << imu * (1.0 + imu_scale) << std::endl;
108 std::cout <<
"aligning..." << std::endl;
110 double velocity = 0.2;
122 std::cout <<
"...done" << std::endl;
129 bool spin(
double velocity,
int rotations,
bool verbose =
false)
135 std::cout <<
"spin..." << std::endl;
148 std::cout <<
"...done" << std::endl;
167 boost::recursive_mutex::scoped_lock lock(
data_mutex_);
177 boost::recursive_mutex::scoped_lock lock(
data_mutex_);
187 boost::recursive_mutex::scoped_lock lock(
data_mutex_);
189 double angle = scan->angle_min;
190 double mean_x, mean_y, n;
191 mean_x = mean_y = n = 0;
193 for (
size_t i = 0; i < scan->ranges.size(); ++i, angle += scan->angle_increment)
201 double px =
sin(angle) * scan->ranges[i];
202 double py =
cos(angle) * scan->ranges[i];
215 angle = scan->angle_min + start * scan->angle_increment;
216 double x,
y, xx, xy, yy;
217 x = y = xx = xy = yy = n = 0;
218 for (
size_t i = start; i < scan->ranges.size(); ++i, angle += scan->angle_increment)
224 double px =
sin(angle) * scan->ranges[i] - mean_x;
225 double py =
cos(angle) * scan->ranges[i] - mean_y;
246 geometry_msgs::Twist twist;
247 twist.angular.z = vel;
254 boost::recursive_mutex::scoped_lock lock(
data_mutex_);
284 int main(
int argc,
char** argv)
286 ros::init(argc, argv,
"base_calibration_node");
311 std::time_t
t = std::time(NULL);
312 std::strftime(datecode, 80,
"%Y_%m_%d_%H_%M_%S", std::localtime(&t));
314 std::stringstream yaml_name;
315 yaml_name <<
"/tmp/base_calibration_" << datecode <<
".yaml";
317 file.open(yaml_name.str().c_str());
ros::Subscriber scan_subscriber_
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())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::Time last_scan_stamp_
bool align(bool verbose=false)
Align to the wall.
TFSIMD_FORCE_INLINE const tfScalar & y() const
geometry_msgs::TransformStamped t
ros::Time last_odom_stamp_
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
std::vector< double > imu_
std::string printCalibrationData()
void odometryCallback(const nav_msgs::Odometry::Ptr &odom)
int main(int argc, char **argv)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
BaseCalibration(ros::NodeHandle &n)
boost::recursive_mutex data_mutex_
TFSIMD_FORCE_INLINE const tfScalar & x() const
ros::Subscriber imu_subscriber_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::vector< double > odom_
void imuCallback(const sensor_msgs::Imu::Ptr &imu)
std::vector< double > scan_
bool spin(double velocity, int rotations, bool verbose=false)
Spin and record imu, odom, scan.
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
ros::Time last_imu_stamp_
void laserCallback(const sensor_msgs::LaserScan::Ptr &scan)
ros::Subscriber odom_subscriber_
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
void sendVelocityCommand(double vel)