47 #include "uavcan_driver.hpp" 48 #include <uavcan/helpers/heap_based_pool_allocator.hpp> 49 #include <uavcan/protocol/global_time_sync_master.hpp> 50 #include <uavcan/protocol/global_time_sync_slave.hpp> 51 #include <uavcan/protocol/node_status_monitor.hpp> 52 #include <uavcan/protocol/param/GetSet.hpp> 53 #include <uavcan/protocol/param/ExecuteOpcode.hpp> 54 #include <uavcan/protocol/RestartNode.hpp> 56 #include <drivers/device/device.h> 59 #include <uORB/topics/actuator_controls.h> 60 #include <uORB/topics/actuator_outputs.h> 61 #include <uORB/topics/actuator_armed.h> 62 #include <uORB/topics/test_motor.h> 63 #include <uORB/topics/actuator_direct.h> 67 #include "sensors/sensor_bridge.hpp" 70 #include "allocator.hpp" 72 #define NUM_ACTUATOR_CONTROL_GROUPS_UAVCAN 4 75 #define UAVCAN_NUM_POLL_FDS (NUM_ACTUATOR_CONTROL_GROUPS_UAVCAN+2) 82 static constexpr
unsigned MaxBitRatePerSec = 1000000;
83 static constexpr
unsigned bitPerFrame = 148;
84 static constexpr
unsigned FramePerSecond = MaxBitRatePerSec / bitPerFrame;
85 static constexpr
unsigned FramePerMSecond = ((FramePerSecond / 1000) + 1);
87 static constexpr
unsigned PollTimeoutMs = 3;
102 static constexpr
unsigned RxQueueLenPerIface = FramePerMSecond * PollTimeoutMs;
103 static constexpr
unsigned StackSize = 2400;
106 typedef UAVCAN_DRIVER::CanInitHelper<RxQueueLenPerIface> CanInitHelper;
107 enum eServerAction {None, Start, Stop, CheckFW, Busy};
109 UavcanNode(uavcan::ICanDriver &can_driver, uavcan::ISystemClock &system_clock);
113 virtual int ioctl(file *filp,
int cmd,
unsigned long arg);
115 static int start(uavcan::NodeID node_id, uint32_t bitrate);
117 uavcan::Node<> &get_node() {
return _node; }
120 static int control_callback(uintptr_t handle, uint8_t control_group, uint8_t control_index,
float &input);
126 int arm_actuators(
bool arm);
132 void hardpoint_controller_set(uint8_t hardpoint_id, uint16_t command);
134 static UavcanNode *instance() {
return _instance; }
135 static int getHardwareVersion(uavcan::protocol::HardwareVersion &hwver);
136 int fw_server(eServerAction action);
137 void attachITxQueueInjector(
ITxQueueInjector *injector) {_tx_injector = injector;}
138 int list_params(
int remote_node_id);
139 int save_params(
int remote_node_id);
140 int set_param(
int remote_node_id,
const char *name,
char *value);
141 int get_param(
int remote_node_id,
const char *name);
142 int reset_node(
int remote_node_id);
145 void fill_node_info();
146 int init(uavcan::NodeID node_id);
147 void node_spin_once();
149 int add_poll_fd(
int fd);
150 int start_fw_server();
151 int stop_fw_server();
152 int request_fw_check();
153 int print_params(uavcan::protocol::param::GetSet::Response &resp);
154 int get_set_param(
int nodeid,
const char *name, uavcan::protocol::param::GetSet::Request &req);
155 void update_params();
156 void set_setget_response(uavcan::protocol::param::GetSet::Response *resp)
158 _setget_response = resp;
160 void free_setget_response(
void)
162 _setget_response =
nullptr;
166 bool _task_should_exit =
false;
167 volatile eServerAction _fw_server_action;
168 int _fw_server_status;
170 actuator_armed_s _armed = {};
171 bool _is_armed =
false;
173 int _test_motor_sub = -1;
174 test_motor_s _test_motor = {};
175 bool _test_in_progress =
false;
177 unsigned _output_count = 0;
183 uavcan::Node<> _node;
184 pthread_mutex_t _node_mutex;
185 px4_sem_t _server_command_sem;
188 uavcan::GlobalTimeSyncMaster _time_sync_master;
189 uavcan::GlobalTimeSyncSlave _time_sync_slave;
190 uavcan::NodeStatusMonitor _node_status_monitor;
196 uint32_t _groups_required = 0;
197 uint32_t _groups_subscribed = 0;
198 int _control_subs[NUM_ACTUATOR_CONTROL_GROUPS_UAVCAN];
199 actuator_controls_s _controls[NUM_ACTUATOR_CONTROL_GROUPS_UAVCAN] = {};
200 orb_id_t _control_topics[NUM_ACTUATOR_CONTROL_GROUPS_UAVCAN] = {};
201 pollfd _poll_fds[UAVCAN_NUM_POLL_FDS] = {};
202 unsigned _poll_fds_num = 0;
203 int32_t _idle_throttle_when_armed = 0;
205 int _actuator_direct_sub = -1;
206 uint8_t _actuator_direct_poll_fd_num = 0;
207 actuator_direct_s _actuator_direct = {};
209 actuator_outputs_s _outputs = {};
213 Mixer::Airmode _airmode = Mixer::Airmode::disabled;
216 uint8_t _poll_ids[NUM_ACTUATOR_CONTROL_GROUPS_UAVCAN];
218 void handle_time_sync(
const uavcan::TimerEvent &);
220 typedef uavcan::MethodBinder<UavcanNode *, void (UavcanNode::*)(const uavcan::TimerEvent &)> TimerCallback;
221 uavcan::TimerEventForwarder<TimerCallback> _master_timer;
223 bool _callback_success;
224 uavcan::protocol::param::GetSet::Response *_setget_response;
226 void (UavcanNode::*)(
const uavcan::ServiceCallResult<uavcan::protocol::param::GetSet> &)> GetSetCallback;
227 typedef uavcan::MethodBinder<UavcanNode *,
228 void (UavcanNode::*)(
const uavcan::ServiceCallResult<uavcan::protocol::param::ExecuteOpcode> &)> ExecuteOpcodeCallback;
229 typedef uavcan::MethodBinder<UavcanNode *,
230 void (UavcanNode::*)(
const uavcan::ServiceCallResult<uavcan::protocol::RestartNode> &)> RestartNodeCallback;
231 void cb_setget(
const uavcan::ServiceCallResult<uavcan::protocol::param::GetSet> &result);
232 void cb_opcode(
const uavcan::ServiceCallResult<uavcan::protocol::param::ExecuteOpcode> &result);
233 void cb_restart(
const uavcan::ServiceCallResult<uavcan::protocol::RestartNode> &result);
Configuration flags used in code.
UAVCAN <–> ORB bridge for ESC messages: uavcan.equipment.esc.RawCommand uavcan.equipment.esc.RPMCommand uavcan.equipment.esc.Status.
A UAVCAN node.
Definition: uavcan_main.hpp:80
Group of mixers, built up from single mixers and processed in order when mixing.
Definition: mixer.h:329
The UavcanHardpointController class.
Definition: hardpoint.hpp:51
This interface defines one method that will be called by the main node thread periodically in order t...
Definition: uavcan_virtual_can_driver.hpp:323
Abstract class for any character device.
Definition: CDev.hpp:58
Defines basic functionality of UAVCAN node.
Definition: allocator.hpp:53
Performance measuring tools.