/** * Return a string describing Research progress. * @return a string describing Research progress. */ std::string ResearchProject::getResearchProgress() const { float progress = (float)getSpent() / getRules()->getCost(); if (getAssigned() == 0) { return "STR_NONE"; } else if (progress < PROGRESS_LIMIT_UNKNOWN) { return "STR_UNKNOWN"; } else { float rating = (float)getAssigned(); rating /= getRules()->getCost(); if (rating < PROGRESS_LIMIT_POOR) { return "STR_POOR"; } else if (rating < PROGRESS_LIMIT_AVERAGE) { return "STR_AVERAGE"; } else if (rating < PROGRESS_LIMIT_GOOD) { return "STR_GOOD"; } return "STR_EXCELLENT"; } }
/** * Saves the research project to a YAML file. * @return YAML node. */ YAML::Node ResearchProject::save() const { YAML::Node node; node["project"] = getRules()->getName(); node["assigned"] = getAssigned(); node["spent"] = getSpent(); node["cost"] = getCost(); return node; }
/** * Loads the research project from a YAML file. * @param node YAML node. */ void ResearchProject::load(const YAML::Node& node) { setAssigned(node["assigned"].as<int>(getAssigned())); setSpent(node["spent"].as<int>(getSpent())); setCost(node["cost"].as<int>(getCost())); }
int main(int argc, char* argv[]) { // Initialize shared memory if (ipc.init(false)) exit(1); // Initialize nominal beaconContainer parseWaypoints(); // Create camera semaphore/ mutex sem_init(&semCam, 0, 0); if (pthread_mutex_init(&mutexImageData, NULL) != 0) { printf("\n Camera mutex init failed\n"); exit(1); } // Start camera thread pthread_t tid; int err = pthread_create(&tid, NULL, &camThread, NULL); if (err != 0) { printf("\nCan't create camera thread :[%s]", strerror(err)); exit(1); } lastPhotogramMicros = getMicroSec(); // Main loop for(;;photogram++) { TRACE(DEBUG, "\nPHOTOGRAM %d, milliseconds: %ld\n", photogram, getMillisSinceStart()); // Update time variables photogramMicros = getMicroSec(); lastPhotogramSpentTime = getSpent(photogramMicros - lastPhotogramMicros); microsSinceStart += lastPhotogramSpentTime; lastPhotogramMicros = photogramMicros; // Get drone roll, pitch and yaw attitudeT attitude, delayedAttitude; ipc.getAttitude(attitude); attitudeSignal.push(attitude, lastPhotogramSpentTime); delayedAttitude = attitudeSignal.getSignal(); droneRoll = delayedAttitude.roll * 0.01; dronePitch = delayedAttitude.pitch * 0.01; droneYaw = delayedAttitude.yaw * 0.01; // Update estimated servo values rollStatusServo.update(lastPhotogramSpentTime); pitchStatusServo.update(lastPhotogramSpentTime); if (rollStatusServo.inBigStep() || pitchStatusServo.inBigStep()) { sem_wait(&semCam); continue; } // Update estimated camera roll and pitch roll = droneRoll + rollStatusServo.getEstimatedAngle(); pitch = dronePitch + pitchStatusServo.getEstimatedAngle(); // Switch beacon containers to preserve one history record if (beaconContainer == &beaconContainerA) { beaconContainer = &beaconContainerB; oldBeaconContainer = &beaconContainerA; } else { beaconContainer = &beaconContainerA; oldBeaconContainer = &beaconContainerB; } beaconContainer->clean(); // Wait until new frame is received sem_wait(&semCam); // Where the magic happens findBeacons(); groupBeacons(); findWaypoints(); computePosition(); } StopCamera(); printf("Finished.\n"); return 0; }