Skip to content
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

Look into waypoint or GPS simulation #2

Open
kuasha opened this issue Feb 24, 2017 · 4 comments
Open

Look into waypoint or GPS simulation #2

kuasha opened this issue Feb 24, 2017 · 4 comments
Assignees

Comments

@kuasha
Copy link
Collaborator

kuasha commented Feb 24, 2017

The simulator should calculate the cars current position and show it on screen, write it to record csv file and add to network packet.

@kuasha kuasha self-assigned this Feb 24, 2017
@kuasha
Copy link
Collaborator Author

kuasha commented Feb 24, 2017

We need only 3 lines to change to 1) save position(x,y,z) and rotation(x,y,z) to csv file and 2) send those to drive.py. I am not sure if we should allow drive.py to set position/ rotation of the car. In that case few more lines will be required.

self-driving-car-sim/Assets/Standard Assets/Vehicles/Car/Scripts/CarController.cs
Line 428:
https://github.com/udacity/self-driving-car-sim/blob/43c30490fd1230e387397139bc01432f020860ff/Assets/Standard%20Assets/Vehicles/Car/Scripts/CarController.cs#L428
Add

sample.position and sample.rotation.eulerAngles (both are Vector3) ti the CSV file

			if (carSamples.Count > 0) {
				//pull off a sample from the que
				CarSample sample = carSamples.Dequeue();

				//pysically moving the car to get the right camera position
				transform.position = sample.position;
				transform.rotation = sample.rotation;

				// Capture and Persist Image
				string centerPath = WriteImage (CenterCamera, "center", sample.timeStamp);
				string leftPath = WriteImage (LeftCamera, "left", sample.timeStamp);
				string rightPath = WriteImage (RightCamera, "right", sample.timeStamp);

				string row = string.Format ("{0},{1},{2},{3},{4},{5},{6},{7},{8}\n", centerPath, leftPath, rightPath, sample.steeringAngle, sample.throttle, sample.brake, sample.speed, Serialize(sample.position), Serialize(sample.rotation));

				File.AppendAllText (Path.Combine (m_saveLocation, CSVFileName), row);
                   }

And add position and rotation to the CommandServer.cs file:

https://github.com/udacity/self-driving-car-sim/blob/master/Assets/1_SelfDrivingCar/Scripts/CommandServer.cs#L54

UnityMainThreadDispatcher.Instance().Enqueue(() =>
		{
			print("Attempting to Send...");
			// send only if it's not being manually driven
			if ((Input.GetKey(KeyCode.W)) || (Input.GetKey(KeyCode.S))) {
				_socket.Emit("telemetry", new JSONObject());
			}
			else {
				// Collect Data from the Car
				Dictionary<string, string> data = new Dictionary<string, string>();
				data["steering_angle"] = _carController.CurrentSteerAngle.ToString("N4");
				data["throttle"] = _carController.AccelInput.ToString("N4");
				data["speed"] = _carController.CurrentSpeed.ToString("N4");
				data["image"] = Convert.ToBase64String(CameraHelper.CaptureFrame(FrontFacingCamera));

				data["position"] = Serialize(_carController.transform.position);
				data["rotation"] = Serialize(_carController.transform.rotation);

				_socket.Emit("telemetry", new JSONObject(data));
			}
		});

@kuasha
Copy link
Collaborator Author

kuasha commented Feb 24, 2017

This is how it looks in the driving_log.csv file

/Users/kuasha/Desktop/thunderhill/IMG/center_2017_02_24_13_02_03_441.jpg,/Users/kuasha/Desktop/thunderhill/IMG/left_2017_02_24_13_02_03_441.jpg,/Users/kuasha/Desktop/thunderhill/IMG/right_2017_02_24_13_02_03_441.jpg,0,0,0,1.282302E-05,179.8037:1.683794:89.80849,358.1013:7.09326:0.1524871

Lat two values are position (x,y,z) and rotation(x,y,z).

@kuasha
Copy link
Collaborator Author

kuasha commented Feb 24, 2017

Here is how it looks when the position and rotation data is sent to drive.py

Adding print(data["position"], data["rotation"]) in the drive.py file will result a line line the two below:
-48.15347:1.71805:102.9838 359.7105:231.4829:0.1081518
-49.5946:1.717933:101.7985 359.711:230.7614:0.08447754

@kuasha
Copy link
Collaborator Author

kuasha commented Feb 24, 2017

Here is the code change patch file:

sim_loc_rot.patch.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant