-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from ethz-asl/feature/enu_frame
Feature/enu frame
- Loading branch information
Showing
16 changed files
with
286 additions
and
27 deletions.
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
60 changes: 60 additions & 0 deletions
60
piksi_multi_cpp/include/piksi_multi_cpp/sbp_callback_handler/geotf_handler.h
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,60 @@ | ||
#ifndef PIKSI_MULTI_CPP_SBP_CALLBACK_HANDLER_SBP_GEOTF_HANDLER_H_ | ||
#define PIKSI_MULTI_CPP_SBP_CALLBACK_HANDLER_SBP_GEOTF_HANDLER_H_ | ||
|
||
#include <geotf/geodetic_converter.h> | ||
#include <libsbp/navigation.h> | ||
#include <piksi_rtk_msgs/EnuOrigin.h> | ||
#include <ros/ros.h> | ||
#include <std_srvs/Empty.h> | ||
#include <Eigen/Dense> | ||
#include <memory> | ||
#include "piksi_multi_cpp/sbp_callback_handler/sbp_lambda_callback_handler.h" | ||
|
||
namespace piksi_multi_cpp { | ||
|
||
// Manages a geotf object to transform between frames. | ||
// The ENU frame is either set automatically to be the base station position, | ||
// through ROS parameters or reset through a service call. | ||
class GeoTfHandler { | ||
public: | ||
typedef std::shared_ptr<GeoTfHandler> Ptr; | ||
GeoTfHandler(const ros::NodeHandle& nh, | ||
const std::shared_ptr<sbp_state_t>& state); | ||
|
||
void setEnuOriginWgs84(const double lat, const double lon, const double alt); | ||
|
||
bool convertPosEcefToEnu(const Eigen::Vector3d& pos_ecef, | ||
const Eigen::Vector3d* pos_enu); | ||
|
||
inline geotf::GeodeticConverter getGeoTf() const { return geotf_; } | ||
|
||
GeoTfHandler(GeoTfHandler const&) = delete; | ||
void operator=(GeoTfHandler const&) = delete; | ||
|
||
private: | ||
void callbackToBasePosLlh(const msg_base_pos_llh_t& msg, const uint8_t len); | ||
void callbackToPosLlh(const msg_pos_llh_t& msg, const uint8_t len); | ||
bool setEnuOriginCallback(piksi_rtk_msgs::EnuOrigin::Request& req, | ||
piksi_rtk_msgs::EnuOrigin::Response& res); | ||
bool setEnuOriginFromBaseStation(std_srvs::Empty::Request& req, | ||
std_srvs::Empty::Response& res); | ||
bool setEnuOriginFromCurrentPos(std_srvs::Empty::Request& req, | ||
std_srvs::Empty::Response& res); | ||
|
||
SBPLambdaCallbackHandler<msg_base_pos_llh_t> base_pos_llh_handler_; | ||
SBPLambdaCallbackHandler<msg_pos_llh_t> pos_llh_handler_; | ||
geotf::GeodeticConverter geotf_; | ||
Eigen::Vector3d enu_origin_wgs84_; | ||
|
||
ros::NodeHandle nh_; | ||
ros::ServiceServer set_enu_origin_srv_; | ||
ros::ServiceServer set_enu_from_base_srv_; | ||
ros::ServiceServer set_enu_from_current_srv_; | ||
|
||
enum ResetEnuOrigin {kNo = 0, kFromBase, kFromCurrentPos}; | ||
ResetEnuOrigin reset_position_ = ResetEnuOrigin::kFromCurrentPos; | ||
}; | ||
|
||
} // namespace piksi_multi_cpp | ||
|
||
#endif // PIKSI_MULTI_CPP_SBP_CALLBACK_HANDLER_SBP_GEOTF_HANDLER_H_ |
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
54 changes: 54 additions & 0 deletions
54
.../include/piksi_multi_cpp/sbp_callback_handler/sbp_callback_handler_relay/ros_enu_relays.h
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,54 @@ | ||
#ifndef PIKSI_MULTI_CPP_SBP_CALLBACK_HANDLER_SBP_CALLBACK_HANDLER_RELAY_ROS_ENU_RELAYS_H_ | ||
#define PIKSI_MULTI_CPP_SBP_CALLBACK_HANDLER_SBP_CALLBACK_HANDLER_RELAY_ROS_ENU_RELAYS_H_ | ||
|
||
#include <geotf/geodetic_converter.h> | ||
#include <libsbp/navigation.h> | ||
#include <ros/assert.h> | ||
#include <Eigen/Dense> | ||
#include <optional> | ||
|
||
#include <geometry_msgs/PointStamped.h> | ||
#include <piksi_rtk_msgs/PositionWithCovarianceStamped.h> | ||
|
||
#include "piksi_multi_cpp/sbp_callback_handler/geotf_handler.h" | ||
#include "piksi_multi_cpp/sbp_callback_handler/ros_time_handler.h" | ||
#include "piksi_multi_cpp/sbp_callback_handler/sbp_callback_handler_relay/ros_relay.h" | ||
|
||
namespace piksi_multi_cpp { | ||
|
||
// Per default the ENU origin will be the base station position. But it can also | ||
// be set to the current rover position or a user defined position. | ||
template <class SbpMsgType, class RosMsgType> | ||
class RosEnuRelay : public RosRelay<SbpMsgType, RosMsgType> { | ||
public: | ||
inline RosEnuRelay(const ros::NodeHandle& nh, const uint16_t sbp_msg_type, | ||
const std::shared_ptr<sbp_state_t>& state, | ||
const std::string& topic, | ||
const RosTimeHandler::Ptr& ros_time_handler, | ||
const GeoTfHandler::Ptr& geotf_handler) | ||
: RosRelay<SbpMsgType, RosMsgType>(nh, sbp_msg_type, state, topic, | ||
ros_time_handler, "enu"), | ||
geotf_handler_(geotf_handler) {} | ||
|
||
protected: | ||
GeoTfHandler::Ptr geotf_handler_; | ||
}; | ||
|
||
class RosPosEnuRelay | ||
: public RosEnuRelay<msg_pos_ecef_t, geometry_msgs::PointStamped> { | ||
public: | ||
inline RosPosEnuRelay(const ros::NodeHandle& nh, | ||
const std::shared_ptr<sbp_state_t>& state, | ||
const RosTimeHandler::Ptr& ros_time_handler, | ||
const GeoTfHandler::Ptr& geotf_handler) | ||
: RosEnuRelay(nh, SBP_MSG_POS_ECEF, state, "pos_enu", ros_time_handler, | ||
geotf_handler) {} | ||
|
||
private: | ||
bool convertSbpMsgToRosMsg(const msg_pos_ecef_t& in, const uint8_t len, | ||
geometry_msgs::PointStamped* out) override; | ||
}; | ||
|
||
} // namespace piksi_multi_cpp | ||
|
||
#endif // PIKSI_MULTI_CPP_SBP_CALLBACK_HANDLER_SBP_CALLBACK_HANDLER_RELAY_ROS_ENU_RELAYS_H_ |
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
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,77 @@ | ||
#include "piksi_multi_cpp/sbp_callback_handler/geotf_handler.h" | ||
|
||
#include <functional> | ||
|
||
namespace piksi_multi_cpp { | ||
namespace s = std::placeholders; | ||
|
||
GeoTfHandler::GeoTfHandler(const ros::NodeHandle& nh, | ||
const std::shared_ptr<sbp_state_t>& state) | ||
: base_pos_llh_handler_{std::bind(&GeoTfHandler::callbackToBasePosLlh, this, | ||
s::_1, s::_2), | ||
SBP_MSG_BASE_POS_LLH, state}, | ||
pos_llh_handler_{ | ||
std::bind(&GeoTfHandler::callbackToPosLlh, this, s::_1, s::_2), | ||
SBP_MSG_POS_LLH, state}, | ||
nh_(nh) { | ||
geotf_.initFromRosParam(); | ||
if (geotf_.hasFrame("enu")) reset_position_ = ResetEnuOrigin::kNo; | ||
ROS_ERROR_COND( | ||
!geotf_.addFrameByEPSG("ecef", 4978), | ||
"Failed to add frame ecef as EPSG:4978. Be careful using converted " | ||
"positions"); | ||
ROS_ERROR_COND( | ||
!geotf_.addFrameByEPSG("wgs84", 4326), | ||
"Failed to add frame ecef as EPSG:4326. Be careful using converted " | ||
"positions"); | ||
|
||
set_enu_origin_srv_ = nh_.advertiseService( | ||
"set_enu_origin", &GeoTfHandler::setEnuOriginCallback, this); | ||
set_enu_from_base_srv_ = | ||
nh_.advertiseService("set_enu_origin_from_base_station", | ||
&GeoTfHandler::setEnuOriginFromBaseStation, this); | ||
set_enu_from_current_srv_ = | ||
nh_.advertiseService("set_enu_origin_from_current_pos", | ||
&GeoTfHandler::setEnuOriginFromCurrentPos, this); | ||
} | ||
|
||
void GeoTfHandler::setEnuOriginWgs84(const double lat, const double lon, | ||
const double alt) { | ||
geotf_.removeFrame("enu"); | ||
geotf_.addFrameByENUOrigin("enu", lat, lon, alt); | ||
reset_position_ = ResetEnuOrigin::kNo; | ||
} | ||
|
||
void GeoTfHandler::callbackToBasePosLlh(const msg_base_pos_llh_t& msg, | ||
const uint8_t len) { | ||
if (reset_position_ != ResetEnuOrigin::kFromBase) return; | ||
setEnuOriginWgs84(msg.lat, msg.lon, msg.height); | ||
} | ||
|
||
void GeoTfHandler::callbackToPosLlh(const msg_pos_llh_t& msg, | ||
const uint8_t len) { | ||
if (reset_position_ != ResetEnuOrigin::kFromCurrentPos) return; | ||
if (((msg.flags >> 0) & 0x7) == 0) return; // Fix invalid. | ||
setEnuOriginWgs84(msg.lat, msg.lon, msg.height); | ||
} | ||
|
||
bool GeoTfHandler::setEnuOriginCallback( | ||
piksi_rtk_msgs::EnuOrigin::Request& req, | ||
piksi_rtk_msgs::EnuOrigin::Response& res) { | ||
setEnuOriginWgs84(req.lat, req.lon, req.alt); | ||
return true; | ||
} | ||
|
||
bool GeoTfHandler::setEnuOriginFromBaseStation(std_srvs::Empty::Request& req, | ||
std_srvs::Empty::Response& res) { | ||
reset_position_ = ResetEnuOrigin::kFromBase; | ||
return true; | ||
} | ||
|
||
bool GeoTfHandler::setEnuOriginFromCurrentPos(std_srvs::Empty::Request& req, | ||
std_srvs::Empty::Response& res) { | ||
reset_position_ = ResetEnuOrigin::kFromCurrentPos; | ||
return true; | ||
} | ||
|
||
} // namespace piksi_multi_cpp |
Oops, something went wrong.