get_calibration_params.cpp
Go to the documentation of this file.
1 #include "ros/ros.h"
2 
4 #include <muse_v2_driver/GetCalibrationParams.h>
5 
6 int main(int argc, char** argv)
7 {
8  ros::init(argc, argv, "get_calibration_params");
9 
11 
13 
14  calib.setupInputCommands(n);
15 
16  ros::ServiceClient client = n.serviceClient<muse_v2_driver::GetCalibrationParams>("get_calibration_params");
17 
18  if (calib.input_command == calib.default_command_list) {
19  ROS_ERROR("No request found.");
20  ros::shutdown();
21  return -1;
22  }
23 
24  muse_v2_driver::GetCalibrationParams srv;
25 
27  srv.request.get_gyroscope_offset = true;
28 
30  srv.request.get_accelerometer_calib_params = true;
31 
33  srv.request.get_magnetometer_calib_params = true;
34 
35 
36  if (client.call(srv))
37  {
38  std::string calib_file_path = ros::package::getPath("muse_v2_driver") + "/config/muse_calib.txt";
39  std::ofstream muse_calib_file;
40 
41  muse_calib_file.open(calib_file_path);
42 
43  std::stringstream stream;
44 
45 
46  if (srv.request.get_gyroscope_offset) {
47 
48  stream.str(std::string());
49 
50  stream << "X" << "\t" << "Y" << "\t" << "Z" << "\n";
51  stream << std::setprecision(6) << std::fixed << srv.response.current_gyro_offset[0] << "\t" << srv.response.current_gyro_offset[1] << "\t" << srv.response.current_gyro_offset[2];
52 
53  ROS_INFO_STREAM("Gyroscope Calibration params: \n" << stream.str());
54 
55  if (!muse_calib_file) {
56  ROS_ERROR("Error: file could not be opened.");
57  return 1;
58  }
59 
60  muse_calib_file << "Accelerometer Calibration params: \n" << stream.str() << "\n";
61 
62  }
63 
64  if (srv.request.get_accelerometer_calib_params) {
65 
66  stream.str(std::string());
67 
68  stream << "X" << "\t" << "Y" << "\t" << "Z" << "\t" << "offset" << "\n";
69  stream << std::setprecision(6) << std::fixed << srv.response.current_acc_params[0] << "\t" << srv.response.current_acc_params[1] << "\t" << srv.response.current_acc_params[2] << "\t" << srv.response.current_acc_params[9] << "\n";
70  stream << srv.response.current_acc_params[3] << "\t" << srv.response.current_acc_params[4] << "\t" << srv.response.current_acc_params[5] << "\t" << srv.response.current_acc_params[10] << "\n";
71  stream << srv.response.current_acc_params[6] << "\t" << srv.response.current_acc_params[7] << "\t" << srv.response.current_acc_params[8] << "\t" << srv.response.current_acc_params[11];
72 
73  ROS_INFO_STREAM("Accelerometer Calibration params: \n" << stream.str());
74 
75  if (!muse_calib_file) {
76  ROS_ERROR("Error: file could not be opened.");
77  return 1;
78  }
79 
80  muse_calib_file << "Accelerometer Calibration params: \n" << stream.str() << "\n";
81 
82  }
83 
84  if (srv.request.get_magnetometer_calib_params) {
85 
86  stream.str(std::string());
87 
88  stream << "X" << "\t" << "Y" << "\t" << "Z" << "\t" << "offset" << "\n";
89  stream << std::setprecision(6) << std::fixed << srv.response.current_mag_params[0] << "\t" << srv.response.current_mag_params[1] << "\t" << srv.response.current_mag_params[2] << "\t" << srv.response.current_mag_params[9] << "\n";
90  stream << srv.response.current_mag_params[3] << "\t" << srv.response.current_mag_params[4] << "\t" << srv.response.current_mag_params[5] << "\t" << srv.response.current_mag_params[10] << "\n";
91  stream << srv.response.current_mag_params[6] << "\t" << srv.response.current_mag_params[7] << "\t" << srv.response.current_mag_params[8] << "\t" << srv.response.current_mag_params[11];
92 
93  ROS_INFO_STREAM("Magnetometer Calibration params: \n" << stream.str());
94 
95  if (!muse_calib_file) {
96  ROS_ERROR("Error: file could not be opened.");
97  return 1;
98  }
99 
100  muse_calib_file << "Magnetometer Calibration params: \n" << stream.str() << "\n";
101 
102  }
103 
104  muse_calib_file.close();
105 
106  }
107  else
108  {
109  ROS_ERROR("Failed to call Get Calibration Params service.");
110  return 1;
111  }
112 
113  return 0;
114 }
ros::package::getPath
ROSLIB_DECL std::string getPath(const std::string &package_name)
muse_v2_driver::Calibration::CommandList::get_accelerometer_calib_params
bool get_accelerometer_calib_params
Definition: Calibration.h:18
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
ros::NodeHandle::serviceClient
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
muse_v2_driver::Calibration::default_command_list
struct muse_v2_driver::Calibration::CommandList default_command_list
ros::shutdown
ROSCPP_DECL void shutdown()
main
int main(int argc, char **argv)
Definition: get_calibration_params.cpp:6
muse_v2_driver::Calibration::CommandList::get_gyroscope_offset
bool get_gyroscope_offset
Definition: Calibration.h:17
muse_v2_driver::Calibration::CommandList::get_magnetometer_calib_params
bool get_magnetometer_calib_params
Definition: Calibration.h:19
ros::ServiceClient
ROS_INFO_STREAM
#define ROS_INFO_STREAM(args)
muse_v2_driver::Calibration
Definition: Calibration.h:11
muse_v2_driver::Calibration::input_command
CommandList input_command
Definition: Calibration.h:38
ROS_ERROR
#define ROS_ERROR(...)
muse_v2_driver::Calibration::setupInputCommands
void setupInputCommands(ros::NodeHandle &node)
Definition: Calibration.cpp:3
ros::ServiceClient::call
bool call(const MReq &req, MRes &resp, const std::string &service_md5sum)
Calibration.h
ros::NodeHandle


muse_v2_driver
Author(s): Elisa Tosello , Roberto Bortoletto
autogenerated on Thu Jan 20 2022 03:24:53