This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 120
Split magnetometer node into C++ class and header #817
Closed
Closed
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "Magnetometer.h" | ||
|
||
#include <ros/ros.h> | ||
#include <geometry_msgs/Vector3Stamped.h> | ||
#include <sensor_msgs/MagneticField.h> | ||
|
||
Magnetometer::Magnetometer() | ||
{ | ||
ros::NodeHandle nh; | ||
ros::NodeHandle pnh("~"); | ||
std::string sub_topic = pnh.param("mag_sub_topic", std::string("/magnetometer/vector")); | ||
std::string pub_topic = pnh.param("mag_pub_topic", std::string("/magnetometer_mag")); | ||
g_mag_field_covar = pnh.param("mag_field_variance", 1e-6); | ||
g_mag_field_pub = nh.advertise<sensor_msgs::MagneticField>(pub_topic, 10); | ||
ros::Subscriber scan_sub = nh.subscribe(sub_topic, 1, magCallback); | ||
} | ||
|
||
void magCallback(const geometry_msgs::Vector3Stamped& msg) | ||
{ | ||
sensor_msgs::MagneticField magnet_msg; | ||
magnet_msg.header.seq = msg.header.seq; | ||
magnet_msg.header.stamp = msg.header.stamp; | ||
magnet_msg.header.frame_id = msg.header.frame_id; | ||
magnet_msg.magnetic_field.x = msg.vector.x; | ||
magnet_msg.magnetic_field.y = msg.vector.y; | ||
magnet_msg.magnetic_field.z = msg.vector.z; | ||
magnet_msg.magnetic_field_covariance = { g_mag_field_covar, 0, 0, 0, g_mag_field_covar, 0, 0, 0, g_mag_field_covar }; | ||
g_mag_field_pub.publish(magnet_msg); | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
ros::init(argc, argv, "mag_republisher"); | ||
Magnetometer m; | ||
ros::spin(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Magnetometer.h | ||
#ifndef Magnetometer_H | ||
#define Magnetometer_H | ||
|
||
#include <ros/ros.h> | ||
#include <sensor_msgs/MagneticField.h> | ||
|
||
class Magnetometer | ||
{ | ||
|
||
public: | ||
Magnetometer::Magnetometer(); | ||
private: | ||
ros::Publisher mag_field_pub; | ||
static double mag_field_covar; | ||
void magCallback(const geometry_msgs::Vector3Stamped& msg); | ||
}; | ||
#endif |
This file was deleted.
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.
Here you are still using the
g_
prefix, while the member variable does not have it. Remove theg_
prefix.