diff --git a/extra/third_party/lsts/onboard/YoYoReactor.cc b/extra/third_party/lsts/onboard/YoYoReactor.cc index 786513731..e02c9079c 100644 --- a/extra/third_party/lsts/onboard/YoYoReactor.cc +++ b/extra/third_party/lsts/onboard/YoYoReactor.cc @@ -33,16 +33,19 @@ namespace TREX { utils::Symbol const YoYoReactor::s_yoyo_state_tl("yoyo_state"); YoYoReactor::YoYoReactor(TeleoReactor::xml_arg_type arg) : - LstsReactor(arg), - m_lastRefState(s_refstate_tl, "Failed"), - m_lastControl(s_control_tl, "Failed"), - m_lastReference(s_reference_tl, "Failed"), - m_lastPosition(s_position_tl, "Failed") + LstsReactor(arg), + m_lastRefState(s_refstate_tl, "Failed"), + m_lastControl(s_control_tl, "Failed"), + m_lastReference(s_reference_tl, "Failed"), + m_lastPosition(s_position_tl, "Failed") { + + m_pitch = Angles::radians(parse_attr(15, TeleoReactor::xml_factory::node(arg), + "pitch")); + m_lat = m_lon = m_speed = m_minz = m_maxz = -1; m_time_at_surface = 0; m_cmdz = 0; - state = IDLE; use(s_reference_tl, true); use(s_refstate_tl, false); @@ -95,9 +98,10 @@ namespace TREX { bool YoYoReactor::synchronize() { - bool nearXY = false, nearZ = false, nearBottom = false; + bool nearXY = false, nearZ = false, nearBottom = false, nearEnd = false; + double dist_to_target = 10000; + Variable v; - // int secs_at_surface = 60; //< unused variable if (m_lastPosition.hasAttribute("altitude")) { @@ -119,9 +123,20 @@ namespace TREX { printReference(m_lastSentRef); return true; } - /*else { - std::cerr << "Requested at " << m_lastSentRef.tick << " and started at " << m_lastSeenRef.tick << std::endl; - }*/ + + if (m_lastPosition.hasAttribute("latitude") && m_lastPosition.hasAttribute("longitude") && m_lastPosition.hasAttribute("depth")) + { + Variable lat = m_lastPosition.getAttribute("latitude"); + Variable lon = m_lastPosition.getAttribute("longitude"); + Variable depth = m_lastPosition.getAttribute("depth"); + + double cur_lat = lat.domain().getTypedSingleton(); + double cur_lon = lon.domain().getTypedSingleton(); + double cur_depth = depth.domain().getTypedSingleton(); + + dist_to_target = WGS84::distance(cur_lat, cur_lon, 0, m_lat, m_lon, 0); + nearEnd = dist_to_target < (cur_depth / std::tan(m_pitch)); + } double atZ = -1000; if (m_lastPosition.hasAttribute("z")) @@ -159,10 +174,13 @@ namespace TREX { } } + syslog(log::info) << "nearZ: " << nearZ<< ", atZ: "<< atZ << ", nearXY: " << nearXY << ", nearEnd: " << + nearEnd << ", nearBottom: "<