mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-23 23:27:34 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 96fc4a0673 | |||
| 122643af25 | |||
| 71afdb5680 | |||
| 0253f9798e | |||
| ad42a5b2f9 | |||
| 761810884e | |||
| 2a779663f6 | |||
| 7816fd14b7 | |||
| 64d18f0a64 | |||
| a3cca099a8 | |||
| 01a65bfcf6 |
@@ -49,7 +49,7 @@ uint8 NAVIGATION_STATE_DESCEND = 12 # Descend mode (no position cont
|
||||
uint8 NAVIGATION_STATE_TERMINATION = 13 # Termination mode
|
||||
uint8 NAVIGATION_STATE_OFFBOARD = 14
|
||||
uint8 NAVIGATION_STATE_STAB = 15 # Stabilized mode
|
||||
uint8 NAVIGATION_STATE_FREE1 = 16
|
||||
uint8 NAVIGATION_STATE_CS_PREFLIGHT_CHECK = 16
|
||||
uint8 NAVIGATION_STATE_AUTO_TAKEOFF = 17 # Takeoff
|
||||
uint8 NAVIGATION_STATE_AUTO_LAND = 18 # Land
|
||||
uint8 NAVIGATION_STATE_AUTO_FOLLOW_TARGET = 19 # Auto Follow
|
||||
|
||||
@@ -1572,6 +1572,42 @@ void Commander::handleCommandsFromModeExecutors()
|
||||
}
|
||||
}
|
||||
|
||||
unsigned Commander::handleCommandControlTest(const vehicle_command_s &cmd)
|
||||
{
|
||||
|
||||
// TODO: trigger this some different way using params for dev purposes...?
|
||||
// TODO: decode from command: do we want to test roll/pitch/yaw(/collective tilt), or
|
||||
// individual control surfaces?
|
||||
// TODO define these somewhere else like all the cool kids do
|
||||
static const int TEST_MODE_INDIVIDUAL = 0;
|
||||
static const int TEST_MODE_RPY = 1;
|
||||
|
||||
int test_mode = TEST_MODE_RPY;
|
||||
|
||||
if (test_mode == TEST_MODE_INDIVIDUAL) {
|
||||
// _user_mode_intention.change()
|
||||
// _user_mode_intention.change(vehicle_status_s::NAVIGATION_STATE_SERVO_TEST);
|
||||
PX4_INFO("Not implemented");
|
||||
return vehicle_command_ack_s::VEHICLE_CMD_RESULT_DENIED;
|
||||
|
||||
} else if (test_mode == TEST_MODE_RPY) {
|
||||
|
||||
// this nice pattern stolen from handle_command
|
||||
if (_user_mode_intention.change(vehicle_status_s::NAVIGATION_STATE_AUTO_LOITER)) {
|
||||
return vehicle_command_ack_s::VEHICLE_CMD_RESULT_ACCEPTED;
|
||||
|
||||
} else {
|
||||
printRejectMode(vehicle_status_s::NAVIGATION_STATE_AUTO_LOITER);
|
||||
return vehicle_command_ack_s::VEHICLE_CMD_RESULT_TEMPORARILY_REJECTED;
|
||||
}
|
||||
|
||||
} else {
|
||||
return vehicle_command_ack_s::VEHICLE_CMD_RESULT_UNSUPPORTED;
|
||||
}
|
||||
|
||||
return vehicle_command_ack_s::VEHICLE_CMD_RESULT_ACCEPTED;
|
||||
}
|
||||
|
||||
unsigned Commander::handleCommandActuatorTest(const vehicle_command_s &cmd)
|
||||
{
|
||||
if (isArmed() || (_safety.isButtonAvailable() && !_safety.isSafetyOff())) {
|
||||
@@ -1835,6 +1871,34 @@ void Commander::run()
|
||||
_status_changed = true;
|
||||
}
|
||||
|
||||
if (_param_com_do_cs_check.get()) {
|
||||
|
||||
// directly modify user intention here.
|
||||
// plan is for this to ultimately to be triggered by a mavlink command
|
||||
// through Commander::handle_command
|
||||
|
||||
// this nice pattern stolen from handle_command
|
||||
// if (_user_mode_intention.change(vehicle_status_s::NAVIGATION_STATE_CS_PREFLIGHT_CHECK, ModeChangeSource::ModeExecutor, false)) {
|
||||
_prev_nav_state = _vehicle_status.nav_state;
|
||||
_user_mode_intention.change(vehicle_status_s::NAVIGATION_STATE_CS_PREFLIGHT_CHECK);
|
||||
|
||||
// no error handling like this for now
|
||||
// if (ret) {
|
||||
// return vehicle_command_ack_s::VEHICLE_CMD_RESULT_ACCEPTED;
|
||||
// PX4_INFO("mode intention changed");
|
||||
|
||||
// } else {
|
||||
// printRejectMode(vehicle_status_s::NAVIGATION_STATE_AUTO_LOITER);
|
||||
// return vehicle_command_ack_s::VEHICLE_CMD_RESULT_TEMPORARILY_REJECTED;
|
||||
// PX4_INFO("mode intention not changed");
|
||||
// }
|
||||
|
||||
} else {
|
||||
if (_vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_CS_PREFLIGHT_CHECK) {
|
||||
_user_mode_intention.change(_prev_nav_state);
|
||||
}
|
||||
}
|
||||
|
||||
modeManagementUpdate();
|
||||
|
||||
const hrt_abstime now = hrt_absolute_time();
|
||||
|
||||
@@ -157,6 +157,8 @@ private:
|
||||
|
||||
unsigned handleCommandActuatorTest(const vehicle_command_s &cmd);
|
||||
|
||||
unsigned handleCommandControlTest(const vehicle_command_s &cmd);
|
||||
|
||||
void executeActionRequest(const action_request_s &action_request);
|
||||
|
||||
void printRejectMode(uint8_t nav_state);
|
||||
@@ -284,6 +286,8 @@ private:
|
||||
|
||||
vehicle_land_detected_s _vehicle_land_detected{};
|
||||
|
||||
uint8_t _prev_nav_state;
|
||||
|
||||
// commander publications
|
||||
actuator_armed_s _actuator_armed{};
|
||||
vehicle_control_mode_s _vehicle_control_mode{};
|
||||
@@ -349,6 +353,7 @@ private:
|
||||
(ParamFloat<px4::params::COM_SPOOLUP_TIME>) _param_com_spoolup_time,
|
||||
(ParamInt<px4::params::COM_FLIGHT_UUID>) _param_com_flight_uuid,
|
||||
(ParamInt<px4::params::COM_TAKEOFF_ACT>) _param_com_takeoff_act,
|
||||
(ParamBool<px4::params::COM_DO_CS_CHECK>) _param_com_do_cs_check,
|
||||
(ParamFloat<px4::params::COM_CPU_MAX>) _param_com_cpu_max
|
||||
)
|
||||
};
|
||||
|
||||
@@ -178,6 +178,21 @@ void getVehicleControlMode(uint8_t nav_state, uint8_t vehicle_type,
|
||||
vehicle_control_mode.flag_control_allocation_enabled = true;
|
||||
break;
|
||||
|
||||
// enabling literally all of these makes the allocator run nicely.
|
||||
// enabling only allocator, it will not run.
|
||||
// surely there is like one or two which we really need and the rest can be dropped...
|
||||
case vehicle_status_s::NAVIGATION_STATE_CS_PREFLIGHT_CHECK:
|
||||
vehicle_control_mode.flag_control_auto_enabled = true;
|
||||
vehicle_control_mode.flag_control_position_enabled = true;
|
||||
vehicle_control_mode.flag_control_velocity_enabled = true;
|
||||
vehicle_control_mode.flag_control_altitude_enabled = true;
|
||||
vehicle_control_mode.flag_control_climb_rate_enabled = true;
|
||||
vehicle_control_mode.flag_control_attitude_enabled = true;
|
||||
vehicle_control_mode.flag_control_rates_enabled = true;
|
||||
vehicle_control_mode.flag_control_allocation_enabled = true;
|
||||
break;
|
||||
|
||||
|
||||
// vehicle_status_s::NAVIGATION_STATE_EXTERNALx: handled in ModeManagement
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -1029,3 +1029,6 @@ PARAM_DEFINE_INT32(COM_FLTT_LOW_ACT, 3);
|
||||
*
|
||||
*/
|
||||
PARAM_DEFINE_INT32(COM_MODE_ARM_CHK, 0);
|
||||
|
||||
// temporary, to test control surface preflight check.
|
||||
PARAM_DEFINE_INT32(COM_DO_CS_CHECK, 0);
|
||||
|
||||
@@ -61,6 +61,8 @@ ControlAllocator::ControlAllocator() :
|
||||
_actuator_servos_pub.advertise();
|
||||
_actuator_servos_trim_pub.advertise();
|
||||
|
||||
_tiltrotor_extra_controls_pub.advertise();
|
||||
|
||||
for (int i = 0; i < MAX_NUM_MOTORS; ++i) {
|
||||
char buffer[17];
|
||||
snprintf(buffer, sizeof(buffer), "CA_R%u_SLEW", i);
|
||||
@@ -346,6 +348,8 @@ ControlAllocator::Run()
|
||||
|
||||
_armed = vehicle_status.arming_state == vehicle_status_s::ARMING_STATE_ARMED;
|
||||
|
||||
_preflight_check_running = vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_CS_PREFLIGHT_CHECK;
|
||||
|
||||
ActuatorEffectiveness::FlightPhase flight_phase{ActuatorEffectiveness::FlightPhase::HOVER_FLIGHT};
|
||||
|
||||
// Check if the current flight phase is HOVER or FIXED_WING
|
||||
@@ -437,8 +441,19 @@ ControlAllocator::Run()
|
||||
}
|
||||
}
|
||||
|
||||
if (_preflight_check_running) {
|
||||
preflight_check_overwrite_torque_sp(c);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _num_control_allocation; ++i) {
|
||||
|
||||
ActuatorEffectivenessTiltrotorVTOL *casted = dynamic_cast<ActuatorEffectivenessTiltrotorVTOL *>
|
||||
(_actuator_effectiveness);
|
||||
|
||||
if (casted != nullptr) {
|
||||
casted->_preflight_check_running = _preflight_check_running;
|
||||
}
|
||||
|
||||
_control_allocation[i]->setControlSetpoint(c[i]);
|
||||
|
||||
// Do allocation
|
||||
@@ -473,6 +488,82 @@ ControlAllocator::Run()
|
||||
perf_end(_loop_perf);
|
||||
}
|
||||
|
||||
// void ControlAllocator::test_individual_control_surfaces() {
|
||||
// goal here: modify actuation at the servo level.
|
||||
|
||||
// in here: small state machine cycling through servos (or taking info
|
||||
// from outside about which servo to actuate)
|
||||
// if test running: if enough time passed: go to next thing
|
||||
// if last thing: test = not running
|
||||
|
||||
// elsewhere (probably Run()...)
|
||||
// set test running if right message received
|
||||
// if test running,
|
||||
|
||||
// }
|
||||
|
||||
void ControlAllocator::preflight_check_overwrite_torque_sp(matrix::Vector<float, NUM_AXES> (&c)[ActuatorEffectiveness::MAX_NUM_MATRICES]) {
|
||||
|
||||
// cycle through roll, pitch, yaw, and for each one inject positive and
|
||||
// negative torque setpoints.
|
||||
|
||||
// is this the proper way to do it?
|
||||
// bool tiltrotor = _effectiveness_source_id == EffectivenessSource::TILTROTOR_VTOL;
|
||||
bool tiltrotor = dynamic_cast<ActuatorEffectivenessTiltrotorVTOL*>(_actuator_effectiveness) != nullptr;
|
||||
|
||||
int n_axes = 3;
|
||||
if (tiltrotor) {
|
||||
n_axes = 4;
|
||||
}
|
||||
|
||||
int max_phase = 2 * n_axes;
|
||||
|
||||
hrt_abstime now = hrt_absolute_time();
|
||||
if (now - _last_preflight_check_update >= 500_ms) {
|
||||
_preflight_check_phase++;
|
||||
_preflight_check_phase %= max_phase; // or quit once we did the whole thing once?
|
||||
_last_preflight_check_update = now;
|
||||
}
|
||||
|
||||
int axis = _preflight_check_phase / 2;
|
||||
int negative = _preflight_check_phase % 2;
|
||||
|
||||
float modified_tilt_control = 0.5f;
|
||||
|
||||
if (axis < 3) {
|
||||
c[0](0) = 0.;
|
||||
c[0](1) = 0.;
|
||||
c[0](2) = 0.;
|
||||
c[0](axis) = negative ? -1.f : 1.f;
|
||||
|
||||
if (_num_control_allocation > 1) {
|
||||
c[1](0) = 0.;
|
||||
c[1](1) = 0.;
|
||||
c[1](2) = 0.;
|
||||
c[1](axis) = negative ? -1.f : 1.f;
|
||||
}
|
||||
|
||||
} else {
|
||||
// axis 4 = tiltrotor.
|
||||
// collective tilt normalised control goes from 0 to 1.
|
||||
modified_tilt_control = negative ? 0.f : 1.f;
|
||||
}
|
||||
|
||||
tiltrotor_extra_controls_s tiltrotor_extra_controls;
|
||||
|
||||
if (!_tiltrotor_extra_controls_sub.copy(&tiltrotor_extra_controls)) {
|
||||
// got no message, make up thrust setpoint
|
||||
tiltrotor_extra_controls.collective_thrust_normalized_setpoint = 0.;
|
||||
}
|
||||
|
||||
tiltrotor_extra_controls.collective_tilt_normalized_setpoint = modified_tilt_control;
|
||||
tiltrotor_extra_controls.timestamp = hrt_absolute_time();
|
||||
_tiltrotor_extra_controls_pub.publish(tiltrotor_extra_controls);
|
||||
|
||||
// PX4_INFO("_torque_sp: %f, %f, %f", (double) _torque_sp(0), (double) _torque_sp(1), (double) _torque_sp(2));
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
ControlAllocator::update_effectiveness_matrix_if_needed(EffectivenessUpdateReason reason)
|
||||
{
|
||||
|
||||
@@ -138,6 +138,8 @@ private:
|
||||
|
||||
void publish_actuator_controls();
|
||||
|
||||
void preflight_check_overwrite_torque_sp(matrix::Vector<float, NUM_AXES> (&c)[ActuatorEffectiveness::MAX_NUM_MATRICES]);
|
||||
|
||||
AllocationMethod _allocation_method_id{AllocationMethod::NONE};
|
||||
ControlAllocation *_control_allocation[ActuatorEffectiveness::MAX_NUM_MATRICES] {}; ///< class for control allocation calculations
|
||||
int _num_control_allocation{0};
|
||||
@@ -179,6 +181,7 @@ private:
|
||||
|
||||
uORB::Subscription _vehicle_torque_setpoint1_sub{ORB_ID(vehicle_torque_setpoint), 1}; /**< vehicle torque setpoint subscription (2. instance) */
|
||||
uORB::Subscription _vehicle_thrust_setpoint1_sub{ORB_ID(vehicle_thrust_setpoint), 1}; /**< vehicle thrust setpoint subscription (2. instance) */
|
||||
uORB::Subscription _tiltrotor_extra_controls_sub{ORB_ID(tiltrotor_extra_controls)};
|
||||
|
||||
// Outputs
|
||||
uORB::PublicationMulti<control_allocator_status_s> _control_allocator_status_pub[2] {ORB_ID(control_allocator_status), ORB_ID(control_allocator_status)};
|
||||
@@ -187,6 +190,8 @@ private:
|
||||
uORB::Publication<actuator_servos_s> _actuator_servos_pub{ORB_ID(actuator_servos)};
|
||||
uORB::Publication<actuator_servos_trim_s> _actuator_servos_trim_pub{ORB_ID(actuator_servos_trim)};
|
||||
|
||||
uORB::Publication<tiltrotor_extra_controls_s> _tiltrotor_extra_controls_pub{ORB_ID(tiltrotor_extra_controls)};
|
||||
|
||||
uORB::SubscriptionInterval _parameter_update_sub{ORB_ID(parameter_update), 1_s};
|
||||
|
||||
uORB::Subscription _vehicle_status_sub{ORB_ID(vehicle_status)};
|
||||
@@ -201,6 +206,10 @@ private:
|
||||
// For example, the system might report two motor failures, but only the first one is handled by CA
|
||||
uint16_t _handled_motor_failure_bitmask{0};
|
||||
|
||||
bool _preflight_check_running{false};
|
||||
int _preflight_check_phase{0};
|
||||
hrt_abstime _last_preflight_check_update{0};
|
||||
|
||||
perf_counter_t _loop_perf; /**< loop duration performance counter */
|
||||
|
||||
bool _armed{false};
|
||||
|
||||
+1
-1
@@ -166,7 +166,7 @@ void ActuatorEffectivenessTiltrotorVTOL::updateSetpoint(const matrix::Vector<flo
|
||||
if (_tilts.config(i).tilt_direction == ActuatorEffectivenessTilts::TiltDirection::TowardsFront) {
|
||||
|
||||
// as long as throttle spoolup is not completed, leave the tilts in the disarmed position (in hover)
|
||||
if (throttleSpoolupFinished() || _flight_phase != FlightPhase::HOVER_FLIGHT) {
|
||||
if (throttleSpoolupFinished() || _flight_phase != FlightPhase::HOVER_FLIGHT || _preflight_check_running) {
|
||||
actuator_sp(i + _first_tilt_idx) += control_collective_tilt;
|
||||
|
||||
} else {
|
||||
|
||||
+2
@@ -88,6 +88,8 @@ public:
|
||||
|
||||
void getUnallocatedControl(int matrix_index, control_allocator_status_s &status) override;
|
||||
|
||||
bool _preflight_check_running{false};
|
||||
|
||||
protected:
|
||||
bool _collective_tilt_updated{true};
|
||||
ActuatorEffectivenessRotors _mc_rotors;
|
||||
|
||||
Reference in New Issue
Block a user