Skip to content

Commit ecb222c

Browse files
uavcannode: implement hardpoint commands (#26334)
* implement cannode hardpoint commands Signed-off-by: dirksavage88 <[email protected]> * Update src/drivers/uavcannode/Subscribers/HardpointCommand.hpp Co-authored-by: Jacob Dahl <[email protected]> * Update src/drivers/uavcannode/Subscribers/HardpointCommand.hpp Co-authored-by: Jacob Dahl <[email protected]> * add hardpoint sub to ark cannode, simplify handling of hardpoint broadcast Signed-off-by: dirksavage88 <[email protected]> --------- Signed-off-by: dirksavage88 <[email protected]> Co-authored-by: Jacob Dahl <[email protected]>
1 parent a5a7dd8 commit ecb222c

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed

boards/ark/cannode/default.px4board

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ CONFIG_UAVCANNODE_ESC_RAW_COMMAND=y
3131
CONFIG_UAVCANNODE_ESC_STATUS=y
3232
CONFIG_UAVCANNODE_FLOW_MEASUREMENT=y
3333
CONFIG_UAVCANNODE_GNSS_FIX=y
34+
CONFIG_UAVCANNODE_HARDPOINT_COMMAND=y
3435
CONFIG_UAVCANNODE_HYGROMETER_MEASUREMENT=y
3536
CONFIG_UAVCANNODE_LIGHTS_COMMAND=y
3637
CONFIG_UAVCANNODE_MAGNETIC_FIELD_STRENGTH=y

src/drivers/uavcannode/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ if DRIVERS_UAVCANNODE
3434
bool "Include GNSS fix"
3535
default n
3636

37+
config UAVCANNODE_HARDPOINT_COMMAND
38+
bool "Include hardpoint commands"
39+
default n
40+
3741
config UAVCANNODE_HYGROMETER_MEASUREMENT
3842
bool "Include hygrometer measurement"
3943
default n
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/****************************************************************************
2+
*
3+
* Copyright (c) 2026 PX4 Development Team. All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in
13+
* the documentation and/or other materials provided with the
14+
* distribution.
15+
* 3. Neither the name PX4 nor the names of its contributors may be
16+
* used to endorse or promote products derived from this software
17+
* without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
* POSSIBILITY OF SUCH DAMAGE.
31+
*
32+
****************************************************************************/
33+
34+
#pragma once
35+
36+
#include "UavcanSubscriberBase.hpp"
37+
38+
#include <uavcan/equipment/hardpoint/Command.hpp>
39+
40+
#include <uORB/Publication.hpp>
41+
#include <uORB/topics/actuator_servos.h>
42+
43+
namespace uavcannode
44+
{
45+
46+
class HardpointCommand;
47+
48+
typedef uavcan::MethodBinder<HardpointCommand *,
49+
void (HardpointCommand::*)(const uavcan::ReceivedDataStructure<uavcan::equipment::hardpoint::Command>&)>
50+
HardpointCommandBinder;
51+
52+
class HardpointCommand :
53+
public UavcanSubscriberBase,
54+
private uavcan::Subscriber<uavcan::equipment::hardpoint::Command, HardpointCommandBinder>
55+
{
56+
public:
57+
HardpointCommand(uavcan::INode &node) :
58+
UavcanSubscriberBase(uavcan::equipment::hardpoint::Command::DefaultDataTypeID),
59+
uavcan::Subscriber<uavcan::equipment::hardpoint::Command, HardpointCommandBinder>(node)
60+
{}
61+
62+
bool init()
63+
{
64+
if (start(HardpointCommandBinder(this, &HardpointCommand::callback)) < 0) {
65+
PX4_ERR("uavcan::equipment::hardpoint::Command subscription failed");
66+
return false;
67+
}
68+
69+
return true;
70+
}
71+
72+
void PrintInfo() const override
73+
{
74+
printf("\t%s:%d -> %s\n",
75+
uavcan::equipment::hardpoint::Command::getDataTypeFullName(),
76+
uavcan::equipment::hardpoint::Command::DefaultDataTypeID,
77+
_actuator_servos_pub.get_topic()->o_name);
78+
}
79+
80+
private:
81+
void callback(const uavcan::ReceivedDataStructure<uavcan::equipment::hardpoint::Command> &msg)
82+
{
83+
84+
uint8_t servo_id = msg.hardpoint_id;
85+
actuator_servos_s actuator_servos {};
86+
87+
if (servo_id >= actuator_servos_s::NUM_CONTROLS) {
88+
return;
89+
}
90+
91+
for (uint8_t i = servo_id; i < actuator_servos_s::NUM_CONTROLS; ++i) {
92+
93+
actuator_servos.timestamp = hrt_absolute_time();
94+
actuator_servos.timestamp_sample = actuator_servos.timestamp;
95+
96+
if (msg.command == 1) {
97+
actuator_servos.control[i] = 1; // grip
98+
99+
} else if (msg.command == 0) {
100+
actuator_servos.control[i] = -1; // release
101+
102+
} else {
103+
actuator_servos.control[i] = 0; // do nothing
104+
}
105+
106+
actuator_servos.timestamp = hrt_absolute_time();
107+
actuator_servos.timestamp_sample = actuator_servos.timestamp;
108+
109+
// If ID is not 0 (broadcast), do not iterate
110+
if (servo_id != 0) {
111+
break;
112+
}
113+
114+
}
115+
116+
_actuator_servos_pub.publish(actuator_servos);
117+
118+
}
119+
120+
uORB::Publication<actuator_servos_s> _actuator_servos_pub{ORB_ID(actuator_servos)};
121+
122+
};
123+
} // namespace uavcannode

src/drivers/uavcannode/UavcanNode.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@
121121
#include "Subscribers/ServoArrayCommand.hpp"
122122
#endif // CONFIG_UAVCANNODE_SERVO_ARRAY_COMMAND
123123

124+
#if defined(CONFIG_UAVCANNODE_HARDPOINT_COMMAND)
125+
#include "Subscribers/HardpointCommand.hpp"
126+
#endif // CONFIG_UAVCANNODE_HARDPOINT_COMMAND
127+
124128
using namespace time_literals;
125129

126130
namespace uavcannode
@@ -485,6 +489,10 @@ int UavcanNode::init(uavcan::NodeID node_id, UAVCAN_DRIVER::BusEvent &bus_events
485489
_subscriber_list.add(new ServoArrayCommand(_node));
486490
#endif // CONFIG_UAVCANNODE_SERVO_ARRAY_COMMAND
487491

492+
#if defined(CONFIG_UAVCANNODE_HARDPOINT_COMMAND)
493+
_subscriber_list.add(new HardpointCommand(_node));
494+
#endif // CONFIG_UAVCANNODE_HARDPOINT_COMMAND
495+
488496
for (auto &subscriber : _subscriber_list) {
489497
subscriber->init();
490498
}

0 commit comments

Comments
 (0)