@@ -20,6 +20,7 @@ Raptor::Raptor(): ModuleParams(nullptr), ScheduledWorkItem(MODULE_NAME, px4::wq_
2020 last_native_status_set = false ;
2121 policy_frequency_check_counter = 0 ;
2222 flightmode_state = FlightModeState::UNREGISTERED;
23+ can_arm = false ;
2324
2425 _actuator_motors_pub.advertise ();
2526 _tune_control_pub.advertise ();
@@ -352,7 +353,7 @@ void Raptor::observe(rl_tools::inference::applications::l2f::Observation<EXECUTO
352353}
353354
354355
355- void Raptor::updateArmingCheckReply (bool active ){
356+ void Raptor::updateArmingCheckReply (){
356357 if (flightmode_state == FlightModeState::CONFIGURED){
357358 if (_arming_check_request_sub.updated ()) {
358359 arming_check_request_s arming_check_request;
@@ -363,7 +364,7 @@ void Raptor::updateArmingCheckReply(bool active){
363364 arming_check_reply.registration_id = ext_component_arming_check_id;
364365 arming_check_reply.health_component_index = arming_check_reply.HEALTH_COMPONENT_INDEX_NONE ;
365366 arming_check_reply.num_events = 0 ;
366- arming_check_reply.can_arm_and_run = active ;
367+ arming_check_reply.can_arm_and_run = can_arm ;
367368 arming_check_reply.mode_req_angular_velocity = true ;
368369 arming_check_reply.mode_req_local_position = true ;
369370 arming_check_reply.mode_req_attitude = true ;
@@ -428,7 +429,7 @@ void Raptor::Run(){
428429 perf_begin (_loop_perf);
429430 hrt_abstime current_time = hrt_absolute_time ();
430431
431- raptor_status_s status;
432+ raptor_status_s status{} ;
432433 status.timestamp = current_time;
433434 status.timestamp_sample = current_time;
434435 status.exit_reason = raptor_status_s::EXIT_REASON_NONE;
@@ -440,6 +441,7 @@ void Raptor::Run(){
440441 status.subscription_update_angular_velocity = _vehicle_angular_velocity_sub.update (&_vehicle_angular_velocity);
441442 if (status.subscription_update_angular_velocity ){
442443 timestamp_last_angular_velocity = current_time;
444+ status.timestamp_last_vehicle_angular_velocity = current_time;
443445 timestamp_last_angular_velocity_set = true ;
444446 angular_velocity_update = true ;
445447 }
@@ -448,17 +450,20 @@ void Raptor::Run(){
448450 status.subscription_update_local_position = _vehicle_local_position_sub.update (&_vehicle_local_position);
449451 if (status.subscription_update_local_position ){
450452 timestamp_last_local_position = current_time;
453+ status.timestamp_last_vehicle_local_position = current_time;
451454 timestamp_last_local_position_set = true ;
452455 }
453456
454457 status.subscription_update_attitude = _vehicle_attitude_sub.update (&_vehicle_attitude);
455458 if (status.subscription_update_attitude ){
456459 timestamp_last_attitude = current_time;
460+ status.timestamp_last_vehicle_attitude = current_time;
457461 timestamp_last_attitude_set = true ;
458462 }
459463
460464 trajectory_setpoint_s temp_trajectory_setpoint;
461- if (_trajectory_setpoint_sub.update (&temp_trajectory_setpoint)) {
465+ status.subscription_update_trajectory_setpoint = _trajectory_setpoint_sub.update (&temp_trajectory_setpoint);
466+ if (status.subscription_update_trajectory_setpoint ){
462467 if (
463468 PX4_ISFINITE (temp_trajectory_setpoint.position [0 ]) &&
464469 PX4_ISFINITE (temp_trajectory_setpoint.position [1 ]) &&
@@ -470,6 +475,7 @@ void Raptor::Run(){
470475 PX4_ISFINITE (temp_trajectory_setpoint.yawspeed )
471476 ){
472477 timestamp_last_trajectory_setpoint_set = true ;
478+ status.timestamp_last_trajectory_setpoint = current_time;
473479 timestamp_last_trajectory_setpoint = temp_trajectory_setpoint.timestamp ;
474480 _trajectory_setpoint = temp_trajectory_setpoint;
475481 }
@@ -479,16 +485,22 @@ void Raptor::Run(){
479485 if (!angular_velocity_update){
480486 status.exit_reason = raptor_status_s::EXIT_REASON_NO_ANGULAR_VELOCITY_UPDATE;
481487 if constexpr (PUBLISH_NON_COMPLETE_STATUS){
482- _raptor_status_pub.publish (status);
488+ // _raptor_status_pub.publish(status);
483489 }
490+ updateArmingCheckReply ();
484491 return ;
485492 }
486493
487494 if (!timestamp_last_angular_velocity_set || !timestamp_last_local_position_set || !timestamp_last_attitude_set){
488495 status.exit_reason = raptor_status_s::EXIT_REASON_NOT_ALL_OBSERVATIONS_SET;
496+ status.vehicle_angular_velocity_stale = !timestamp_last_angular_velocity_set;
497+ status.vehicle_local_position_stale = !timestamp_last_local_position_set;
498+ status.vehicle_attitude_stale = !timestamp_last_attitude_set;
489499 if constexpr (PUBLISH_NON_COMPLETE_STATUS){
490500 _raptor_status_pub.publish (status);
491501 }
502+ can_arm = false ;
503+ updateArmingCheckReply ();
492504 return ;
493505 }
494506
@@ -501,7 +513,8 @@ void Raptor::Run(){
501513 PX4_ERR (" angular velocity timeout" );
502514 timeout_message_sent = true ;
503515 }
504- updateArmingCheckReply (false );
516+ can_arm = false ;
517+ updateArmingCheckReply ();
505518 return ;
506519 }
507520 if ((current_time - timestamp_last_local_position) > OBSERVATION_TIMEOUT_LOCAL_POSITION){
@@ -513,7 +526,8 @@ void Raptor::Run(){
513526 PX4_ERR (" local position timeout" );
514527 timeout_message_sent = true ;
515528 }
516- updateArmingCheckReply (false );
529+ can_arm = false ;
530+ updateArmingCheckReply ();
517531 return ;
518532 }
519533 else {
@@ -535,11 +549,16 @@ void Raptor::Run(){
535549 PX4_ERR (" attitude timeout" );
536550 timeout_message_sent = true ;
537551 }
538- updateArmingCheckReply (false );
552+ can_arm = false ;
553+ updateArmingCheckReply ();
539554 return ;
540555 }
541556 timeout_message_sent = false ;
542557
558+ // is ready to control at this point
559+ can_arm = true ;
560+ updateArmingCheckReply ();
561+
543562 if (!timestamp_last_trajectory_setpoint_set || (current_time - timestamp_last_trajectory_setpoint) > TRAJECTORY_SETPOINT_TIMEOUT){
544563 status.trajectory_setpoint_stale = true ;
545564 if (!previous_trajectory_setpoint_stale){
@@ -564,6 +583,9 @@ void Raptor::Run(){
564583 }
565584
566585
586+
587+
588+
567589 rl_tools::inference::applications::l2f::Observation<EXECUTOR_SPEC> observation;
568590 rl_tools::inference::applications::l2f::Action<EXECUTOR_SPEC> action;
569591 observe (observation);
@@ -573,7 +595,7 @@ void Raptor::Run(){
573595 if (executor_status.source != decltype (executor_status.source )::CONTROL){
574596 status.exit_reason = raptor_status_s::EXIT_REASON_EXECUTOR_STATUS_SOURCE_NOT_CONTROL;
575597 if constexpr (PUBLISH_NON_COMPLETE_STATUS){
576- _raptor_status_pub.publish (status);
598+ // _raptor_status_pub.publish(status);
577599 }
578600 return ;
579601 }
@@ -592,9 +614,6 @@ void Raptor::Run(){
592614
593615 // no return after this point!
594616
595- updateArmingCheckReply (true );
596-
597-
598617 raptor_input_s input_msg;
599618 input_msg.active = status.active ;
600619 static_assert (raptor_input_s::ACTION_DIM == EXECUTOR_CONFIG::OUTPUT_DIM);
0 commit comments