forked from Livox-SDK/livox_ros_driver2
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[LIVOX MID 360][CALIBRATION]: Adding calibration and filter to livox lidar MID 360 #1
Open
Sunart24
wants to merge
13
commits into
kiwi-devel
Choose a base branch
from
feature/livox_nav2
base: kiwi-devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c116034
optimize the framing logic
Livox-Infra dc45190
Change to respawnable container with a PC filter
Sunart24 40d4bb1
Add roll and pitch calculation and publisher
Sunart24 658d492
add calibration service
Sunart24 f9e1bc6
add missing false condition
Sunart24 0b3be3d
fix QoS
Sunart24 c6be2ff
correct filter limits
Sunart24 852c147
fix a bad_alloc problem
Livox-Infra bb709cb
Proper ip configuration for livox
pepisg c10133a
update filter limits with real measurements
Sunart24 85f9bc1
Merge branch 'master' of https://github.com/kiwicampus/livox_ros_driv…
pepisg 4b48429
bring back original frame ID
pepisg d7876b4
USe params file to livox filter configurations
Sunart24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
#include <iomanip> | ||
#include <math.h> | ||
#include <stdint.h> | ||
#include <numeric> | ||
|
||
#include "include/ros_headers.h" | ||
|
||
|
@@ -148,6 +149,11 @@ void Lddc::DistributeImuData(void) { | |
} | ||
|
||
lds_->imu_semaphore_.Wait(); | ||
|
||
#ifdef BUILDING_ROS2 | ||
Service<TriggerSrv>::SharedPtr calibration_srv_ptr = std::dynamic_pointer_cast<Service<TriggerSrv>>(GetCurrentCalibService()); | ||
#endif | ||
|
||
for (uint32_t i = 0; i < lds_->lidar_count_; i++) { | ||
uint32_t lidar_id = i; | ||
LidarDevice *lidar = &lds_->lidars_[lidar_id]; | ||
|
@@ -495,6 +501,71 @@ void Lddc::InitImuMsg(const ImuData& imu_data, ImuMsg& imu_msg, uint64_t& timest | |
imu_msg.linear_acceleration.z = imu_data.acc_z; | ||
} | ||
|
||
void Lddc::StoreAccelerationValues(ImuMsg& imu_msg) { | ||
|
||
_imu_accel_x_vector.push_back(imu_msg.linear_acceleration.x); | ||
_imu_accel_y_vector.push_back(imu_msg.linear_acceleration.y); | ||
_imu_accel_z_vector.push_back(imu_msg.linear_acceleration.z); | ||
|
||
if (_imu_accel_x_vector.size() > 30) | ||
{ | ||
quaternion_vector_filled = true; | ||
|
||
_imu_accel_x_vector.pop_front(); | ||
_imu_accel_y_vector.pop_front(); | ||
_imu_accel_z_vector.pop_front(); | ||
} | ||
} | ||
|
||
bool Lddc::CalibrateLivoxCb(std_srvs::srv::Trigger::Request::SharedPtr req, std_srvs::srv::Trigger::Response::SharedPtr res){ | ||
|
||
if(quaternion_vector_filled){ | ||
|
||
#ifdef BUILDING_ROS1 | ||
PublisherPtr publisher_ptr = GetCurrentQuaternionPublisher(); | ||
#elif defined BUILDING_ROS2 | ||
Publisher<QuaternionMsg>::SharedPtr publisher_ptr = std::dynamic_pointer_cast<Publisher<QuaternionMsg>>(GetCurrentQuaternionPublisher()); | ||
#endif | ||
|
||
double accel_x = std::accumulate(_imu_accel_x_vector.begin(), _imu_accel_x_vector.end(), 0.0) / _imu_accel_x_vector.size(); | ||
double accel_y = std::accumulate(_imu_accel_y_vector.begin(), _imu_accel_y_vector.end(), 0.0) / _imu_accel_y_vector.size(); | ||
double accel_z = std::accumulate(_imu_accel_z_vector.begin(), _imu_accel_z_vector.end(), 0.0) / _imu_accel_z_vector.size(); | ||
|
||
double livox_pitch = atan2((-accel_x), sqrt(accel_y * accel_y + accel_z * accel_z)); | ||
double livox_roll = atan2(accel_y, sqrt(accel_x * accel_x + accel_z * accel_z)); | ||
|
||
std::cout << "ROLL: " << livox_roll*57.2958 << std::endl; | ||
std::cout << "PITCH: " << livox_pitch*57.2958 << std::endl; | ||
Comment on lines
+537
to
+538
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this logs shouldn't be necessary anymore |
||
double livox__yaw = 0.0; | ||
|
||
tf2::Quaternion _Quaternion; | ||
_Quaternion.setRPY(livox_roll, livox_pitch, livox__yaw); | ||
geometry_msgs::msg::Quaternion Quaternion_msg; | ||
Quaternion_msg = tf2::toMsg(_Quaternion); | ||
if (kOutputToRos == output_type_) { | ||
publisher_ptr->publish(Quaternion_msg); | ||
} else { | ||
#ifdef BUILDING_ROS1 | ||
if (bag_ && enable_lidar_bag_) { | ||
bag_->write(publisher_ptr->getTopic(), ros::Time(timestamp / 1000000000.0), cloud); | ||
} | ||
#endif | ||
} | ||
|
||
_imu_accel_x_vector.clear(); | ||
_imu_accel_y_vector.clear(); | ||
_imu_accel_z_vector.clear(); | ||
|
||
quaternion_vector_filled=false; | ||
|
||
return true; | ||
} | ||
else{ | ||
return false; | ||
} | ||
} | ||
|
||
|
||
void Lddc::PublishImuData(LidarImuDataQueue& imu_data_queue, const uint8_t index) { | ||
ImuData imu_data; | ||
if (!imu_data_queue.Pop(imu_data)) { | ||
|
@@ -505,7 +576,7 @@ void Lddc::PublishImuData(LidarImuDataQueue& imu_data_queue, const uint8_t index | |
ImuMsg imu_msg; | ||
uint64_t timestamp; | ||
InitImuMsg(imu_data, imu_msg, timestamp); | ||
|
||
StoreAccelerationValues(imu_msg); | ||
#ifdef BUILDING_ROS1 | ||
PublisherPtr publisher_ptr = GetCurrentImuPublisher(index); | ||
#elif defined BUILDING_ROS2 | ||
|
@@ -547,11 +618,29 @@ std::shared_ptr<rclcpp::PublisherBase> Lddc::CreatePublisher(uint8_t msg_type, | |
"%s publish use imu format", topic_name.c_str()); | ||
return cur_node_->create_publisher<ImuMsg>(topic_name, | ||
queue_size); | ||
} | ||
else if (kLivoxQuaternionMsg == msg_type) { | ||
rclcpp::PublisherOptionsWithAllocator<std::allocator<void>> options; | ||
options.use_intra_process_comm = rclcpp::IntraProcessSetting::Disable; | ||
DRIVER_INFO(*cur_node_, | ||
"%s publish use quaternion format", topic_name.c_str()); | ||
return cur_node_->create_publisher<QuaternionMsg>(topic_name,rclcpp::QoS(1).keep_all().transient_local().reliable(), options); | ||
} else { | ||
PublisherPtr null_publisher(nullptr); | ||
return null_publisher; | ||
} | ||
} | ||
std::shared_ptr<rclcpp::ServiceBase> Lddc::CreateService(uint8_t service_type, | ||
std::string &service_name) { | ||
if (kCalibrationSrv == service_type) { | ||
DRIVER_INFO(*cur_node_, | ||
"Using a service trigger service for calibration"); | ||
return cur_node_->create_service<TriggerSrv>(service_name,std::bind(&Lddc::CalibrateLivoxCb, this, std::placeholders::_1, std::placeholders::_2) ); | ||
} else { | ||
ServicePtr null_service(nullptr); | ||
return null_service; | ||
} | ||
} | ||
#endif | ||
|
||
#ifdef BUILDING_ROS1 | ||
|
@@ -688,6 +777,26 @@ std::shared_ptr<rclcpp::PublisherBase> Lddc::GetCurrentImuPublisher(uint8_t hand | |
return global_imu_pub_; | ||
} | ||
} | ||
|
||
std::shared_ptr<rclcpp::PublisherBase> Lddc::GetCurrentQuaternionPublisher() { | ||
uint32_t queue_size = kMinEthPacketQueueSize; | ||
if (!quaternion_imu_pub_) { | ||
std::string topic_name("livox/angles"); | ||
queue_size = queue_size * 8; // shared queue size is 256, for all lidars | ||
quaternion_imu_pub_ = CreatePublisher(kLivoxQuaternionMsg, topic_name, queue_size); | ||
} | ||
return quaternion_imu_pub_; | ||
} | ||
|
||
std::shared_ptr<rclcpp::ServiceBase> Lddc::GetCurrentCalibService() { | ||
if (!calib_service_) { | ||
std::string service_name("livox/calibration"); | ||
calib_service_ = CreateService(kCalibrationSrv, service_name); | ||
} | ||
|
||
return calib_service_; | ||
} | ||
|
||
#endif | ||
|
||
void Lddc::CreateBagFile(const std::string &file_name) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of
push_back
useemplace_back
for a better performance usehttps://www.geeksforgeeks.org/push_back-vs-emplace_back-in-cpp-stl-vectors/#:~:text=Everytime%20push_back%20a%20value%20to%20a%20vector%20%2C%20cpp%20will%20create%20a%20new%20vector%20which%20copied%20the%20new%20value%20from%20parameter%20and%20all%20values%20in%20the%20old%20vector%C2%A0