SMACC2
Loading...
Searching...
No Matches
cl_px4_mr::CpVehicleLocalPosition Class Reference

#include <cp_vehicle_local_position.hpp>

Inheritance diagram for cl_px4_mr::CpVehicleLocalPosition:
Inheritance graph
Collaboration diagram for cl_px4_mr::CpVehicleLocalPosition:
Collaboration graph

Public Member Functions

 CpVehicleLocalPosition ()
 
virtual ~CpVehicleLocalPosition ()
 
void onInitialize () override
 
float getX () const
 
float getY () const
 
float getZ () const
 
float getHeading () const
 
bool isValid () const
 
bool globalRefValid () const
 
double getRefLat () const
 
double getRefLon () const
 
float getRefAlt () const
 
uint64_t getRefTimestamp () const
 
uint8_t getXyResetCounter () const
 
uint8_t getZResetCounter () const
 
bool projectToNed (double lat, double lon, float &x, float &y) const
 
bool reprojectFromNed (float x, float y, double &lat, double &lon) const
 
- Public Member Functions inherited from smacc2::ISmaccComponent
 ISmaccComponent ()
 
virtual ~ISmaccComponent ()
 
virtual std::string getName () const
 

Public Attributes

smacc2::SmaccSignal< void()> onPositionReceived_
 
smacc2::SmaccSignal< void()> onLocalPositionReset_
 

Private Member Functions

void onPositionMessage (const px4_msgs::msg::VehicleLocalPosition::SharedPtr msg)
 

Private Attributes

rclcpp::Subscription< px4_msgs::msg::VehicleLocalPosition >::SharedPtr subscriber_
 
float x_ = 0.0f
 
float y_ = 0.0f
 
float z_ = 0.0f
 
float heading_ = 0.0f
 
bool valid_ = false
 
bool xyGlobal_ = false
 
bool zGlobal_ = false
 
double refLat_ = 0.0
 
double refLon_ = 0.0
 
float refAlt_ = 0.0f
 
uint64_t refTimestamp_ = 0
 
uint8_t xyResetCounter_ = 0
 
uint8_t zResetCounter_ = 0
 
bool firstMessage_ = true
 
MapProjection projection_
 
std::mutex mutex_
 

Additional Inherited Members

- Protected Member Functions inherited from smacc2::ISmaccComponent
template<typename TOrthogonal , typename TClient >
void onComponentInitialization ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
template<typename TComponent >
void requiresComponent (TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TComponent >
void requiresComponent (std::string name, TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TClient >
void requiresClient (TClient *&requiredClientStorage)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingComponent (TArgs... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingNamedComponent (std::string name, TArgs... targs)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger () const
 
ISmaccStateMachine * getStateMachine ()
 
- Protected Attributes inherited from smacc2::ISmaccComponent
ISmaccStateMachine * stateMachine_
 
ISmaccClient * owner_
 

Detailed Description

Definition at line 36 of file cp_vehicle_local_position.hpp.

Constructor & Destructor Documentation

◆ CpVehicleLocalPosition()

cl_px4_mr::CpVehicleLocalPosition::CpVehicleLocalPosition ( )

Definition at line 20 of file cp_vehicle_local_position.cpp.

20{}

◆ ~CpVehicleLocalPosition()

cl_px4_mr::CpVehicleLocalPosition::~CpVehicleLocalPosition ( )
virtual

Definition at line 22 of file cp_vehicle_local_position.cpp.

22{}

Member Function Documentation

◆ getHeading()

◆ getRefAlt()

float cl_px4_mr::CpVehicleLocalPosition::getRefAlt ( ) const

Definition at line 146 of file cp_vehicle_local_position.cpp.

147{
148 std::lock_guard<std::mutex> lock(mutex_);
149 return refAlt_;
150}

References mutex_, and refAlt_.

◆ getRefLat()

double cl_px4_mr::CpVehicleLocalPosition::getRefLat ( ) const

Definition at line 134 of file cp_vehicle_local_position.cpp.

135{
136 std::lock_guard<std::mutex> lock(mutex_);
137 return refLat_;
138}

References mutex_, and refLat_.

◆ getRefLon()

double cl_px4_mr::CpVehicleLocalPosition::getRefLon ( ) const

Definition at line 140 of file cp_vehicle_local_position.cpp.

141{
142 std::lock_guard<std::mutex> lock(mutex_);
143 return refLon_;
144}

References mutex_, and refLon_.

◆ getRefTimestamp()

uint64_t cl_px4_mr::CpVehicleLocalPosition::getRefTimestamp ( ) const

Definition at line 152 of file cp_vehicle_local_position.cpp.

153{
154 std::lock_guard<std::mutex> lock(mutex_);
155 return refTimestamp_;
156}

References mutex_, and refTimestamp_.

◆ getX()

◆ getXyResetCounter()

uint8_t cl_px4_mr::CpVehicleLocalPosition::getXyResetCounter ( ) const

Definition at line 158 of file cp_vehicle_local_position.cpp.

159{
160 std::lock_guard<std::mutex> lock(mutex_);
161 return xyResetCounter_;
162}

References mutex_, and xyResetCounter_.

◆ getY()

◆ getZ()

float cl_px4_mr::CpVehicleLocalPosition::getZ ( ) const

◆ getZResetCounter()

uint8_t cl_px4_mr::CpVehicleLocalPosition::getZResetCounter ( ) const

Definition at line 164 of file cp_vehicle_local_position.cpp.

165{
166 std::lock_guard<std::mutex> lock(mutex_);
167 return zResetCounter_;
168}

References mutex_, and zResetCounter_.

◆ globalRefValid()

bool cl_px4_mr::CpVehicleLocalPosition::globalRefValid ( ) const

Definition at line 128 of file cp_vehicle_local_position.cpp.

129{
130 std::lock_guard<std::mutex> lock(mutex_);
132}
bool isInitialized() const
Definition geo_utils.hpp:89

References cl_px4_mr::MapProjection::isInitialized(), mutex_, projection_, and xyGlobal_.

Here is the call graph for this function:

◆ isValid()

bool cl_px4_mr::CpVehicleLocalPosition::isValid ( ) const

◆ onInitialize()

void cl_px4_mr::CpVehicleLocalPosition::onInitialize ( )
overridevirtual

Reimplemented from smacc2::ISmaccComponent.

Definition at line 24 of file cp_vehicle_local_position.cpp.

25{
26 auto node = this->getNode();
27 subscriber_ = node->create_subscription<px4_msgs::msg::VehicleLocalPosition>(
28 "/fmu/out/vehicle_local_position", rclcpp::SensorDataQoS(),
29 std::bind(&CpVehicleLocalPosition::onPositionMessage, this, std::placeholders::_1));
30 RCLCPP_INFO(getLogger(), "CpVehicleLocalPosition: subscribed to /fmu/out/vehicle_local_position");
31}
void onPositionMessage(const px4_msgs::msg::VehicleLocalPosition::SharedPtr msg)
rclcpp::Subscription< px4_msgs::msg::VehicleLocalPosition >::SharedPtr subscriber_
rclcpp::Logger getLogger() const
rclcpp::Node::SharedPtr getNode()

References smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::getNode(), onPositionMessage(), and subscriber_.

Here is the call graph for this function:

◆ onPositionMessage()

void cl_px4_mr::CpVehicleLocalPosition::onPositionMessage ( const px4_msgs::msg::VehicleLocalPosition::SharedPtr msg)
private

Definition at line 33 of file cp_vehicle_local_position.cpp.

35{
36 bool resetDetected = false;
37
38 {
39 std::lock_guard<std::mutex> lock(mutex_);
40 x_ = msg->x;
41 y_ = msg->y;
42 z_ = msg->z;
43 heading_ = msg->heading;
44 valid_ = msg->xy_valid && msg->z_valid;
45
46 // global reference of the local frame
47 xyGlobal_ = msg->xy_global;
48 zGlobal_ = msg->z_global;
49 refAlt_ = msg->ref_alt;
50 if (msg->xy_global && (!projection_.isInitialized() || msg->ref_timestamp != refTimestamp_))
51 {
52 refLat_ = msg->ref_lat;
53 refLon_ = msg->ref_lon;
54 refTimestamp_ = msg->ref_timestamp;
56 RCLCPP_INFO(
57 getLogger(),
58 "CpVehicleLocalPosition: global reference set - NED origin at lat=%.7f lon=%.7f "
59 "alt=%.1f m AMSL",
60 refLat_, refLon_, static_cast<double>(refAlt_));
61 }
62
63 // EKF origin resets
64 if (!firstMessage_)
65 {
66 if (msg->xy_reset_counter != xyResetCounter_)
67 {
68 RCLCPP_WARN(
69 getLogger(),
70 "CpVehicleLocalPosition: local XY reset #%u (delta_xy=[%.2f, %.2f]); running paths "
71 "are NOT re-projected",
72 msg->xy_reset_counter, static_cast<double>(msg->delta_xy[0]),
73 static_cast<double>(msg->delta_xy[1]));
74 resetDetected = true;
75 }
76 if (msg->z_reset_counter != zResetCounter_)
77 {
78 RCLCPP_WARN(
79 getLogger(),
80 "CpVehicleLocalPosition: local Z reset #%u (delta_z=%.2f); running paths are NOT "
81 "re-projected",
82 msg->z_reset_counter, static_cast<double>(msg->delta_z));
83 resetDetected = true;
84 }
85 }
86 xyResetCounter_ = msg->xy_reset_counter;
87 zResetCounter_ = msg->z_reset_counter;
88 firstMessage_ = false;
89 }
90
91 if (resetDetected)
92 {
94 }
96}
smacc2::SmaccSignal< void()> onPositionReceived_
smacc2::SmaccSignal< void()> onLocalPositionReset_
void initReference(double lat0, double lon0, uint64_t timestamp=0)
Definition geo_utils.hpp:79

References firstMessage_, smacc2::ISmaccComponent::getLogger(), heading_, cl_px4_mr::MapProjection::initReference(), cl_px4_mr::MapProjection::isInitialized(), mutex_, onLocalPositionReset_, onPositionReceived_, projection_, refAlt_, refLat_, refLon_, refTimestamp_, valid_, x_, xyGlobal_, xyResetCounter_, y_, z_, zGlobal_, and zResetCounter_.

Referenced by onInitialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ projectToNed()

bool cl_px4_mr::CpVehicleLocalPosition::projectToNed ( double lat,
double lon,
float & x,
float & y ) const

Definition at line 170 of file cp_vehicle_local_position.cpp.

171{
172 std::lock_guard<std::mutex> lock(mutex_);
174 {
175 return false;
176 }
177 projection_.project(lat, lon, x, y);
178 return true;
179}
void project(double lat, double lon, float &x, float &y) const
Definition geo_utils.hpp:95

References cl_px4_mr::MapProjection::isInitialized(), mutex_, cl_px4_mr::MapProjection::project(), projection_, and xyGlobal_.

Here is the call graph for this function:

◆ reprojectFromNed()

bool cl_px4_mr::CpVehicleLocalPosition::reprojectFromNed ( float x,
float y,
double & lat,
double & lon ) const

Definition at line 181 of file cp_vehicle_local_position.cpp.

182{
183 std::lock_guard<std::mutex> lock(mutex_);
185 {
186 return false;
187 }
188 projection_.reproject(x, y, lat, lon);
189 return true;
190}
void reproject(float x, float y, double &lat, double &lon) const

References cl_px4_mr::MapProjection::isInitialized(), mutex_, projection_, cl_px4_mr::MapProjection::reproject(), and xyGlobal_.

Here is the call graph for this function:

Member Data Documentation

◆ firstMessage_

bool cl_px4_mr::CpVehicleLocalPosition::firstMessage_ = true
private

Definition at line 85 of file cp_vehicle_local_position.hpp.

Referenced by onPositionMessage().

◆ heading_

float cl_px4_mr::CpVehicleLocalPosition::heading_ = 0.0f
private

Definition at line 74 of file cp_vehicle_local_position.hpp.

Referenced by getHeading(), and onPositionMessage().

◆ mutex_

◆ onLocalPositionReset_

smacc2::SmaccSignal<void()> cl_px4_mr::CpVehicleLocalPosition::onLocalPositionReset_

Definition at line 65 of file cp_vehicle_local_position.hpp.

Referenced by onPositionMessage().

◆ onPositionReceived_

smacc2::SmaccSignal<void()> cl_px4_mr::CpVehicleLocalPosition::onPositionReceived_

Definition at line 64 of file cp_vehicle_local_position.hpp.

Referenced by onPositionMessage().

◆ projection_

MapProjection cl_px4_mr::CpVehicleLocalPosition::projection_
private

◆ refAlt_

float cl_px4_mr::CpVehicleLocalPosition::refAlt_ = 0.0f
private

Definition at line 81 of file cp_vehicle_local_position.hpp.

Referenced by getRefAlt(), and onPositionMessage().

◆ refLat_

double cl_px4_mr::CpVehicleLocalPosition::refLat_ = 0.0
private

Definition at line 79 of file cp_vehicle_local_position.hpp.

Referenced by getRefLat(), and onPositionMessage().

◆ refLon_

double cl_px4_mr::CpVehicleLocalPosition::refLon_ = 0.0
private

Definition at line 80 of file cp_vehicle_local_position.hpp.

Referenced by getRefLon(), and onPositionMessage().

◆ refTimestamp_

uint64_t cl_px4_mr::CpVehicleLocalPosition::refTimestamp_ = 0
private

Definition at line 82 of file cp_vehicle_local_position.hpp.

Referenced by getRefTimestamp(), and onPositionMessage().

◆ subscriber_

rclcpp::Subscription<px4_msgs::msg::VehicleLocalPosition>::SharedPtr cl_px4_mr::CpVehicleLocalPosition::subscriber_
private

Definition at line 70 of file cp_vehicle_local_position.hpp.

Referenced by onInitialize().

◆ valid_

bool cl_px4_mr::CpVehicleLocalPosition::valid_ = false
private

Definition at line 75 of file cp_vehicle_local_position.hpp.

Referenced by isValid(), and onPositionMessage().

◆ x_

float cl_px4_mr::CpVehicleLocalPosition::x_ = 0.0f
private

Definition at line 71 of file cp_vehicle_local_position.hpp.

Referenced by getX(), and onPositionMessage().

◆ xyGlobal_

bool cl_px4_mr::CpVehicleLocalPosition::xyGlobal_ = false
private

◆ xyResetCounter_

uint8_t cl_px4_mr::CpVehicleLocalPosition::xyResetCounter_ = 0
private

Definition at line 83 of file cp_vehicle_local_position.hpp.

Referenced by getXyResetCounter(), and onPositionMessage().

◆ y_

float cl_px4_mr::CpVehicleLocalPosition::y_ = 0.0f
private

Definition at line 72 of file cp_vehicle_local_position.hpp.

Referenced by getY(), and onPositionMessage().

◆ z_

float cl_px4_mr::CpVehicleLocalPosition::z_ = 0.0f
private

Definition at line 73 of file cp_vehicle_local_position.hpp.

Referenced by getZ(), and onPositionMessage().

◆ zGlobal_

bool cl_px4_mr::CpVehicleLocalPosition::zGlobal_ = false
private

Definition at line 78 of file cp_vehicle_local_position.hpp.

Referenced by onPositionMessage().

◆ zResetCounter_

uint8_t cl_px4_mr::CpVehicleLocalPosition::zResetCounter_ = 0
private

Definition at line 84 of file cp_vehicle_local_position.hpp.

Referenced by getZResetCounter(), and onPositionMessage().


The documentation for this class was generated from the following files: