-
Notifications
You must be signed in to change notification settings - Fork 0
New Thread for Picture Taking #364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
22be1bb
c0ca7c9
0b05542
1f84613
b248aed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,11 @@ | |
| #include "utilities/locks.hpp" | ||
| #include "utilities/logging.hpp" | ||
| #include "utilities/obc_config.hpp" | ||
| #include "pathing/environment.hpp" | ||
| #include "utilities/common.hpp" | ||
| #include "ticks/ids.hpp" | ||
|
|
||
| using namespace std::chrono_literals; | ||
|
|
||
| MissionState::MissionState(OBCConfig config) : config(config) {} | ||
|
|
||
|
|
@@ -94,6 +99,59 @@ void MissionState::setAirdropPath(const MissionPath& airdrop_path) { | |
| this->airdrop_path = airdrop_path; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| void MissionState::zoneHandler(const std::chrono::milliseconds& interval, | ||
| std::shared_ptr<MavlinkClient> mavlinkClient){ | ||
| //TODO: find a way to handle stopping the while loop when stopThread hits | ||
|
Vidyuth2 marked this conversation as resolved.
Outdated
|
||
| std::chrono::milliseconds last_photo_time = getUnixTime_ms(); | ||
| while(this->cameraThreadActive){ | ||
| auto [lat_deg, lng_deg] =this->getMav()->latlng_deg(); | ||
| double altitude_agl_m = this->getMav()->altitude_agl_m(); | ||
| GPSCoord current_pos = makeGPSCoord(lat_deg, lng_deg, altitude_agl_m); | ||
| // Get the CartesianConverter (which is already initialized from mission boundaries) | ||
|
Vidyuth2 marked this conversation as resolved.
Outdated
|
||
| auto converter = this->getCartesianConverter(); | ||
| if (converter) { | ||
| // Convert GPS to local XYZ coords | ||
| XYZCoord current_xyz = converter->toXYZ(current_pos); | ||
| // Get the airdrop boundary polygon | ||
| Polygon airdrop_boundary = this->mission_params.getAirdropBoundary(); | ||
| // Check if we're inside the airdrop zone | ||
| bool in_zone = Environment::isPointInPolygon(airdrop_boundary, current_xyz); | ||
| if(in_zone){ | ||
| auto now = getUnixTime_ms(); | ||
| if ((now - last_photo_time) >= 300ms) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this magic number should be a config option. |
||
| auto photo = this->getCamera()->takePicture(100ms, this->getMav()); | ||
| if (this->config.camera.save_images_to_file) { | ||
| photo->saveToFile(this->config.camera.save_dir); | ||
| } | ||
|
|
||
| if (photo.has_value()&&((this->getTickID()==TickID::FlySearch)|| | ||
| (this->getTickID()==TickID::CVLoiter))) { | ||
| // Update the last photo time | ||
| // Run the pipeline on the photo | ||
| this->getCV()->runPipeline(photo.value()); | ||
| } | ||
| last_photo_time = getUnixTime_ms(); | ||
| } | ||
| } | ||
| } | ||
| std::this_thread::sleep_for(interval); | ||
| } | ||
| } | ||
| void MissionState::initThread(const std::chrono::milliseconds& interval, | ||
| std::shared_ptr<MavlinkClient> mavlinkClient){ | ||
| this->cameraThreadActive=true; | ||
| this->captureThread = std::thread([this, interval, mavlinkClient]() { | ||
| this->zoneHandler(interval, mavlinkClient); | ||
| }); | ||
|
|
||
| } | ||
| void MissionState::stopThread(){ | ||
| this->captureThread.join(); | ||
| this->cameraThreadActive = false; | ||
| } | ||
|
|
||
| MissionPath MissionState::getAirdropPath() { | ||
| Lock lock(this->airdrop_path_mut); | ||
| return this->airdrop_path; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ void FlySearchTick::init() { | |
| LOG_F(INFO, "Total Waypoint #: %zu", this->state->getMav()->totalWaypoints()); | ||
| } | ||
|
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete extra line |
||
| Tick* FlySearchTick::tick() { | ||
| if (!this->mission_started) { | ||
| this->mission_started = this->state->getMav()->startMission(); | ||
|
|
@@ -56,32 +57,50 @@ Tick* FlySearchTick::tick() { | |
| // so we can just return a CVLoiterTick | ||
| return new CVLoiterTick(this->state); | ||
| } | ||
| auto [lat_deg, lng_deg] = state->getMav()->latlng_deg(); | ||
| double altitude_agl_m = state->getMav()->altitude_agl_m(); | ||
| GPSCoord current_pos = makeGPSCoord(lat_deg, lng_deg, altitude_agl_m); | ||
| auto converter = state->getCartesianConverter(); | ||
|
|
||
| // IMPORTANT: currently hardcoded to assume hover search pathing, so it | ||
| // takes photos whenever it gets to a new waypoint (loiter position) | ||
| // if we were doing forward pathing would probably want to make it | ||
| // take photos at an interval but only when over the zone | ||
| auto curr_waypoint = this->state->getMav()->curr_waypoint(); | ||
|
|
||
| if (this->curr_mission_item != curr_waypoint) { | ||
| LOG_F(INFO, "FlySearch Area reached (%zu, %d)", this->curr_mission_item, curr_waypoint); | ||
| for (int i = 0; i < this->state->config.pathing.coverage.hover.pictures_per_stop; i++) { | ||
| auto photo = this->state->getCamera()->takePicture(500ms, this->state->getMav()); | ||
| if (state->config.camera.save_images_to_file) { | ||
| photo->saveToFile(state->config.camera.save_dir); | ||
| } | ||
|
|
||
| if (photo.has_value()) { | ||
| // Update the last photo time | ||
| this->last_photo_time = getUnixTime_ms(); | ||
| // Run the pipeline on the photo | ||
| this->state->getCV()->runPipeline(photo.value()); | ||
| // Convert GPS to local XYZ coords | ||
| if(converter){ | ||
| XYZCoord current_xyz = converter->toXYZ(current_pos); | ||
| // Get the airdrop boundary polygon | ||
| Polygon airdrop_boundary = state->mission_params.getAirdropBoundary(); | ||
| // Check if we're inside the airdrop zone | ||
| bool in_zone = Environment::isPointInPolygon(airdrop_boundary, current_xyz); | ||
|
|
||
| if(in_zone){ | ||
| auto curr_waypoint = this->state->getMav()->curr_waypoint(); | ||
|
|
||
| if (this->curr_mission_item != curr_waypoint) { | ||
| LOG_F(INFO, "FlySearch Area reached (%zu, %d)", this->curr_mission_item, curr_waypoint); | ||
| /* | ||
| for (int i = 0; i < this->state->config.pathing.coverage.hover.pictures_per_stop; i++) { | ||
| auto photo = this->state->getCamera()->takePicture(500ms, this->state->getMav()); | ||
| if (state->config.camera.save_images_to_file) { | ||
| photo->saveToFile(state->config.camera.save_dir); | ||
| } | ||
|
|
||
| if (photo.has_value()) { | ||
| // Update the last photo time | ||
| this->last_photo_time = getUnixTime_ms(); | ||
| // Run the pipeline on the photo | ||
| this->state->getCV()->runPipeline(photo.value()); | ||
| } | ||
| } | ||
| */ | ||
| this->curr_mission_item = curr_waypoint; | ||
|
|
||
| return nullptr; | ||
|
Comment on lines
+61
to
+99
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code should be deleted/moved to the camera thread (it should take picture on waypoint for hover mode).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still needs to be done (i.e. if it is migrated, delete the current code) |
||
| } | ||
| } | ||
| this->curr_mission_item = curr_waypoint; | ||
|
|
||
| return nullptr; | ||
| } | ||
|
|
||
|
|
||
| return nullptr; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These names are very ambiguous. The camera is not the only separate thread that is running, nor is the aridrop_zone the only zone (or at least in years past).