Skip to content

Commit 835cf20

Browse files
committed
added desired heading callback
1 parent 6a26537 commit 835cf20

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/network_systems/projects/can_transceiver/src/can_frame_parser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,8 @@ std::string DesiredHeading::debugStr() const
747747
std::string DesiredHeading::toString() const
748748
{
749749
std::stringstream ss;
750-
ss << "[DESIRED HEADING] Heading: " << heading_;
750+
ss << "[DESIRED HEADING] Heading: " << heading_ << "\n"
751+
<< "Steering bit: " << steering_ << "\n";
751752
return ss.str();
752753
}
753754

src/network_systems/projects/can_transceiver/src/can_transceiver_ros_intf.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class CanTransceiverIntf : public NetNode
8989

9090
sail_cmd_sub_ = this->create_subscription<msg::SailCmd>(
9191
ros_topics::SAIL_CMD, QUEUE_SIZE, [this](msg::SailCmd sail_cmd_) { subSailCmdCb(sail_cmd_); });
92+
desired_heading_sub_ = this->create_subscription<msg::DesiredHeading>(
93+
ros_topics::DESIRED_HEADING, QUEUE_SIZE,
94+
[this](msg::DesiredHeading desired_heading_) { subDesiredHeading(desired_heading_); });
9295

9396
if (mode == SYSTEM_MODE::DEV) { // Initialize the CAN Sim Intf
9497
mock_ais_sub_ = this->create_subscription<msg::AISShips>(
@@ -129,6 +132,7 @@ class CanTransceiverIntf : public NetNode
129132
rclcpp::Publisher<msg::GenericSensors>::SharedPtr generic_sensors_pub_;
130133
msg::GenericSensors generic_sensors_;
131134
rclcpp::Subscription<msg::DesiredHeading>::SharedPtr desired_heading_sub_;
135+
msg::DesiredHeading desired_heading_;
132136
rclcpp::Subscription<msg::SailCmd>::SharedPtr sail_cmd_sub_;
133137
msg::SailCmd sail_cmd_;
134138

@@ -213,7 +217,7 @@ class CanTransceiverIntf : public NetNode
213217
* @brief Publish a GPS frame
214218
* Intended to be registered as a callback with the CAN Tranceiver instance
215219
*
216-
* @param gps_frame gps CAN rfame read from the CAN bus
220+
* @param gps_frame gps CAN frame read from the CAN bus
217221
*/
218222
void publishGPS(const CanFrame & gps_frame)
219223
{
@@ -307,6 +311,23 @@ class CanTransceiverIntf : public NetNode
307311
RCLCPP_INFO(this->get_logger(), "%s %s", getCurrentTimeString().c_str(), ss.str().c_str());
308312
}
309313

314+
/**
315+
* @brief Subscribe to a MAIN_HEADING frame
316+
* Intended to be registered as a callback with the CAN Tranceiver instance
317+
*
318+
* @param heading_frame main_heading CAN frame read from the CAN bus
319+
*/
320+
void subDesiredHeading(msg::DesiredHeading & desired_heading_input)
321+
{
322+
msg::HelperHeading helper_msg;
323+
helper_msg = desired_heading_input.heading;
324+
desired_heading_.set__heading(helper_msg);
325+
desired_heading_.set__steering(desired_heading_input.steering);
326+
auto main_heading_frame = CAN_FP::DesiredHeading(desired_heading_, CanId::MAIN_HEADING);
327+
can_trns_->send(main_heading_frame.toLinuxCan());
328+
RCLCPP_INFO(this->get_logger(), "%s %s", getCurrentTimeString().c_str(), main_heading_frame.toString().c_str());
329+
}
330+
310331
// SIMULATION CALLBACKS //
311332

312333
/**

0 commit comments

Comments
 (0)