34 #ifndef ROTWING_QUAD_MIN_RPM
35 #define ROTWING_QUAD_MIN_RPM 400
39 #ifndef ROTWING_PUSH_MIN_RPM
40 #define ROTWING_PUSH_MIN_RPM 300
44 #ifndef ROTWING_RPM_TIMEOUT
45 #define ROTWING_RPM_TIMEOUT 1.0
49 #ifndef ROTWING_QUAD_IDLE_MIN_THRUST
50 #define ROTWING_QUAD_IDLE_MIN_THRUST 100
54 #ifndef ROTWING_QUAD_IDLE_TIMEOUT
55 #define ROTWING_QUAD_IDLE_TIMEOUT 0.4
59 #ifndef ROTWING_FW_SKEW_ANGLE
60 #define ROTWING_FW_SKEW_ANGLE 85.0
64 #ifndef ROTWING_SKEW_BACK_MARGIN
65 #define ROTWING_SKEW_BACK_MARGIN 5.0
69 #ifndef ROTWING_SKEW_REF_MODEL_MAX_DIFF
70 #define ROTWING_SKEW_REF_MODEL_MAX_DIFF 5.f
74 #ifndef ROTWING_MIN_AIRSPEED_SLOPE_START_ANGLE
75 #define ROTWING_MIN_AIRSPEED_SLOPE_START_ANGLE 30.0
79 #ifndef ROTWING_FW_STALL_TIMEOUT
80 #define ROTWING_FW_STALL_TIMEOUT 0.5
84 #ifndef SERVO_BMOTOR_PUSH_IDX
85 #define SERVO_BMOTOR_PUSH_IDX SERVO_MOTOR_PUSH_IDX
89 #ifndef SERVO_BROTATION_MECH_IDX
90 #define SERVO_BROTATION_MECH_IDX SERVO_ROTATION_MECH_IDX
94 #ifndef ROTWING_STATE_ACT_FEEDBACK_ID
95 #define ROTWING_STATE_ACT_FEEDBACK_ID ABI_BROADCAST
100 #if PERIODIC_TELEMETRY
117 pprz_msg_send_ROTATING_WING_STATE(trans,
dev, AC_ID,
142 for (
int i = 0; i < 5; i++) {
153 #if PERIODIC_TELEMETRY
163 static float last_idle_time = 0;
179 static float last_stall_time = 0;
183 Bound(meas_skew_angle, 0, 90);
186 last_stall_time = current_time;
221 float skew_max_airspeed = ROTWING_QUAD_MAX_AIRSPEED + (ROTWING_FW_MAX_AIRSPEED - ROTWING_QUAD_MAX_AIRSPEED) * meas_skew_angle /
ROTWING_FW_SKEW_ANGLE;
223 Bound(skew_max_airspeed, ROTWING_QUAD_MAX_AIRSPEED, ROTWING_FW_MAX_AIRSPEED);
227 skew_max_airspeed = ROTWING_FW_MAX_AIRSPEED;
249 if (meas_airspeed < ROTWING_SKEW_DOWN_AIRSPEED) {
251 }
else if (meas_airspeed < ROTWING_SKEW_UP_AIRSPEED) {
253 }
else if (meas_airspeed < ROTWING_QUAD_MAX_AIRSPEED) {
293 nav_max_deceleration_sp = ROTWING_FW_MAX_DECELERATION * meas_skew_angle / 90.f + ROTWING_QUAD_MAX_DECELERATION * (90.f - meas_skew_angle) / 90.f;
301 static float rotwing_state_skew_p_cmd = -
MAX_PPRZ;
302 static float rotwing_state_skew_d_cmd = 0;
304 float speed_sp = ROTWING_SKEW_REF_MODEL_P_GAIN * (servo_pprz_cmd - rotwing_state_skew_p_cmd);
305 BoundAbs(
speed_sp, ROTWING_SKEW_REF_MODEL_MAX_SPEED);
306 rotwing_state_skew_d_cmd += ROTWING_SKEW_REF_MODEL_D_GAIN * (
speed_sp - rotwing_state_skew_d_cmd);
307 rotwing_state_skew_p_cmd += rotwing_state_skew_d_cmd;
308 BoundAbs(rotwing_state_skew_p_cmd,
MAX_PPRZ);
311 #if (ROTWING_SKEW_REF_MODEL || USE_NPS)
316 #ifdef COMMAND_ROT_MECH
323 #ifdef COMMAND_ROT_MECH
330 feedback.
idx = SERVO_ROTATION_MECH_IDX;
345 for(
uint8_t i = 0; i < 5; i++) {
369 for (
int i = 0; i < num_act_message; i++) {
370 int idx = feedback_msg[i].idx;
375 float skew_angle_rad = 0.5 * M_PI - feedback_msg[i].position;
381 if (feedback_msg[i].
set.
rpm) {
382 if ((
idx == SERVO_MOTOR_FRONT_IDX) || (
idx == SERVO_BMOTOR_FRONT_IDX)) {
385 }
else if ((
idx == SERVO_MOTOR_RIGHT_IDX) || (
idx == SERVO_BMOTOR_RIGHT_IDX)) {
388 }
else if ((
idx == SERVO_MOTOR_BACK_IDX) || (
idx == SERVO_BMOTOR_BACK_IDX)) {
391 }
else if ((
idx == SERVO_MOTOR_LEFT_IDX) || (
idx == SERVO_BMOTOR_LEFT_IDX)) {
433 return (!skew_timeout && skew_angle_match);
457 static struct FloatVect3 x_axis = {.
x = 1, .y = 0, .z = 0};
458 static struct FloatVect3 z_axis = {.
x = 0, .y = 0, .z = 1};
468 float body_to_wp_angle_rad = atan2f(
y,
x);
470 if (body_to_wp_angle_rad >= 0.f) {
484 static struct FloatVect3 x_axis = {.
x = 1, .y = 0, .z = 0};
490 target_enu.
x = 100.f * x_att_NED.
y + target_enu.
x;
491 target_enu.
y = 100.f * x_att_NED.
x + target_enu.
y;
496 RunOnceEvery(100 / 2, {
Main include for ABI (AirBorneInterface).
Event structure to store callbacks in a linked list.
#define ACT_FEEDBACK_BOARD_ID
pprz_t commands[COMMANDS_NB]
Hardware independent code for commands handling.
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
void float_rmat_transp_vmult(struct FloatVect3 *vb, struct FloatRMat *m_b2a, struct FloatVect3 *va)
rotate 3D vector by transposed rotation matrix.
#define VECT3_CROSS_PRODUCT(_vo, _v1, _v2)
#define VECT3_DIFF(_c, _a, _b)
#define VECT3_DOT_PRODUCT(_v1, _v2)
static struct FloatRMat * stateGetNedToBodyRMat_f(void)
Get vehicle body attitude rotation matrix (float).
static struct NedCoor_f * stateGetPositionNed_f(void)
Get position in local NED coordinates (float).
static float stateGetAirspeed_f(void)
Get airspeed (float).
struct FloatVect3 speed_sp
void guidance_set_min_max_airspeed(float min_airspeed, float max_airspeed)
float gi_unbounded_airspeed_sp
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.
void waypoint_set_enu(uint8_t wp_id, struct EnuCoor_f *enu)
Set local ENU waypoint coordinates.
float nav_max_deceleration_sp
vector in East North Up coordinates Units: meters
Rotorcraft specific autopilot interface and initialization.
struct HorizontalGuidance guidance_h
#define GUIDANCE_H_MODE_NONE
bool rotwing_state_pusher_motor_running(void)
static void rotwing_state_feedback_cb(uint8_t sender_id, struct act_feedback_t *feedback_msg, uint8_t num_act)
#define ROTWING_RPM_TIMEOUT
#define ROTWING_SKEW_REF_MODEL_MAX_DIFF
bool rotwing_state_hover_motors_running(void)
#define ROTWING_FW_STALL_TIMEOUT
#define ROTWING_FW_SKEW_ANGLE
#define ROTWING_MIN_AIRSPEED_SLOPE_START_ANGLE
void rotwing_state_init(void)
#define ROTWING_PUSH_MIN_RPM
bool rotwing_state_hover_motors_idling(void)
Check if hover motors are idling (COMMAND_THRUST < ROTWING_QUAD_IDLE_MIN_THRUST) for ROTWING_QUAD_IDL...
#define ROTWING_SKEW_BACK_MARGIN
#define SERVO_BMOTOR_PUSH_IDX
bool rotwing_state_skew_angle_valid(void)
#define ROTWING_QUAD_IDLE_MIN_THRUST
#define SERVO_BROTATION_MECH_IDX
#define ROTWING_QUAD_MIN_RPM
static void send_rotating_wing_state(struct transport_tx *trans, struct link_device *dev)
void rotwing_state_set_transition_wp(uint8_t wp_id)
#define ROTWING_STATE_ACT_FEEDBACK_ID
ABI binding feedback data.
abi_event rotwing_state_feedback_ev
#define ROTWING_QUAD_IDLE_TIMEOUT
bool rotwing_state_choose_circle_direction(uint8_t wp_id)
struct rotwing_state_t rotwing_state
void rotwing_state_periodic(void)
void rotwing_state_update_WP_height(uint8_t wp_id, float height)
void rotwing_state_set(enum rotwing_states_t state)
enum rotwing_states_t state
float meas_skew_angle_time
bool hover_motors_enabled
float ref_model_skew_angle_deg
float meas_skew_angle_deg
#define ROTWING_SKEW_ANGLE_STEP
@ ROTWING_STATE_REQUEST_HOVER
@ ROTWING_STATE_FORCE_HOVER
@ ROTWING_STATE_REQUEST_FW
enum rotwing_states_t nav_state
struct Stabilization stabilization
#define STABILIZATION_MODE_ATTITUDE
uint8_t att_submode
current attitude sub-mode
#define STABILIZATION_ATT_SUBMODE_FORWARD
int32_t cmd[COMMANDS_NB]
output command vector, range from [-MAX_PPRZ:MAX_PPRZ] (store for messages)
#define STABILIZATION_MODE_NONE
Stabilization modes.
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.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.