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 isHeadingGoodForControl () const
 
bool isVelocityValid () 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 headingGoodForControl_ = false
 
bool velocityValid_ = 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 160 of file cp_vehicle_local_position.cpp.

161{
162 std::lock_guard<std::mutex> lock(mutex_);
163 return refAlt_;
164}

References mutex_, and refAlt_.

◆ getRefLat()

double cl_px4_mr::CpVehicleLocalPosition::getRefLat ( ) const

Definition at line 148 of file cp_vehicle_local_position.cpp.

149{
150 std::lock_guard<std::mutex> lock(mutex_);
151 return refLat_;
152}

References mutex_, and refLat_.

◆ getRefLon()

double cl_px4_mr::CpVehicleLocalPosition::getRefLon ( ) const

Definition at line 154 of file cp_vehicle_local_position.cpp.

155{
156 std::lock_guard<std::mutex> lock(mutex_);
157 return refLon_;
158}

References mutex_, and refLon_.

◆ getRefTimestamp()

uint64_t cl_px4_mr::CpVehicleLocalPosition::getRefTimestamp ( ) const

Definition at line 166 of file cp_vehicle_local_position.cpp.

167{
168 std::lock_guard<std::mutex> lock(mutex_);
169 return refTimestamp_;
170}

References mutex_, and refTimestamp_.

◆ getX()

◆ getXyResetCounter()

uint8_t cl_px4_mr::CpVehicleLocalPosition::getXyResetCounter ( ) const

Definition at line 172 of file cp_vehicle_local_position.cpp.

173{
174 std::lock_guard<std::mutex> lock(mutex_);
175 return xyResetCounter_;
176}

References mutex_, and xyResetCounter_.

◆ getY()

◆ getZ()

◆ getZResetCounter()

uint8_t cl_px4_mr::CpVehicleLocalPosition::getZResetCounter ( ) const

Definition at line 178 of file cp_vehicle_local_position.cpp.

179{
180 std::lock_guard<std::mutex> lock(mutex_);
181 return zResetCounter_;
182}

References mutex_, and zResetCounter_.

◆ globalRefValid()

bool cl_px4_mr::CpVehicleLocalPosition::globalRefValid ( ) const

Definition at line 142 of file cp_vehicle_local_position.cpp.

143{
144 std::lock_guard<std::mutex> lock(mutex_);
146}
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:

◆ isHeadingGoodForControl()

bool cl_px4_mr::CpVehicleLocalPosition::isHeadingGoodForControl ( ) const

Definition at line 130 of file cp_vehicle_local_position.cpp.

131{
132 std::lock_guard<std::mutex> lock(mutex_);
134}

References headingGoodForControl_, and mutex_.

Referenced by cl_px4_mr::CbConnectMicroRosAgent::onEntry().

Here is the caller graph for this function:

◆ isValid()

◆ isVelocityValid()

bool cl_px4_mr::CpVehicleLocalPosition::isVelocityValid ( ) const

Definition at line 136 of file cp_vehicle_local_position.cpp.

137{
138 std::lock_guard<std::mutex> lock(mutex_);
139 return velocityValid_;
140}

References mutex_, and velocityValid_.

Referenced by cl_px4_mr::CbConnectMicroRosAgent::onEntry().

Here is the caller graph for this function:

◆ 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 headingGoodForControl_ = msg->heading_good_for_control;
46 velocityValid_ = msg->v_xy_valid && msg->v_z_valid;
47
48 // global reference of the local frame
49 xyGlobal_ = msg->xy_global;
50 zGlobal_ = msg->z_global;
51 refAlt_ = msg->ref_alt;
52 if (msg->xy_global && (!projection_.isInitialized() || msg->ref_timestamp != refTimestamp_))
53 {
54 refLat_ = msg->ref_lat;
55 refLon_ = msg->ref_lon;
56 refTimestamp_ = msg->ref_timestamp;
58 RCLCPP_INFO(
59 getLogger(),
60 "CpVehicleLocalPosition: global reference set - NED origin at lat=%.7f lon=%.7f "
61 "alt=%.1f m AMSL",
62 refLat_, refLon_, static_cast<double>(refAlt_));
63 }
64
65 // EKF origin resets
66 if (!firstMessage_)
67 {
68 if (msg->xy_reset_counter != xyResetCounter_)
69 {
70 RCLCPP_WARN(
71 getLogger(),
72 "CpVehicleLocalPosition: local XY reset #%u (delta_xy=[%.2f, %.2f]); running paths "
73 "are NOT re-projected",
74 msg->xy_reset_counter, static_cast<double>(msg->delta_xy[0]),
75 static_cast<double>(msg->delta_xy[1]));
76 resetDetected = true;
77 }
78 if (msg->z_reset_counter != zResetCounter_)
79 {
80 RCLCPP_WARN(
81 getLogger(),
82 "CpVehicleLocalPosition: local Z reset #%u (delta_z=%.2f); running paths are NOT "
83 "re-projected",
84 msg->z_reset_counter, static_cast<double>(msg->delta_z));
85 resetDetected = true;
86 }
87 }
88 xyResetCounter_ = msg->xy_reset_counter;
89 zResetCounter_ = msg->z_reset_counter;
90 firstMessage_ = false;
91 }
92
93 if (resetDetected)
94 {
96 }
98}
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_, headingGoodForControl_, cl_px4_mr::MapProjection::initReference(), cl_px4_mr::MapProjection::isInitialized(), mutex_, onLocalPositionReset_, onPositionReceived_, projection_, refAlt_, refLat_, refLon_, refTimestamp_, valid_, velocityValid_, 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 184 of file cp_vehicle_local_position.cpp.

185{
186 std::lock_guard<std::mutex> lock(mutex_);
188 {
189 return false;
190 }
191 projection_.project(lat, lon, x, y);
192 return true;
193}
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 195 of file cp_vehicle_local_position.cpp.

196{
197 std::lock_guard<std::mutex> lock(mutex_);
199 {
200 return false;
201 }
202 projection_.reproject(x, y, lat, lon);
203 return true;
204}
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 92 of file cp_vehicle_local_position.hpp.

Referenced by onPositionMessage().

◆ heading_

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

Definition at line 79 of file cp_vehicle_local_position.hpp.

Referenced by getHeading(), and onPositionMessage().

◆ headingGoodForControl_

bool cl_px4_mr::CpVehicleLocalPosition::headingGoodForControl_ = false
private

Definition at line 81 of file cp_vehicle_local_position.hpp.

Referenced by isHeadingGoodForControl(), and onPositionMessage().

◆ mutex_

◆ onLocalPositionReset_

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

Definition at line 70 of file cp_vehicle_local_position.hpp.

Referenced by onPositionMessage().

◆ onPositionReceived_

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

Definition at line 69 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 88 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 86 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 87 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 89 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 75 of file cp_vehicle_local_position.hpp.

Referenced by onInitialize().

◆ valid_

bool cl_px4_mr::CpVehicleLocalPosition::valid_ = false
private

Definition at line 80 of file cp_vehicle_local_position.hpp.

Referenced by isValid(), and onPositionMessage().

◆ velocityValid_

bool cl_px4_mr::CpVehicleLocalPosition::velocityValid_ = false
private

Definition at line 82 of file cp_vehicle_local_position.hpp.

Referenced by isVelocityValid(), and onPositionMessage().

◆ x_

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

Definition at line 76 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 90 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 77 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 78 of file cp_vehicle_local_position.hpp.

Referenced by getZ(), and onPositionMessage().

◆ zGlobal_

bool cl_px4_mr::CpVehicleLocalPosition::zGlobal_ = false
private

Definition at line 85 of file cp_vehicle_local_position.hpp.

Referenced by onPositionMessage().

◆ zResetCounter_

uint8_t cl_px4_mr::CpVehicleLocalPosition::zResetCounter_ = 0
private

Definition at line 91 of file cp_vehicle_local_position.hpp.

Referenced by getZResetCounter(), and onPositionMessage().


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