//constructor for MissionSelection Form for polygon mission public MissionSelection(ProjectSummary _ps, String _FlightPlanFolder, LogFile _logFile, NavInterfaceMBed navIF_In, SDKHandler cameraIn, bool hardwareAttached_, SettingsManager _settings, String _MissionDateString) { InitializeComponent(); posVel_ = new PosVel(); //set the flight plans folder and the Project Summary structure from the prior Project Selection FlightPlanFolder = _FlightPlanFolder; ps = _ps; navIF_ = navIF_In; camera = cameraIn; hardwareAttached = hardwareAttached_; settings = _settings; MissionDateString = _MissionDateString; logFile = _logFile; projectName = ps.ProjectName; //there is a separate constructor for the linearFeature coverage type coverageType = COVERAGE_TYPE.polygon; //getPosVelTimer = new Stopwatch(); utm = new UTM2Geodetic(); ///////////////////////////////////////////////////////////////////////////////////// //set up the project polygon and the individual Mission polygons in pixel units ///////////////////////////////////////////////////////////////////////////////////// //set of points in Pixels that we use to draw the project polygon onto the project map //creats space for an array of Point structures tha will hold the project polygon projectPolyPointsPix = new Point[ps.ProjectPolygon.Count]; //lat/lon image bounds from the mission plan ib = ps.ProjectImage; //placeholder for the project image bounds NOTE: this is also used elsewhere //multiplier used for pix-to-geodetic conversion for the project map -- scales lat/lon to pixels // TODO: ugly --- cant we do this exactly??? //lon2PixMultiplier = mapScaleFactor * mapWidth / (ib.eastDeg - ib.westDeg); //lat2PixMultiplier = -mapScaleFactor * mapHeight / (ib.northDeg - ib.southDeg); //"-" cause vertical map direction is positive towards the south lon2PixMultiplier = mapWidth / (ib.eastDeg - ib.westDeg); lat2PixMultiplier = -mapHeight / (ib.northDeg - ib.southDeg); //"-" cause vertical map direction is positive towards the south //create the project polygon in pixel units -- once for (int i = 0; i < ps.ProjectPolygon.Count; i++) projectPolyPointsPix[i] = GeoToPix(ps.ProjectPolygon[i]); //just uses a linear scaling //create the mission polygons (one per mission) in pixel units //used to form the clickable region on the project map missionPolysInPix = new List<Point[]>(); for (int i = 0; i < ps.msnSum.Count; i++) { Point [] pts = new Point[ps.msnSum[i].missionGeodeticPolygon.Count]; for (int j = 0; j < ps.msnSum[i].missionGeodeticPolygon.Count; j++) pts[j] = GeoToPix(ps.msnSum[i].missionGeodeticPolygon[j]); missionPolysInPix.Add(pts); } }
int volumeChangedCounter; //used to measure the times of the "volume changed" events (two per download) #endregion Fields #region Constructors /// <summary> /// Initialises the SDK and adds events /// </summary> public SDKHandler(LogFile _logFile, SettingsManager settings) { Error = EDSDK.EdsInitializeSDK(); SDKStateEvent += new EDSDK.EdsStateEventHandler(Camera_SDKStateEvent); SDKPropertyEvent += new EDSDK.EdsPropertyEventHandler(Camera_SDKPropertyEvent); SDKObjectEvent += new EDSDK.EdsObjectEventHandler(Camera_SDKObjectEvent); logFile = _logFile; photoParameters = new PhotoParameters(); photoStats = new PhotoStats(); PhotoInProgress = false; photoTimer = new Stopwatch(); volumeChangedCounter = 0; //get the camera list of attached cameras CamList = GetCameraList(); if (CamList.Count == 0) { logFile.WriteLine("There are no attached cameras"); MessageBox.Show("There are no attached cameras"); return; } else if (CamList.Count > 1) { MessageBox.Show("Found more than one attached Canon camera"); logFile.WriteLine("There is more than one attached camera"); return; } //open the session with the first camera (only a single camera is allowed) OpenSession(CamList[0]); //label the camera type String cameraDescription = MainCamera.Info.szDeviceDescription; //label camera serial number String cameraSN = GetSettingString((uint)EDSDK.PropID_BodyIDEx); //label firmware String cameraFirmware = GetSettingString((uint)EDSDK.PropID_FirmwareVersion); //CameraHandler.SetSetting(EDSDK.PropID_SaveTo, (uint)EDSDK.EdsSaveTo.Camera); //CameraHandler.SetSetting(EDSDK.PropID_SaveTo, (uint)EDSDK.EdsSaveTo.Host); SetSetting(EDSDK.PropID_SaveTo, (uint)EDSDK.EdsSaveTo.Both); SetCapacity(); //used to tell camera there is enough room on the PC HD (see codeproject tutorial) //get the capacity and loading of the camera card storage drive //also write out the names of the images to output cameraStats = StorageAssessment(); //fill in the remainder of the camera parameters cameraStats.cameraDescription = cameraDescription; cameraStats.cameraSN = cameraSN; cameraStats.cameraFirmware = cameraFirmware; missionPlansFolder = settings.SaveToFolder; if (!Directory.Exists(missionPlansFolder)) Directory.CreateDirectory(missionPlansFolder); if (!Directory.Exists(missionPlansFolder + @"/TestImages/")) Directory.CreateDirectory(missionPlansFolder + @"/TestImages/"); //default value -- update this ImageSaveDirectory = missionPlansFolder + @"/TestImages/"; ///////////////////////////////////////////////////// // camera settings for WaldoAir Flight Operations ///////////////////////////////////////////////////// try { //set the aperture --- SetSetting(EDSDK.PropID_Av, CameraValues.AV(settings.Camera_fStop)); logFile.WriteLine("Set the fStop: " + settings.Camera_fStop); //set the shutter speed SetSetting(EDSDK.PropID_Tv, CameraValues.TV(settings.Camera_shutter)); logFile.WriteLine("Set the shutter: " + settings.Camera_shutter); //set the ISO SetSetting(EDSDK.PropID_ISOSpeed, CameraValues.ISO(settings.Camera_ISO)); logFile.WriteLine("Set the ISO: " + settings.Camera_ISO); //set the white balance to Daylight SetSetting(EDSDK.PropID_WhiteBalance, EDSDK.WhiteBalance_Daylight); logFile.WriteLine("Set the WhiteBalance: DayLight"); } catch { logFile.WriteLine(" could not set the camera parameters"); MessageBox.Show("Problem setting the Camera parameters"); } }
public void resetLogFile(LogFile _logFile) { //used to change to location of the log file if required logFile = _logFile; }
//constructor for the linearFeature coverage form public Mission(String _FlightPlanFolder, String _MissionDataFolder, String MissionDateStringNameIn, int _missionNumber, linearFeatureCoverageSummary _LFSum, LogFile _logFile, NavInterfaceMBed navIF_In, SDKHandler cameraIn, bool simulatedMission_, bool hardwareAttached_, Image _projectImage) { InitializeComponent(); coverageType = COVERAGE_TYPE.linearFeature; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; posVel_ = new PosVel(); //set the mission image this.Width = (int)(mapScaleFactor * mapWidth); this.Height = (int)(mapScaleFactor * mapHeight); //this.Width = 640; //pixel height of the form //this.Height = 480; //pixel width of the form //retrieve local variables from the arguments missionNumber = _missionNumber; LFSum = _LFSum; MissionDataFolder = _MissionDataFolder; FlightPlanFolder = _FlightPlanFolder; navIF_ = navIF_In; camera = cameraIn; logFile = _logFile; MissionDateStringName = MissionDateStringNameIn; projectImage = _projectImage; //NOTE: if the simulatedMission=true, we will always generate the platform state from the software // If hardwareAttached=true, we will collect the IMU and GPS simulatedMission = simulatedMission_; hardwareAttached = hardwareAttached_; //st up the form to allow keydown events only in the simulation if (simulatedMission) { this.KeyPreview = true; } timeFromTrigger = new Stopwatch(); //showMessage = new Stopwatch(); elapsedTime = new Stopwatch(); getPosVelTimer = new Stopwatch(); //placeholder for the first of the path image bounds ib = LFSum.paths[0].imageBounds[0]; //placeholder for the project image bounds //multiplier used for pix-to-geodetic conversion for the project map -- scales lat/lon to pixels //NOTE -- we do the drawing on top of a bitmap sized to the mapWidth, mapHeight -- then stretch to fit the actual screen lon2PixMultiplier = mapWidth / (ib.eastDeg - ib.westDeg); lat2PixMultiplier = -mapHeight / (ib.northDeg - ib.southDeg); //"-" cause vertical map direction is positive towards the south //lon2PixMultiplier = mapWidth / (ib.eastDeg - ib.westDeg); //lat2PixMultiplier = -mapHeight / (ib.northDeg - ib.southDeg); //"-" cause vertical map direction is positive towards the south platFormPosVel = new PosVel(); platFormPosVel.GeodeticPos = new PointD(0.0, 0.0); platFormPosVel.UTMPos = new PointD(0.0, 0.0); //this will hold the locations of the aircraft over a period of time crumbTrail = new Point[numberCrumbTrailPoints]; labelPilotMessage.Visible = false; //form the along-Path distance at each point (vertex) //will be used for interpolating the commanded altitude along the path for (int j = 0; j < LFSum.paths.Count; j++ ) { LFSum.paths[j].alongPathDistanceAtVertex = new List<double>(); double cumulativeDistance = 0; for (int i=0; i<LFSum.paths[j].pathUTM.Count; i++) if (i == 0) LFSum.paths[j].alongPathDistanceAtVertex.Add(0.0); else { double delX = LFSum.paths[j].pathUTM[i].X - LFSum.paths[j].pathUTM[i - 1].X; double delY = LFSum.paths[j].pathUTM[i].Y - LFSum.paths[j].pathUTM[i - 1].Y; cumulativeDistance += Math.Sqrt(delX * delX + delY * delY); LFSum.paths[j].alongPathDistanceAtVertex.Add(cumulativeDistance); } } }
//constructor for the polygon coverage form public Mission(String _FlightPlanFolder, String _MissionDataFolder, String MissionDateStringNameIn, int _missionNumber, ProjectSummary _ps, bool[] _priorFlownFLs, LogFile _logFile, NavInterfaceMBed navIF_In, SDKHandler cameraIn, bool _simulatedMission, bool _hardwareAttached, StreamWriter _reflyFile, Image _projectImage) { InitializeComponent(); coverageType = COVERAGE_TYPE.polygon; //we use a separate constructor for the linearFeature mission this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; //set the mission image -- mapWidth & mapHeight = 640 X 480 based on the Google Earth map download limits this.Width = (int)(mapScaleFactor * mapWidth); //mapscaleFactor scales the map to fit a screen size of 1024 X 768 this.Height = (int)(mapScaleFactor * mapHeight); //this.Width = 640; //pixel height of the form //this.Height = 480; //pixel width of the form posVel_ = new PosVel(); //retrieve local variables from the arguments missionNumber = _missionNumber; ps = _ps; MissionDataFolder = _MissionDataFolder; FlightPlanFolder = _FlightPlanFolder; priorFlownFLs = _priorFlownFLs; //this contains the completed flight lines so they arent reflown reflyFile = _reflyFile; //write the completed flight line indices to this file projectImage = _projectImage; //contains the complete project image in case the display runs off the smaller maps navIF_ = navIF_In; camera = cameraIn; logFile = _logFile; MissionDateStringName = MissionDateStringNameIn; //NOTE: if the simulatedMission=true, we will always generate the platform state from the software // If hardwareAttached=true, we will collect the IMU and GPS simulatedMission = _simulatedMission; hardwareAttached = _hardwareAttached; timeFromTrigger = new Stopwatch(); elapsedTime = new Stopwatch(); getPosVelTimer = new Stopwatch(); timePastEndfFlightline = new Stopwatch(); ////ib is used internally to the GeoToPix procedures ////we will need to reset the ib & PixMultipliers if we have to use the Project map (plane exits mission map) //ib = ps.msnSum[missionNumber].MissionImage; //placeholder for the Mission image bounds ////multiplier used for pix-to-geodetic conversion for the project map -- scales lat/lon to pixels ////NOTE -- we do the drawing on top of a bitmap sized to the mapWidth, mapHeight -- then stretch to fit the actual screen //lon2PixMultiplier = mapWidth / (ib.eastDeg - ib.westDeg); //lat2PixMultiplier = -mapHeight / (ib.northDeg - ib.southDeg); //"-" cause vertical map direction is positive towards the south platFormPosVel = new PosVel(); platFormPosVel.GeodeticPos = new PointD(0.0, 0.0); platFormPosVel.UTMPos = new PointD(0.0, 0.0); //this will hold the locations of the aircraft over a period of time crumbTrail = new Point[numberCrumbTrailPoints]; //shows the "waiting sats" message labelPilotMessage.Visible = false; //get the max flight line length for this mission -- should come from the missionPlan //used to establish a region before and after the flightlines where flightlinecapture is allowed for (int i = 0; i < ps.msnSum[missionNumber].FlightLinesCurrentPlan.Count; i++) { if (ps.msnSum[missionNumber].FlightLinesCurrentPlan[i].FLLengthMeters > maxFlightLineLength) maxFlightLineLength = ps.msnSum[missionNumber].FlightLinesCurrentPlan[i].FLLengthMeters; } }
void checkForAndValidateFilesNeeded() { //get initialization settings from the Settings.txt file initializationSettings = new SettingsManager(); //initializationSettings.SaveToFolder is the location of the mission plan folder //this is typically set to C://_Waldo_FCS FlightPlanFolder = initializationSettings.SaveToFolder; //set up the logging procedures for the application logFile = new LogFile( ref MissionDateString, initializationSettings); logFile.WriteLine("Mission DateString established: " + MissionDateString); //this will be a temporary location for saving the log file //this will be revised later after we select the mssion //FlightLogFolder = initializationSettings.SaveToFolder + "logs//"; String[] ProjectFolders = null; ProjectFileNames = new List<String>(); ProjectCoverageTypes = new List<COVERAGE_TYPE>(); //flight folder location "_Waldo_FS" at top of C drive if (!Directory.Exists(FlightPlanFolder)) { DialogResult res = MessageBox.Show("There is no mission plan folder (_Waldo_FCS) at the top of the C drive\n ... Use the default example? ", "NO Mission Folder", MessageBoxButtons.YesNo); if (res == DialogResult.No) { Environment.Exit(0); } else { FlightPlanFolder = Directory.GetCurrentDirectory() + "\\SampleMission\\"; if (Directory.Exists(FlightPlanFolder)) { MessageBox.Show("There is no sample mission folder ...", "Terminating ..."); Environment.Exit(0); } } } //////////////////////////////////////////////////////////////////////////////////// //if we get here, we have located the flight plan folder and created a log folder //////////////////////////////////////////////////////////////////////////////////// //get the list of projects in the FlightPlanFolder ProjectFolders = Directory.GetFiles(FlightPlanFolder, "*.kml"); //all files ending in .kml if (ProjectFolders.Count() == 0) { MessageBox.Show("There are no Projects in the FlightPlanFolder folder", "Terminating ... "); Environment.Exit(0); } logFile.WriteLine(""); logFile.WriteLine("Opening Project plans"); foreach (String pth in ProjectFolders) { //open each of the .kml files to see if they are valid missions plans //and detect either Polygon plans or LinearFeature Plans String kmlFilename = FlightPlanFolder + Path.GetFileNameWithoutExtension(pth) + ".kml"; logFile.WriteLine("Project plan: " + kmlFilename); COVERAGE_TYPE coverageType = COVERAGE_TYPE.notSet; XmlTextReader tr = new XmlTextReader(kmlFilename); //associate the textReader with input file ProjectKmlReadUtility ps = new ProjectKmlReadUtility(tr, ref coverageType); //we will display only input kml files that are detected to be polygon of linearFeature types if (coverageType != COVERAGE_TYPE.notSet) { //test for a matching Background folder String BackgroundMapFolderName = FlightPlanFolder + Path.GetFileNameWithoutExtension(pth) + "_Background\\"; if (!Directory.Exists(BackgroundMapFolderName)) { MessageBox.Show("Valid plan: " + pth + ", found but no matching Background maps folder\n skip this plan"); } else { int validMaps = 0; String[] mapFiles = Directory.GetFiles(BackgroundMapFolderName, "*.png"); //all files ending in .kml foreach (String st in mapFiles) { String ss = Path.GetFileNameWithoutExtension(st); if (ss == "ProjectMap" || ss == "Background_00") { validMaps++; } } if (validMaps < 2) { MessageBox.Show(pth + ": maps not correct in Background Folder\n skip this plan"); break; } //have found a valid mission plan with matching Background maps. ProjectFileNames.Add(Path.GetFileNameWithoutExtension(pth)); ProjectCoverageTypes.Add(coverageType); } } else { MessageBox.Show(pth + ": Invalid mission plan\n id you use latest KML_Reader?\n skip this plan"); } } //test for no valid mission plans if (ProjectFileNames.Count == 0) { MessageBox.Show("There are no valid Polygon or LinearFeature projects \nDid you use a valid mission planner?"); Environment.Exit(0); } logFile.WriteLine("Completed opening project plans"); logFile.WriteLine(""); }
public NavInterfaceMBed(LogFile _logFile, SettingsManager Settings) { logFile = _logFile; //file where we write the mbed navigation data and status message //Thread reader/writer lock to prevent clobbering the posvel variable while it is being accessed posvelLock = new ReaderWriterLockSlim(); comStatusMessageLock = new ReaderWriterLockSlim(); triggerTimeReceievdFromMbed = false; //set to true when we receive a 1PPS status message //reset to false in the calling program when the status message is processed //used to store the CRC results fpr the GPS messages received at the PC GPS_PC_CRC = new GPSMessageCRC_atPC(); trigger = new Trigger(); computeCRC = new NovatelCRC(); //class to compute the Novatel CRC value (see their manual) comStats = new CommStats(); //accumulated comm stats commStatusMessage = new CommStatusMessage(); //per sec comm status message navIFMutex_ = new Mutex(); //not sure we need this //////////////////////////////////////////////////////////////////////////////////////////// //wait here in a loop unitl we have attached the USB cable to access the mbed device //////////////////////////////////////////////////////////////////////////////////////////// initializeMbedSerialPort(); if (!serialInit_) { logFile.WriteLine("mbed serial port not found"); throw new Exception("no serial port found"); } ///////////////////////////////////////////////////////////////////////////////////// //At this stage we have found the mbed port and have successfully opened the port ///////////////////////////////////////////////////////////////////////////////////// logFile.WriteLine("Successfully opened the mbed device"); utm = new UTM2Geodetic(); posvelAt1PPS = new PosVel(); timeFrom1PPS = new Stopwatch(); //set up the communications interface thread Thread mbedCommunication = new Thread(mbedCommunicationWorker); mbedCommunication.IsBackground = false; //start the communication and begin retrieving mbed messages mbedCommunication.Start(); logFile.WriteLine("Completed starting the mbed communication thread"); if (mbedCommunication.IsAlive) { logFile.WriteLine("mbedCommunication thread is operating "); } else { logFile.WriteLine("mbed communication htread os not operating "); MessageBox.Show("mbed comminication thread did not start "); } }
public void resetLogFile(LogFile _mbedLogFile) { //allows resetting the logfile for the case where we close it and reopen it in the calling procedure; //allows an early definition/placement of logging messages and then close/re-open the log file at another location //used to enable naming the log file AFTER we have selected a mission during Waldo_FCS logFile = _mbedLogFile; }
//constructor for MissionSelection Form Linear Feature mission public MissionSelection(linearFeatureCoverageSummary _LFSum, String _FlightPlanFolder, LogFile _logFile, NavInterfaceMBed navIF_In, SDKHandler cameraIn, bool hardwareAttached_, SettingsManager _settings, String _MissionDateString) { InitializeComponent(); posVel_ = new PosVel(); //set the flight plans folder and the Project Summary structure from the prior Project Selection FlightPlanFolder = _FlightPlanFolder; LFSum = _LFSum; navIF_ = navIF_In; camera = cameraIn; hardwareAttached = hardwareAttached_; settings = _settings; MissionDateString = _MissionDateString; logFile = _logFile; projectName = LFSum.ProjectName; //this is a specific constructor for the linear feature coverage type coverageType = COVERAGE_TYPE.linearFeature; getPosVelTimer = new Stopwatch(); utm = new UTM2Geodetic(); //lat/lon image bounds from the mission plan ib = LFSum.ProjectImage; //placeholder for the project image bounds NOTE: this is also used elsewhere //multiplier used for pix-to-geodetic conversion for the project map -- scales lat/lon to pixels // TODO: ugly --- cant we do this exactly??? //lon2PixMultiplier = mapScaleFactor * mapWidth / (ib.eastDeg - ib.westDeg); //lat2PixMultiplier = -mapScaleFactor * mapHeight / (ib.northDeg - ib.southDeg); //"-" cause vertical map direction is positive towards the south lon2PixMultiplier = mapWidth / (ib.eastDeg - ib.westDeg); lat2PixMultiplier = -mapHeight / (ib.northDeg - ib.southDeg); //"-" cause vertical map direction is positive towards the south }