VOLATILE : 메시지를 캐싱 X , 실시간
TRANSIENT_LOCAL : 토픽의 최근 메시지를 캐싱
KEEP_LAST : 최근 10개(dep죽th) 메시지만 저장
BEST_EFFORT : QoS 설정 중 신뢰성 정책 , 최대한 빠르고 효율적으로 메시지를 전달하려는 방식
subscripiton, publisher 생성
publisher가 특정 토픽으로 데이터를 보내면 subscription 이 데이터를 받고 콜백 함수를 호출한다
0.1초로 주기로 ARM 관련 콜백 함수 호출 , 0.05초로 command관련 콜백 함수 호출
msg : Bool type 임
ef arm_timer_callback(self):
match self.current_state:
case "IDLE":
if(self.flightCheck and self.arm_message):
self.current_state = "ARMING"
self.get_logger().info("idle case passed")
case "ARMING":
if(not(self.flightCheck)):
self.current_state = "IDLE"
self.get_logger().info("case arming failed: FC failed")
elif(self.arm_state == VehicleStatus.ARMING_STATE_ARMED and self.myCnt > 10):
self.current_state = "TAKEOFF"
self.get_logger().info("case arming passed")
self.arm()
case "TAKEOFF":
if(not(self.flightCheck)):
self.current_state = "IDLE"
self.get_logger().info("case takeoff failed: FC failed")
elif(self.nav_state == VehicleStatus.NAVIGATION_STATE_AUTO_TAKEOFF):
self.current_state = "LOITER"
self.get_logger().info("case takeoff passed")
self.arm()
self.take_off()
case "LOITER":
if(not(self.flightCheck)):
self.current_state = "IDLE"
self.get_logger().info("case loiter failed: FC failed")
elif(self.nav_state == VehicleStatus.NAVIGATION_STATE_AUTO_LOITER):
self.current_state = "OFFBOARD"
self.get_logger().info("case loiter passed")
self.arm()
case "OFFBOARD":
if(not(self.flightCheck) or self.arm_state == VehicleStatus.ARMING_STATE_DISARMED or self.failsafe == True):
self.current_state = "IDLE"
self.get_logger().info("case offboard failed: FC failed")
self.state_offboard()
self.current_state = "DONE"
case "DONE":
if (self.myCnt > 100):
self.destroy_timer(self.arm_timer)
self.get_logger().info("timer destroyed")
if(self.arm_state != VehicleStatus.ARMING_STATE_ARMED):
self.arm_message = False
if(self.last_state != self.current_state):
self.last_state = self.current_state
self.get_logger().info(self.current_state)
self.myCnt += 1
if(self.last_state != self.current_state):
self.last_state = self.current_state
self.get_logger().info(self.current_state)
이전 상태를 현재 상태로 업데이트