Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete ToF Distance Node example. #150

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ typedef struct
static int const MKRCAN_MCP2515_CS_PIN = 3;
static int const MKRCAN_MCP2515_INT_PIN = 7;
static uint8_t const OPEN_CYPHAL_NODE_ID = 14;

static CanardPortID const OPEN_CYPHAL_ID_DISTANCE_DATA = 1001U;

static OpenCyphalNodeData const OPEN_CYPHAL_NODE_INITIAL_DATA =
{
uavcan::node::Heartbeat_1_0<>::Mode::INITIALIZATION,
Expand Down Expand Up @@ -290,6 +293,12 @@ namespace tof
void onTofDistanceUpdate(drone::unit::Length const l)
{
DBG_INFO("[%05lu] Distance = %.3f m", millis(), l.value());

typedef uavcan::primitive::scalar::Real32_1_0<OPEN_CYPHAL_ID_DISTANCE_DATA> DistanceMessageType;
DistanceMessageType tof_distance_msg;
tof_distance_msg.data.value = l.value();

node_hdl.publish(tof_distance_msg);
}

}