コード例 #1
0
ファイル: Main.cs プロジェクト: kasertim/sentience
		public static void Main(string[] args)
		{
			//tests_metagridbuffer.LocaliseAlongPath();
			
            // extract command line parameters
            ArrayList parameters = commandline.ParseCommandLineParameters(args, "-", GetValidParameters());

            string help_str = commandline.GetParameterValue("help", parameters);
            if (help_str != "")
            {
                ShowHelp();
            }
            else
            {
                Console.WriteLine("steersman: creates sensor models to steer a robot along a path");					
				
				int body_width_mm = 465;
                string body_width_mm_str = commandline.GetParameterValue("bodywidth", parameters);
                if (body_width_mm_str != "")
					body_width_mm = Convert.ToInt32(body_width_mm_str);

				int body_length_mm = 375;
                string body_length_mm_str = commandline.GetParameterValue("bodylength", parameters);
                if (body_length_mm_str != "")
					body_length_mm = Convert.ToInt32(body_length_mm_str);

				int body_height_mm = 930;
                string body_height_mm_str = commandline.GetParameterValue("bodyheight", parameters);
                if (body_height_mm_str != "")
					body_height_mm = Convert.ToInt32(body_height_mm_str);

				int centre_of_rotation_x = body_width_mm/2;
                string centre_of_rotation_x_str = commandline.GetParameterValue("centrex", parameters);
                if (centre_of_rotation_x_str != "")
					centre_of_rotation_x = Convert.ToInt32(centre_of_rotation_x_str);

				int centre_of_rotation_y = 75; //body_length_mm/2;
                string centre_of_rotation_y_str = commandline.GetParameterValue("centrey", parameters);
                if (centre_of_rotation_y_str != "")
					centre_of_rotation_y = Convert.ToInt32(centre_of_rotation_y_str);

				int centre_of_rotation_z = 75;
                string centre_of_rotation_z_str = commandline.GetParameterValue("centrez", parameters);
                if (centre_of_rotation_z_str != "")
					centre_of_rotation_z = Convert.ToInt32(centre_of_rotation_z_str);

				int head_centroid_x = body_width_mm/2;
                string head_centroid_x_str = commandline.GetParameterValue("headx", parameters);
                if (head_centroid_x_str != "")
					head_centroid_x = Convert.ToInt32(head_centroid_x_str);

				int head_centroid_y = 65; //body_length_mm/2;
                string head_centroid_y_str = commandline.GetParameterValue("heady", parameters);
                if (head_centroid_y_str != "")
					head_centroid_y = Convert.ToInt32(head_centroid_y_str);

				int head_centroid_z = 1600; //body_height_mm;
                string head_centroid_z_str = commandline.GetParameterValue("headz", parameters);
                if (head_centroid_z_str != "")
					head_centroid_z = Convert.ToInt32(head_centroid_z_str);

                string sensormodels_filename = "";

				int no_of_stereo_cameras = 2;
                string no_of_stereo_cameras_str = commandline.GetParameterValue("cameras", parameters);
                if (no_of_stereo_cameras_str != "")
					no_of_stereo_cameras = Convert.ToInt32(no_of_stereo_cameras_str);

				float baseline_mm = 120;
                string baseline_mm_str = commandline.GetParameterValue("baseline", parameters);
                if (baseline_mm_str != "")
					baseline_mm = Convert.ToSingle(baseline_mm_str);

				// height of the cameras above the head tilt axis
				float dist_from_centre_of_tilt_mm = 0;
                string dist_from_centre_of_tilt_str = commandline.GetParameterValue("disttilt", parameters);
                if (dist_from_centre_of_tilt_str != "")
					dist_from_centre_of_tilt_mm = Convert.ToSingle(dist_from_centre_of_tilt_str);

				int image_width = 320;
				int image_height = 240;
                string resolution_str = commandline.GetParameterValue("resolution", parameters);
                if (resolution_str != "")
				{
					string[] str = resolution_str.ToLower().Split('x');
					if (str.Length == 2)
					{
						image_width = Convert.ToInt32(str[0]);
						image_height = Convert.ToInt32(str[1]);
					}					
				}

				float FOV_degrees = 65;
                string FOV_degrees_str = commandline.GetParameterValue("fov", parameters);
                if (FOV_degrees_str != "")
					FOV_degrees = Convert.ToSingle(FOV_degrees_str);

				float head_diameter_mm = 215;
                string head_diameter_mm_str = commandline.GetParameterValue("headdiam", parameters);
                if (head_diameter_mm_str != "")
					head_diameter_mm = Convert.ToSingle(head_diameter_mm_str);

				float default_head_orientation_degrees = 0;
                string default_head_orientation_degrees_str = commandline.GetParameterValue("orient", parameters);
                if (default_head_orientation_degrees_str != "")
					default_head_orientation_degrees = Convert.ToSingle(default_head_orientation_degrees_str);

				int no_of_grid_levels = 1;
                string no_of_grid_levels_str = commandline.GetParameterValue("gridlevels", parameters);
                if (no_of_grid_levels_str != "")
					no_of_grid_levels = Convert.ToInt32(no_of_grid_levels_str);
				
				int dimension_mm = 8000;
                string dimension_mm_str = commandline.GetParameterValue("griddim", parameters);
                if (dimension_mm_str != "")
					dimension_mm = Convert.ToInt32(dimension_mm_str);

				int dimension_vertical_mm = 2000;
                string dimension_vertical_mm_str = commandline.GetParameterValue("griddimvert", parameters);
                if (dimension_vertical_mm_str != "")
					dimension_vertical_mm = Convert.ToInt32(dimension_vertical_mm_str);

				int cellSize_mm = 50;
                string cellSize_mm_str = commandline.GetParameterValue("cellsize", parameters);
                if (cellSize_mm_str != "")
					cellSize_mm = Convert.ToInt32(cellSize_mm_str);
				
                string filename = commandline.GetParameterValue("filename", parameters);
                if (filename == "") filename = "steersman.xml";
                
				
				Console.WriteLine("Computing sensor models...Please wait");
				steersman visual_guidance = new steersman(
				    body_width_mm,
				    body_length_mm,
				    body_height_mm,
				    centre_of_rotation_x,
				    centre_of_rotation_y,
				    centre_of_rotation_z,
				    head_centroid_x,
				    head_centroid_y,
				    head_centroid_z,
				    sensormodels_filename,
				    no_of_stereo_cameras,
				    baseline_mm,
				    dist_from_centre_of_tilt_mm,
				    image_width,
				    image_height,
				    FOV_degrees,
				    head_diameter_mm,
				    default_head_orientation_degrees,
		            no_of_grid_levels,
				    dimension_mm, 
		            dimension_vertical_mm, 
		            cellSize_mm);
				
				visual_guidance.Save(filename);
				Console.WriteLine("Saved as " + filename);
            }
		}
コード例 #2
0
ファイル: tests_steersman.cs プロジェクト: kasertim/sentience
		public void LocaliseAlongPath()
		{
            // systematic bias
            float bias_x_mm = -200;
            float bias_y_mm = 0;
			
			// number of stereo features per step during mapping
			int no_of_mapping_stereo_features = 300;
			
			// number of stereo features observed per localisation step
			int no_of_localisation_stereo_features = 50;

		    string filename = "steersman_localise_along_path.dat";
		    float path_length_mm = 10000;
		    float start_orientation = 0;
		    float end_orientation = 0; //90 * (float)Math.PI / 180.0f;
		    float distance_between_poses_mm = 100;
            float disparity = 15;
			
			string steersman_filename = "tests_steersman_LocaliseAlongPath.xml";
		    int body_width_mm = 465;
		    int body_length_mm = 380;
		    int body_height_mm= 1660;
		    int centre_of_rotation_x = body_width_mm/2;
		    int centre_of_rotation_y = body_length_mm/2;
		    int centre_of_rotation_z = 10;
		    int head_centroid_x = body_width_mm/2;
		    int head_centroid_y = 65;
		    int head_centroid_z = 1600;
		    string sensormodels_filename = "";
		    int no_of_stereo_cameras = 2;
		    float baseline_mm = 120;
			float dist_to_centre_of_tilt_mm = 0;
		    int image_width = 320;
		    int image_height = 240;
		    float FOV_degrees = 65;
		    float head_diameter_mm = 160;
		    float default_head_orientation_degrees = 0;
            int no_of_grid_levels = 1;
		    int dimension_mm = 8000;
            int dimension_vertical_mm = 2000; 
            int cellSize_mm = 50;
						
			string[] str = filename.Split('.');
				
			List<OdometryData> path = null;
            tests_metagridbuffer.SavePath(
		        filename,
		        path_length_mm,
		        start_orientation,
		        end_orientation,
		        distance_between_poses_mm,
                disparity,
			    no_of_mapping_stereo_features,
			    no_of_stereo_cameras,
			    ref path);
			
			Assert.AreEqual(true, File.Exists(filename));
			Assert.AreEqual(true, File.Exists(str[0] + "_disparities_index.dat"));
			Assert.AreEqual(true, File.Exists(str[0] + "_disparities.dat"));
						
			steersman visual_guidance = null;
			if (File.Exists(steersman_filename))
			{
				visual_guidance = new steersman();
				visual_guidance.Load(steersman_filename);
			}
			else
			{
				visual_guidance = new steersman(
			        body_width_mm,
			        body_length_mm,
			        body_height_mm,
			        centre_of_rotation_x,
			        centre_of_rotation_y,
			        centre_of_rotation_z,
			        head_centroid_x,
			        head_centroid_y,
			        head_centroid_z,
			        sensormodels_filename,
			        no_of_stereo_cameras,
			        baseline_mm,
				    dist_to_centre_of_tilt_mm,
			        image_width,
			        image_height,
			        FOV_degrees,
			        head_diameter_mm,
			        default_head_orientation_degrees,
	                no_of_grid_levels,
			        dimension_mm,
	                dimension_vertical_mm,
	                cellSize_mm);
				
			    visual_guidance.Save(steersman_filename);
			}
			
            visual_guidance.LoadPath(filename, str[0] + "_disparities_index.dat", str[0] + "_disparities.dat");
            
			visual_guidance.ShowLocalisations("steersman_localise_along_path.jpg", 640, 480);
			
		    Random rnd = new Random(0);
            pos3D pose_offset = null;
            bool buffer_transition = false;

		    float[][] stereo_features = new float[no_of_stereo_cameras][];
		    byte[][,] stereo_features_colour = new byte[no_of_stereo_cameras][,];
		    float[][] stereo_features_uncertainties = new float[no_of_stereo_cameras][];
			for (int i = 0; i < no_of_stereo_cameras; i++)
			{
			    stereo_features_uncertainties[i] = new float[no_of_localisation_stereo_features];
			    for (int j = 0; j < no_of_localisation_stereo_features; j++)
				    stereo_features_uncertainties[i][j] = 1;
			}

            float average_offset_x_mm = 0;
            float average_offset_y_mm = 0;
			List<OdometryData> estimated_path = new List<OdometryData>();
			
			int no_of_localisation_failures = 0;

			DateTime start_time = DateTime.Now;
			int no_of_localisations = 0;
			for (int i = 0; i < path.Count-1; i += 5, no_of_localisations++)
			{
                string debug_mapping_filename = "steersman_localise_along_path_map_" + i.ToString() + ".jpg";

				OdometryData p0 = path[i];
				OdometryData p1 = path[i + 1];
				
				float current_x_mm = p0.x + ((p1.x - p0.x)/2) + bias_x_mm; 
				float current_y_mm = p0.y + ((p1.y - p0.y)/2) + bias_y_mm;
				float current_pan = p0.orientation + ((p1.orientation - p0.orientation)/2);
				
				// create an intermediate pose
				for (int cam = 0; cam < no_of_stereo_cameras; cam++)
				{
					// set the current pose
					visual_guidance.SetCurrentPosition(
					    cam,
				        current_x_mm,
				        current_y_mm,
				        0,
				        current_pan,
					    0, 0);
								
					// create stereo features				
					int ctr = 0;
					stereo_features[cam] = new float[no_of_localisation_stereo_features * 3];
					stereo_features_colour[cam] = new byte[no_of_localisation_stereo_features, 3];
					for (int f = 0; f < no_of_localisation_stereo_features; f += 5)
					{
						if (f < no_of_localisation_stereo_features/2)
						{
							stereo_features[cam][ctr++] = 20;
							stereo_features[cam][ctr++] = rnd.Next(239);
						}
						else
						{
							stereo_features[cam][ctr++] = image_width - 20;
							stereo_features[cam][ctr++] = rnd.Next(239);
						}
					    stereo_features[cam][ctr++] = disparity;
					}
				}
				
				float offset_x_mm = 0;
				float offset_y_mm = 0;
				float offset_z_mm = 0;
				float offset_pan = 0;
				float offset_tilt = 0;
				float offset_roll = 0;
				
				bool valid_localisation = visual_guidance.Localise(
				    stereo_features,
				    stereo_features_colour,
				    stereo_features_uncertainties,
				    debug_mapping_filename,
				    bias_x_mm, bias_y_mm,
				    ref offset_x_mm,
				    ref offset_y_mm,
				    ref offset_z_mm,
				    ref offset_pan,
				    ref offset_tilt,
				    ref offset_roll);
				
				if (valid_localisation)
				{				
					Console.WriteLine("pose_offset (mm): " + offset_x_mm.ToString() + ", " + offset_y_mm.ToString() + ", " + offset_pan.ToString());
					OdometryData estimated_pose = new OdometryData();
					estimated_pose.x = current_x_mm + offset_x_mm;
					estimated_pose.y = current_y_mm + offset_y_mm;
					estimated_pose.orientation = current_pan + offset_pan;
					estimated_path.Add(estimated_pose);
	                average_offset_x_mm += offset_x_mm;
	                average_offset_y_mm += offset_y_mm;
				}
				else
				{
					// fail!
					no_of_localisation_failures++;
					Console.WriteLine("Localisation failure");
				}
			}
			
			TimeSpan diff = DateTime.Now.Subtract(start_time);
			float time_per_localisation_sec = (float)diff.TotalSeconds / no_of_localisations;
			Console.WriteLine("Time per localisation: " + time_per_localisation_sec.ToString() + " sec");

            visual_guidance.ShowLocalisations("steersman_localisations_along_path.jpg", 640, 480);

            average_offset_x_mm /= estimated_path.Count;
            average_offset_y_mm /= estimated_path.Count;
            Console.WriteLine("Average offsets: " + average_offset_x_mm.ToString() + ", " + average_offset_y_mm.ToString());

            float diff_x_mm = Math.Abs(average_offset_x_mm - bias_x_mm);
            float diff_y_mm = Math.Abs(average_offset_y_mm - bias_y_mm);
            Assert.Less(diff_x_mm, cellSize_mm*3/2, "x bias not detected");
            Assert.Less(diff_y_mm, cellSize_mm*3/2, "y bias not detected");	
			
			if (no_of_localisation_failures > 0)
				Console.WriteLine("Localisation failures: " + no_of_localisation_failures.ToString());
			else
				Console.WriteLine("No localisation failures!");
			Assert.Less(no_of_localisation_failures, 4, "Too many localisation failures");
        }