static void guidance_h_update_reference(void) { /* compute reference even if usage temporarily disabled via guidance_h_use_ref */ #if GUIDANCE_H_USE_REF if (bit_is_set(guidance_h.sp.mask, 5)) { gh_update_ref_from_speed_sp(guidance_h.sp.speed); } else { gh_update_ref_from_pos_sp(guidance_h.sp.pos); } #endif /* either use the reference or simply copy the pos setpoint */ if (guidance_h.use_ref) { /* convert our reference to generic representation */ INT32_VECT2_RSHIFT(guidance_h.ref.pos, gh_ref.pos, (GH_POS_REF_FRAC - INT32_POS_FRAC)); INT32_VECT2_LSHIFT(guidance_h.ref.speed, gh_ref.speed, (INT32_SPEED_FRAC - GH_SPEED_REF_FRAC)); INT32_VECT2_LSHIFT(guidance_h.ref.accel, gh_ref.accel, (INT32_ACCEL_FRAC - GH_ACCEL_REF_FRAC)); } else { VECT2_COPY(guidance_h.ref.pos, guidance_h.sp.pos); INT_VECT2_ZERO(guidance_h.ref.speed); INT_VECT2_ZERO(guidance_h.ref.accel); } #if GUIDANCE_H_USE_SPEED_REF if (guidance_h.mode == GUIDANCE_H_MODE_HOVER) { VECT2_COPY(guidance_h.sp.pos, guidance_h.ref.pos); // for display only } #endif /* update heading setpoint from rate */ if (bit_is_set(guidance_h.sp.mask, 7)) { guidance_h.sp.heading += (guidance_h.sp.heading_rate >> (INT32_ANGLE_FRAC - INT32_RATE_FRAC)) / PERIODIC_FREQUENCY; INT32_ANGLE_NORMALIZE(guidance_h.sp.heading); }
void guidance_h_init(void) { guidance_h.mode = GUIDANCE_H_MODE_KILL; guidance_h.use_ref = GUIDANCE_H_USE_REF; guidance_h.approx_force_by_thrust = GUIDANCE_H_APPROX_FORCE_BY_THRUST; INT_VECT2_ZERO(guidance_h.sp.pos); INT_VECT2_ZERO(guidance_h_trim_att_integrator); INT_EULERS_ZERO(guidance_h.rc_sp); guidance_h.sp.heading = 0; guidance_h.sp.heading_rate = 0; guidance_h.gains.p = GUIDANCE_H_PGAIN; guidance_h.gains.i = GUIDANCE_H_IGAIN; guidance_h.gains.d = GUIDANCE_H_DGAIN; guidance_h.gains.a = GUIDANCE_H_AGAIN; guidance_h.gains.v = GUIDANCE_H_VGAIN; transition_percentage = 0; transition_theta_offset = 0; gh_ref_init(); #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE guidance_h_module_init(); #endif #if PERIODIC_TELEMETRY register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_GUIDANCE_H_INT, send_gh); register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_HOVER_LOOP, send_hover_loop); register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_GUIDANCE_H_REF_INT, send_href); register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_ROTORCRAFT_TUNE_HOVER, send_tune_hover); #endif }
static inline void reset_guidance_reference_from_current_position(void) { VECT2_COPY(guidance_h.ref.pos, *stateGetPositionNed_i()); VECT2_COPY(guidance_h.ref.speed, *stateGetSpeedNed_i()); INT_VECT2_ZERO(guidance_h.ref.accel); gh_set_ref(guidance_h.ref.pos, guidance_h.ref.speed, guidance_h.ref.accel); INT_VECT2_ZERO(guidance_h_trim_att_integrator); }
void gps_sim_hitl_event(void) { if (SysTimeTimer(gps_sim_hitl_timer) > 100000) { SysTimeTimerStart(gps_sim_hitl_timer); gps.last_msg_ticks = sys_time.nb_sec_rem; gps.last_msg_time = sys_time.nb_sec; if (state.ned_initialized_i) { if (!autopilot_in_flight) { struct Int32Vect2 zero_vector; INT_VECT2_ZERO(zero_vector); gh_set_ref(zero_vector, zero_vector, zero_vector); INT_VECT2_ZERO(guidance_h.ref.pos); INT_VECT2_ZERO(guidance_h.ref.speed); INT_VECT2_ZERO(guidance_h.ref.accel); gv_set_ref(0, 0, 0); guidance_v_z_ref = 0; guidance_v_zd_ref = 0; guidance_v_zdd_ref = 0; } struct NedCoor_i ned_c; ned_c.x = guidance_h.ref.pos.x * INT32_POS_OF_CM_DEN / INT32_POS_OF_CM_NUM; ned_c.y = guidance_h.ref.pos.y * INT32_POS_OF_CM_DEN / INT32_POS_OF_CM_NUM; ned_c.z = guidance_v_z_ref * INT32_POS_OF_CM_DEN / INT32_POS_OF_CM_NUM; ecef_of_ned_point_i(&gps.ecef_pos, &state.ned_origin_i, &ned_c); gps.lla_pos.alt = state.ned_origin_i.lla.alt - ned_c.z; gps.hmsl = state.ned_origin_i.hmsl - ned_c.z; ned_c.x = guidance_h.ref.speed.x * INT32_SPEED_OF_CM_S_DEN / INT32_SPEED_OF_CM_S_NUM; ned_c.y = guidance_h.ref.speed.y * INT32_SPEED_OF_CM_S_DEN / INT32_SPEED_OF_CM_S_NUM; ned_c.z = guidance_v_zd_ref * INT32_SPEED_OF_CM_S_DEN / INT32_SPEED_OF_CM_S_NUM; ecef_of_ned_vect_i(&gps.ecef_vel, &state.ned_origin_i, &ned_c); gps.fix = GPS_FIX_3D; gps.last_3dfix_ticks = sys_time.nb_sec_rem; gps.last_3dfix_time = sys_time.nb_sec; gps_available = true; } else { struct Int32Vect2 zero_vector; INT_VECT2_ZERO(zero_vector); gh_set_ref(zero_vector, zero_vector, zero_vector); gv_set_ref(0, 0, 0); } // publish gps data uint32_t now_ts = get_sys_time_usec(); gps.last_msg_ticks = sys_time.nb_sec_rem; gps.last_msg_time = sys_time.nb_sec; if (gps.fix == GPS_FIX_3D) { gps.last_3dfix_ticks = sys_time.nb_sec_rem; gps.last_3dfix_time = sys_time.nb_sec; } AbiSendMsgGPS(GPS_SIM_ID, now_ts, &gps); } }