Project 04 |
Goals
- Design and implement an accelerometer/compass controller for a Unity Application.
- Control the x, y, z position and rotation.
- Navigate a space in Unity using the controller.
|
Create Unity World |
Install Unity
On your personal laptop install Unity 6.
Create a new 3D unity project scene
- Create a plane
- Game Object Menu -> 3D Object -> Plane
- In the object inspector tab set the scale in the x and z direction to 100.
- Create a sphere
- Game Object Menu -> 3D Object -> Cube
- In the object inspector tab set the cube scale in the x, y and z direction to 10.
- In the object inspector tab set the cube position to (0,7,50).
Create a new C# script
- Create a new script
- Unity Manual: Creating and Using Scripts
- In the project tab click on the Assets folder
- Assets Menu -> Create -> MonoBehaviour Script
- Name your new script "cameraBehavior"
- Double click on your "cameraBehavior" script. (You may want to two finger click, and select "Reveal in Finder" to open in your preferred text editor.)
- Before the start method (but inside the class) create a public float field named rotationDegree and set it equal to 2.0f (you may want to set this constant to something smaller later).
- Attach cameraBehavior script to Main Camera
- Click on Main Camera in Hierarchy tab
- Click on Add Component -> Scripts -> Camera Behavior
- A new Camera Behavior Component should appear in the inspector tab with the ability to set the rotationDegree field.
- Rotate Camera left and right using left and right arrow keys
- Open your "cameraBehavior" script in your preferred text editor.
- Add an if statement to check if the left or right key has been pressed in the update method using a keycode.
- Rotate "rotationDegree" around the y axis left when the left arrow is pressed and right when the right arrow is pressed by calling
transform.Rotate.
- Save your script.
- Click the play button and use the arrow keys to test your program.
- Click the play button again to end testing mode.
Update script
- Add rotation around x, y and z axis
- Rotate "rotationDegree" around the x axis up when the up arrow is pressed and down when the down arrow is pressed.
- Rotate "rotationDegree" around the z axis clockwise when the key "z" is pressed and counter clockwise when the key "q" is pressed.
- Save your script.
- Click the play button and use the keys to test your program.
- Add movement up, down, left, right, forward and back
- Before the start method create a public float field named speed and set it equal to 100.0f (you may want to set this constant to something smaller later).
- Update the object's position forward when pressing 'w', backward when pressing 'x', up when pressing 'e', down when pressing 'c', left when pressing 'a', and right when pressing 'd'.
- Save your script.
- Click the play button and use the keys to test your program.
|
Calibrate Sensor |
Calibration Values
Start with your code from Lab 4.
Save it as a new Arduino project titled colbyUsername_P04_calibration (with your colby username, mine would be hewolfe_P04_calibration).
Calibrate Sensor
To calibrate the sensor, you need to calculate the minimum and maximum values for the accelerometer's x, y, and z and the magnometer's x, y, and z.
- At the global scope, create floats to represent the minimum and maximum values for the the 6 sensor readings (12 variables total) initialized to zero. Also create
Adafruit_LSM303_Accel_Unified and Adafruit_LSM303_Mag_Unified objects.
- In the setup function, begin a serial connection at the baud rate 115200. Initialize the accelerometer and the magnometer.
- In the loop function, update the minimum and maximum values if the value is greater than the maximum or less than the minimum. Once a second, display the sensors 12 minimum and maximum values.
- While running your code, accelerate the sensor in the x, y and z direction and rotate it around the x, y and z axis, to find the minimum and maximum values. Record your final values to use to calibrate your Gesture Controller.
|
Gesture Controller |
Setup
Start with your code from Lab 4.
Save it as a new Arduino project titled colbyUsername_P04_controller (with your colby username, mine would be hewolfe_P04_controller).
Gesture Controller Design
Design an accelerometer based interface to navigate a 3D space.
Interface requirements:
- Control X, Y and Z position of camera in object space
- Control roll, pitch and yaw rotation of camera
- Turn controller "on" and "off"
- Optional: Use button to change between "rotation" and "position" mode.
You may choose to filter or smooth your data using methods from the previous projects.
Carry-over from Lab
Loop Function
- Calibrate your data using linear interpolation. Map your raw data which has a minimum and maximum calibration values, to a value between -9.78 and 9.78 for acceleration and -60 to 60 for compass readings. Optionally: Smooth your results using a rolling average.
- Send sensor data over bluetooth to Unity as keyboard inputs and interpret as movement and rotation.
- A simple solution would be converting values from the sensor as key presses and writing them to bluetooth.
- A more complex solution would be to write the sensor data (floats) to the bluetooth keyboard and modify the C# script interpret the values reference.
- A well organized, designed, and documented solution with an intuitive, accurate and easy to use interface can be worth up to 2 extension points.
Linear Interpolation
Write a method that will take a value from one range and map it to a new value inside another range. The idea here is that we want to map the input value, x, which is within the range x0 to x1, to a new range y0 to y1.
y the new value (output)
y0 the new minimum value
y1 the new maximum value
x the input value
x0 the original minimum value
x1 the original maximum value
Documentation and Analysis
- User Interface Documentation
- Using a diagram, explain how your interface works.
- In a short paragraph explain how your interface works and why you made the design decisions that you did.
- Analysis
- How easy is it to use the interface?
- How accurate is it?
- Were there any modifications you made to it increase the accuracy/usability?
|
Extension |
Extensions
Optionally you can complete 1-2 extensions. Extensions can build on the pre-existing circuit for this project or can be a new circuit. The complexity of the chosen extension, the implementation and the quality of the documentation effects the final grade. I encourage ideas not on the list. I reccommend discussing your extension idea with me (in person or over email) if you are unsure if it reasonable.
Extension code must be separate from the project.
Software Extension
Software extensions build on the pre-existing circuit for this project.
Here are some ideas:
- Add additional functionality/controls.
- Create a more complex scene and control aspects of it with the accelerometer.
- Implement, test and compare other types of interpolation (SLERP etc).
- Connect to a device that is not a phone or computer and create an interface for it. Include atleast 3 commands and explain your user interface design.
Hardware Extension
Design and implement an idea for a new project which involves adding new components and modifying the circuitry.
- It must incorporate the materials from this project; the bluetooth and accelerometer breakout boards.
- It must include atleast one of the following components: microphone, a piezo element, the IR emitters, IR receivers, and/or the vibrating motors.
- It can include potentiometers, buttons and/or red LEDs.
Include in the documentation:
- A circuit diagram.
- A photograph of the circuit board.
Document your Extensions
- Submit your code on filer in a folder inside your project folder.
- A 1-3 minute video documenting your extension working.
- A description of the extension.
- A section on implementation.
- A section on results & reflection.
- Include any relevant photographs, drawings, charts or graphs.
|
Submission |
Export Unity Code as Package
- Assets Menu -> Export Package
- Make sure all the boxes are ticked
- Click "Export"
- Name your package colbyUserID_p4
- Copy you package to filer in your project folder
Submit your code on Filer
Submit your arduino code in a folder titled colbyUsername_P04_controller and colbyUsername_P04_calibration (with your colby username, mine would be hewolfe_P04_controller).
Submit your report and video on Google Classroom
Upload a 1-3 min Documentation Video of your gesture controller working. Show the ability to move forward, back, left, right, up and down. Show the ability to rotate left, right, up, down, clockwise and counter clockwise. State your intention before completing the task. Explain your interface as you are using it. In your video, your controller, screen and keyboard should be visible at all times.
Attach a Google Doc Report which includes:
- Photo of circuit. Clear photo of the circuit in which the wiring is clearly visible.
- Implementation Section
- Explain how you implemented the project.
- Explain what algorithms or techniques you used.
- Explain how a user could collect calibration data using
colbyUsername_P04_calibration and use it in colbyUsername_P04_controller.
- Draw a diagram and explain how you designed your interface.
- Results & Reflection Section
- How well does your implementation work?
- What were the results of your analysis?
- Acknowledgements Section
- What resources did you use? Include websites, books and anyone you received help from or discussed the project with.
|