23 #include "goby/common/logger.h" 36 frontseat_providing_data_ =
true;
43 TIMESTAMP_OF_COMMAND = 3,
44 BEHAVIOR_INSERT_ID = 4,
53 REQUEST_UNSUCCESSFULLY_PROCESSED = 1,
54 REQUEST_SUCCESSFULLY_PROCESSED = 2,
58 AckStatus status =
static_cast<AckStatus
>(nmea.as<
int>(ACK_STATUS));
60 std::string acked_sentence = nmea.at(COMMAND_NAME);
65 glog.is(DEBUG1) &&
glog << warn <<
"Huxley reports that we sent an invalid " 66 << acked_sentence <<
" request." << std::endl;
68 case REQUEST_UNSUCCESSFULLY_PROCESSED:
70 <<
"Huxley reports that it unsuccessfully processed our " 71 << acked_sentence <<
" request: " 72 <<
"\"" << nmea.at(DESCRIPTION) <<
"\"" << std::endl;
74 case REQUEST_SUCCESSFULLY_PROCESSED:
break;
76 glog.is(DEBUG1) &&
glog <<
"Huxley reports that our " << acked_sentence
77 <<
" request is pending." << std::endl;
79 pending_.push_back(out_.front().message());
83 boost::to_upper(acked_sentence);
85 if (!out_.empty() && boost::iequals(out_.front().sentence_id(), acked_sentence))
89 else if (!pending_.empty() && boost::iequals(pending_.front().sentence_id(), acked_sentence))
95 glog.is(DEBUG1) &&
glog << warn <<
"Received NMEA Ack for message that was the front " 96 <<
"of neither the outgoing or pending queue. Clearing our queues " 97 "and attempting to carry on ..." 105 if (status != REQUEST_PENDING)
107 gpb::BluefinExtraCommands::BluefinCommand type = gpb::BluefinExtraCommands::UNKNOWN_COMMAND;
108 switch (sentence_id_map_.left.at(acked_sentence))
110 case RMB: type = gpb::BluefinExtraCommands::DESIRED_COURSE;
break;
111 case BOY: type = gpb::BluefinExtraCommands::BUOYANCY_ADJUST;
break;
112 case TRM: type = gpb::BluefinExtraCommands::TRIM_ADJUST;
break;
113 case SIL: type = gpb::BluefinExtraCommands::SILENT_MODE;
break;
114 case RCB: type = gpb::BluefinExtraCommands::CANCEL_CURRENT_BEHAVIOR;
break;
118 if (outstanding_requests_.count(type))
121 response.set_request_successful(status == REQUEST_SUCCESSFULLY_PROCESSED);
122 response.set_request_id(outstanding_requests_[type].request_id());
123 if (!response.request_successful())
125 response.set_error_code(status);
126 response.set_error_string(nmea.at(DESCRIPTION));
128 outstanding_requests_.erase(type);
129 signal_command_response(response);
132 waiting_for_huxley_ =
false;
139 if (bf_config_.accepting_commands_hook() == BluefinFrontSeatConfig::BFMSC_TRIGGER)
140 frontseat_state_ = gpb::FRONTSEAT_ACCEPTING_COMMANDS;
145 frontseat_providing_data_ =
true;
155 QUALITY_OF_POSITION = 6,
161 COMPUTED_TIMESTAMP = 12
167 goby::util::as<double>(goby::common::nmea_time2ptime(nmea.at(COMPUTED_TIMESTAMP))));
169 const std::string& lat_string = nmea.at(LATITUDE);
170 if (lat_string.length() > 2)
172 double lat_deg = goby::util::as<double>(lat_string.substr(0, 2));
173 double lat_min = goby::util::as<double>(lat_string.substr(2, lat_string.size()));
174 double lat = lat_deg + lat_min / 60;
175 status_.mutable_global_fix()->set_lat((nmea.at(LAT_HEMISPHERE) ==
"S") ? -lat : lat);
179 status_.mutable_global_fix()->set_lat(std::numeric_limits<double>::quiet_NaN());
182 const std::string& lon_string = nmea.at(LONGITUDE);
183 if (lon_string.length() > 2)
185 double lon_deg = goby::util::as<double>(lon_string.substr(0, 3));
186 double lon_min = goby::util::as<double>(lon_string.substr(3, nmea.at(4).size()));
187 double lon = lon_deg + lon_min / 60;
188 status_.mutable_global_fix()->set_lon((nmea.at(LON_HEMISPHERE) ==
"W") ? -lon : lon);
192 status_.mutable_global_fix()->set_lon(std::numeric_limits<double>::quiet_NaN());
195 if (nmea.as<
int>(QUALITY_OF_POSITION) == 1)
197 status_.mutable_global_fix()->set_lat_source(goby::moos::protobuf::GPS);
198 status_.mutable_global_fix()->set_lon_source(goby::moos::protobuf::GPS);
201 status_.mutable_global_fix()->set_altitude(nmea.as<
double>(ALTITUDE));
202 status_.mutable_global_fix()->set_depth(nmea.as<
double>(DEPTH));
203 status_.mutable_pose()->set_heading(nmea.as<
double>(HEADING));
204 status_.mutable_pose()->set_roll(nmea.as<
double>(ROLL));
205 status_.mutable_pose()->set_pitch(nmea.as<
double>(PITCH));
222 goby::util::as<double>(goby::common::nmea_time2ptime(nmea.at(TIMESTAMP))) - status_.time();
223 double east_speed = nmea.as<
double>(EAST_VELOCITY);
224 double north_speed = nmea.as<
double>(NORTH_VELOCITY);
226 status_.mutable_pose()->set_pitch_rate(nmea.as<
double>(PITCH_RATE));
227 status_.mutable_pose()->set_roll_rate(nmea.as<
double>(ROLL_RATE));
228 status_.mutable_pose()->set_heading_rate(nmea.as<
double>(YAW_RATE));
229 status_.set_speed(std::sqrt(north_speed * north_speed + east_speed * east_speed));
231 status_.mutable_pose()->set_roll_rate_time_lag(dt);
232 status_.mutable_pose()->set_pitch_rate_time_lag(dt);
233 status_.mutable_pose()->set_heading_rate_time_lag(dt);
234 status_.set_speed_time_lag(dt);
237 compute_missing(&status_);
240 data.mutable_node_status()->CopyFrom(status_);
241 signal_data_from_frontseat(data);
258 glog.is(WARN) &&
glog <<
"Bluefin sent us the SHT message: they are shutting down!" 269 CURRENT_DIVE_FILE = 2,
270 DEPRECATED_BEHAVIOR_NUMBER = 3,
271 PAYLOAD_BEHAVIOR_IDENTIFIER = 4,
275 std::string behavior_type = nmea.at(BEHAVIOR_TYPE);
276 glog.is(DEBUG1) &&
glog <<
"Bluefin began frontseat mission: " << behavior_type << std::endl;
287 BUOYANCY_ESTIMATE_NEWTONS = 5
292 data.MutableExtension(gpb::bluefin_data)->mutable_buoyancy_status();
294 int status = nmea.as<
int>(STATUS);
295 if (gpb::BuoyancyStatus::Status_IsValid(status))
296 buoy_status->set_status(static_cast<gpb::BuoyancyStatus::Status>(status));
298 int error = nmea.as<
int>(ERROR_CODE);
299 if (gpb::BuoyancyStatus::Error_IsValid(error))
300 buoy_status->set_error(static_cast<gpb::BuoyancyStatus::Error>(error));
301 buoy_status->set_debug_string(nmea.at(DEBUG_STRING));
302 buoy_status->set_buoyancy_newtons(nmea.as<
double>(BUOYANCY_ESTIMATE_NEWTONS));
303 signal_data_from_frontseat(data);
319 gpb::TrimStatus* trim_status = data.MutableExtension(gpb::bluefin_data)->mutable_trim_status();
321 int status = nmea.as<
int>(STATUS);
322 int error = nmea.as<
int>(ERROR_CODE);
324 if (gpb::TrimStatus::Status_IsValid(status))
325 trim_status->set_status(static_cast<gpb::TrimStatus::Status>(status));
326 if (gpb::TrimStatus::Error_IsValid(error))
327 trim_status->set_error(static_cast<gpb::TrimStatus::Error>(error));
328 trim_status->set_debug_string(nmea.at(DEBUG_STRING));
329 trim_status->set_pitch_trim_degrees(nmea.as<
double>(PITCH_DEGREES));
330 trim_status->set_roll_trim_degrees(nmea.as<
double>(ROLL_DEGREES));
332 signal_data_from_frontseat(data);
340 CURRENT_DIVE_FILE = 2,
341 DEPRECATED_BEHAVIOR_NUMBER = 3,
342 PAYLOAD_BEHAVIOR_IDENTIFIER = 4,
346 std::string behavior_type = nmea.at(BEHAVIOR_TYPE);
348 glog.is(DEBUG1) &&
glog <<
"Bluefin ended frontseat mission: " << behavior_type << std::endl;
364 std::string running = nmea.at(3);
365 if (running.find(
"Running") != std::string::npos)
367 switch (bf_config_.accepting_commands_hook())
369 case BluefinFrontSeatConfig::BFMIS_RUNNING_TRIGGER:
370 frontseat_state_ = gpb::FRONTSEAT_ACCEPTING_COMMANDS;
373 case BluefinFrontSeatConfig::BFCTL_TRIGGER:
374 case BluefinFrontSeatConfig::BFMSC_TRIGGER:
375 if (frontseat_state_ != gpb::FRONTSEAT_ACCEPTING_COMMANDS)
376 frontseat_state_ = gpb::FRONTSEAT_IN_CONTROL;
384 frontseat_state_ = gpb::FRONTSEAT_IDLE;
403 ctd_sample->set_conductivity(nmea.as<
double>(CONDUCTIVITY) / 1e4);
406 ctd_sample->set_temperature(nmea.as<
double>(TEMPERATURE));
409 ctd_sample->set_pressure(nmea.as<
double>(PRESSURE) * 1e3);
410 compute_missing(ctd_sample);
411 signal_data_from_frontseat(data);
416 if (bf_config_.accepting_commands_hook() == BluefinFrontSeatConfig::BFCTL_TRIGGER)
424 bool control = nmea.as<
bool>(CONTROL);
426 frontseat_state_ = gpb::FRONTSEAT_ACCEPTING_COMMANDS;
427 else if (frontseat_state_ == gpb::FRONTSEAT_ACCEPTING_COMMANDS)
428 frontseat_state_ = gpb::FRONTSEAT_IN_CONTROL;
Contains functions for adding color to Terminal window streams.
double goby_time< double >()
Returns current UTC time as seconds and fractional seconds since 1970-01-01 00:00:00.
ReturnType goby_time()
Returns current UTC time as a boost::posix_time::ptime.
common::FlexOstream glog
Access the Goby logger through this object.