34 #ifndef UAVCAN_ACTUATORS_USE_CURRENT
35 #define UAVCAN_ACTUATORS_USE_CURRENT TRUE
53 #ifdef SERVOS_UAVCAN1_NB
56 #ifdef SERVOS_UAVCAN2_NB
59 #ifdef SERVOS_UAVCAN1CMD_NB
62 #ifdef SERVOS_UAVCAN2CMD_NB
67 #if SERVOS_UAVCAN1CMD_NB > SERVOS_UAVCAN1_NB
68 #define UAVCAN1_TELEM_NB SERVOS_UAVCAN1CMD_NB
70 #elif defined(SERVOS_UAVCAN1_NB)
71 #define UAVCAN1_TELEM_NB SERVOS_UAVCAN1_NB
75 #if SERVOS_UAVCAN2CMD_NB > SERVOS_UAVCAN2_NB
76 #define UAVCAN2_TELEM_NB SERVOS_UAVCAN2CMD_NB
78 #elif defined(SERVOS_UAVCAN2_NB)
79 #define UAVCAN2_TELEM_NB SERVOS_UAVCAN2_NB
84 #define UAVCAN_CMD_UNUSED (MIN_PPRZ-1)
87 #define UAVCAN_EQUIPMENT_ESC_STATUS_ID 1034
88 #define UAVCAN_EQUIPMENT_ESC_STATUS_SIGNATURE (0xA9AF28AEA2FBB254ULL)
89 #define UAVCAN_EQUIPMENT_ESC_STATUS_MAX_SIZE ((110 + 7)/8)
92 #define UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_ID 1030
93 #define UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_SIGNATURE (0x217F5C87D7EC951DULL)
94 #define UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_MAX_SIZE ((285 + 7)/8)
97 #define UAVCAN_EQUIPMENT_ACTUATOR_STATUS_ID 1011
98 #define UAVCAN_EQUIPMENT_ACTUATOR_STATUS_SIGNATURE (0x5E9BBA44FAF1EA04ULL)
99 #define UAVCAN_EQUIPMENT_ACTUATOR_STATUS_MAX_SIZE ((64 + 7)/8)
102 #define UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_ID 1010
103 #define UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_SIGNATURE (0xD8A7486238EC3AF3ULL)
104 #define UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_MAX_SIZE ((484 + 7)/8)
107 #define UAVCAN_EQUIPMENT_DEVICE_TEMPERATURE_ID 1110
108 #define UAVCAN_EQUIPMENT_DEVICE_TEMPERATURE_SIGNATURE (0x70261C28A94144C6ULL)
109 #define UAVCAN_EQUIPMENT_DEVICE_TEMPERATURE_MAX_SIZE ((40 + 7)/8)
117 #if PERIODIC_TELEMETRY
131 #ifdef UAVCAN1_TELEM_NB
133 if(uavcan1_telem[i].
set) {
136 return &uavcan1_telem[i];
141 offset += UAVCAN1_TELEM_NB;
143 #ifdef UAVCAN2_TELEM_NB
145 if(uavcan2_telem[i].
set) {
148 return &uavcan2_telem[i];
153 offset += UAVCAN2_TELEM_NB;
192 #ifdef UAVCAN1_TELEM_NB
193 if (iface == &uavcan1) {
194 telem = uavcan1_telem;
195 max_id = UAVCAN1_TELEM_NB;
198 #ifdef UAVCAN2_TELEM_NB
199 if (iface == &uavcan2) {
200 telem = uavcan2_telem;
201 max_id = UAVCAN2_TELEM_NB;
207 if (
esc_idx >= max_id || telem == NULL || max_id == 0) {
214 canardDecodeScalar(
transfer, 32, 16,
true, (
void *)&tmp_float);
215 telem[
esc_idx].
voltage = canardConvertFloat16ToNativeFloat(tmp_float);
216 canardDecodeScalar(
transfer, 48, 16,
true, (
void *)&tmp_float);
217 telem[
esc_idx].
current = canardConvertFloat16ToNativeFloat(tmp_float);
218 canardDecodeScalar(
transfer, 64, 16,
true, (
void *)&tmp_float);
227 #if UAVCAN_ACTUATORS_USE_CURRENT
230 #ifdef UAVCAN1_TELEM_NB
231 for (
uint8_t i = 0; i < UAVCAN1_TELEM_NB; ++i) {
235 #ifdef UAVCAN2_TELEM_NB
236 for (
uint8_t i = 0; i < UAVCAN2_TELEM_NB; ++i) {
243 #ifdef UAVCAN1_TELEM_NB
244 if (iface == &uavcan1) {
249 #ifdef SERVOS_UAVCAN1_NB
250 feedback.
idx = get_servo_idx_UAVCAN1(
esc_idx);
252 #ifdef SERVOS_UAVCAN1CMD_NB
254 feedback.
idx = get_servo_idx_UAVCAN1CMD(
esc_idx);
262 #ifdef UAVCAN2_TELEM_NB
263 if (iface == &uavcan2) {
268 #ifdef SERVOS_UAVCAN2_NB
269 feedback.
idx = get_servo_idx_UAVCAN2(
esc_idx);
271 #ifdef SERVOS_UAVCAN2CMD_NB
273 feedback.
idx = get_servo_idx_UAVCAN2CMD(
esc_idx);
293 #ifdef UAVCAN1_TELEM_NB
294 if (iface == &uavcan1) {
295 telem = uavcan1_telem;
296 max_id = UAVCAN1_TELEM_NB;
299 #ifdef UAVCAN2_TELEM_NB
300 if (iface == &uavcan2) {
301 telem = uavcan2_telem;
302 max_id = UAVCAN2_TELEM_NB;
306 canardDecodeScalar(
transfer, 0, 8,
false, (
void *)&actuator_idx);
308 if (actuator_idx >= max_id || telem == NULL || max_id == 0) {
313 canardDecodeScalar(
transfer, 8, 16,
true, (
void *)&tmp_float);
314 telem[actuator_idx].
position = canardConvertFloat16ToNativeFloat(tmp_float);
316 #ifdef UAVCAN1_TELEM_NB
317 if (iface == &uavcan1) {
322 #ifdef SERVOS_UAVCAN1_NB
323 feedback.
idx = get_servo_idx_UAVCAN1(actuator_idx);
325 #ifdef SERVOS_UAVCAN1CMD_NB
327 feedback.
idx = get_servo_idx_UAVCAN1CMD(actuator_idx);
336 #ifdef UAVCAN2_TELEM_NB
337 if (iface == &uavcan2) {
342 #ifdef SERVOS_UAVCAN2_NB
343 feedback.
idx = get_servo_idx_UAVCAN2(actuator_idx);
345 #ifdef SERVOS_UAVCAN2CMD_NB
347 feedback.
idx = get_servo_idx_UAVCAN2CMD(actuator_idx);
367 #ifdef UAVCAN1_TELEM_NB
368 if (iface == &uavcan1) {
369 telem = uavcan1_telem;
370 max_id = UAVCAN1_TELEM_NB;
373 #ifdef UAVCAN2_TELEM_NB
374 if (iface == &uavcan2) {
375 telem = uavcan2_telem;
376 max_id = UAVCAN2_TELEM_NB;
381 canardDecodeScalar(
transfer, 0, 16,
false, (
void*)&device_id);
383 if (device_id >= max_id || telem == NULL || max_id == 0) {
387 telem[device_id].
set =
true;
388 canardDecodeScalar(
transfer, 16, 16,
false, (
void*)&tmp_float);
389 telem[device_id].
temperature_dev = canardConvertFloat16ToNativeFloat(tmp_float) - 273.15;
412 #if PERIODIC_TELEMETRY
417 #ifdef SERVOS_UAVCAN1CMD_NB
418 for(
uint8_t i = 0; i < SERVOS_UAVCAN1CMD_NB; i++)
421 #ifdef SERVOS_UAVCAN2CMD_NB
422 for(
uint8_t i = 0; i < SERVOS_UAVCAN2CMD_NB; i++)
442 for (
uint8_t i = 0; i < nb; i++) {
443 canardEncodeScalar(buffer,
offset, 14, (
void *)&values[i]);
449 CANARD_TRANSFER_PRIORITY_HIGH, buffer, (
offset + 7) / 8);
462 for (
uint8_t i = 0; i < nb; i++) {
468 canardEncodeScalar(buffer,
offset, 8, (
void*)&i);
472 canardEncodeScalar(buffer,
offset, 8, (
void*)&command_type);
476 uint16_t tmp_float = canardConvertNativeFloatToFloat16((
float)values[i] / (
float)
MAX_PPRZ);
477 canardEncodeScalar(buffer,
offset, 16, (
void*)&tmp_float);
483 CANARD_TRANSFER_PRIORITY_HIGH, buffer, (
offset + 7) / 8);
Main include for ABI (AirBorneInterface).
#define ACT_FEEDBACK_UAVCAN_ID
int16_t actuators_uavcan1_values[SERVOS_UAVCAN1_NB]
Stub file needed per uavcan interface because of generator.
int16_t actuators_uavcan1cmd_values[SERVOS_UAVCAN1CMD_NB]
Stub file needed per uavcan interface because of generator.
int16_t actuators_uavcan2_values[SERVOS_UAVCAN2_NB]
Stub file needed per interface because of generator.
int16_t actuators_uavcan2cmd_values[SERVOS_UAVCAN2CMD_NB]
Stub file needed per uavcan interface because of generator.
#define UAVCAN_EQUIPMENT_ESC_STATUS_ID
static void actuators_uavcan_send_esc(struct transport_tx *trans, struct link_device *dev)
void actuators_uavcan_init(struct uavcan_iface_t *iface)
Initialize an uavcan interface.
static void actuators_uavcan_device_temperature_cb(struct uavcan_iface_t *iface, CanardRxTransfer *transfer)
Whevener an DEVICE_TEMPERATURE message from the EQUIPMENT group is received.
static uavcan_event actuator_status_ev
#define UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_MAX_SIZE
#define UAVCAN_EQUIPMENT_ESC_STATUS_SIGNATURE
void actuators_uavcan_commit(struct uavcan_iface_t *iface, int16_t *values, uint8_t nb)
Commit actuator values to the uavcan interface (EQUIPMENT_ESC_RAWCOMMAND)
#define UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_ID
#define UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_SIGNATURE
static struct actuators_uavcan_telem_t * actuators_uavcan_next_telem(void)
#define UAVCAN_EQUIPMENT_ACTUATOR_ARRAYCOMMAND_SIGNATURE
static void actuators_uavcan_esc_status_cb(struct uavcan_iface_t *iface, CanardRxTransfer *transfer)
Whevener an ESC_STATUS message from the EQUIPMENT group is received.
static uavcan_event device_temperature_ev
static void actuators_uavcan_actuator_status_cb(struct uavcan_iface_t *iface, CanardRxTransfer *transfer)
Whevener an ACTUATOR_STATUS message from the EQUIPMENT group is received.
static bool actuators_uavcan_initialized
#define UAVCAN_EQUIPMENT_DEVICE_TEMPERATURE_SIGNATURE
#define UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_ID
void actuators_uavcan_cmd_commit(struct uavcan_iface_t *iface, int16_t *values, uint8_t nb)
Commit actuator values to the uavcan interface (EQUIPMENT_ACTUATOR_ARRAYCOMMAND)
#define UAVCAN_EQUIPMENT_DEVICE_TEMPERATURE_ID
#define UAVCAN_EQUIPMENT_ACTUATOR_STATUS_SIGNATURE
#define UAVCAN_CMD_UNUSED
static uavcan_event esc_status_ev
#define UAVCAN_EQUIPMENT_ESC_RAWCOMMAND_MAX_SIZE
#define UAVCAN_EQUIPMENT_ACTUATOR_STATUS_ID
Main uavcan event structure for registering/calling callbacks.
static const float offset[]
struct Electrical electrical
Interface for electrical status: supply voltage, current, battery status, etc.
float current
current in A
float vsupply
supply voltage in V
Hardware independent API for actuators (servos, motor controllers).
bool position
Position is set.
struct act_feedback_t::act_feedback_set_t set
Bitset registering what is set as feedback.
uint8_t idx
General index of the actuators (generated in airframe.h)
float position
In radians.
double rand_uniform(void)
uavcan interface structure
static const struct usb_device_descriptor dev
static float get_sys_time_float(void)
Get the time in seconds since startup.
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
void uavcan_broadcast(struct uavcan_iface_t *iface, uint64_t data_type_signature, uint16_t data_type_id, uint8_t priority, const void *payload, uint16_t payload_len)
Broadcast an uavcan message to a specific interface.
void uavcan_bind(uint16_t data_type_id, uint64_t data_type_signature, uavcan_event *ev, uavcan_callback cb)
Bind to a receiving message from uavcan.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
int transfer(const Mat *from, const image_t *to)