Download presentation
Presentation is loading. Please wait.
Published byTiffany Foster Modified over 8 years ago
1
1 Introduction to Haptics Introduction to the Hapkit board Allison M. Okamura Stanford University
2
2 We need to calibrate the Hapkit so that we know what positions and forces we are working with in real, translational units (meters and Newtons) Stanford University Introduction to Haptics © Allison M. Okamura, 2013 Motor calibration: Given a desired force output (based on what we want our haptic VE to feel like), what duty cycle must we command? 1. Assume you start with the desired force at the handle in Newtons. (Since this the force that your haptic virtual environment will generate) 1. Using the kinematic equations for force/torque, find what motor pulley torque (tp) is required to generate that force. Add this to your code. 1. The lab has determined a calibration equation to compute the PWM duty cycle needed to generate this torque. In Arduino code, it is: duty = sqrt(tp/0.03); Activity: Calibrate Sensor and Actuator 2
3
3 We need to calibrate the Hapkit so that we know what positions and forces we are working with in real, translational units (meters and Newtons) Stanford University Introduction to Haptics © Allison M. Okamura, 2013 MR sensor calibration: Use angle markings on your Hapkit sector, the Serial Monitor (SM), and r handle to determine x handle. Manually record a series of about 10 sector angles (degrees) and their corresponding A/D output values. Plot these sector angles in Excel with angles on vertical axis (y) and A/D outputs on horizontal axis (x) and fit a straight line. Record the m and b parameters of the fit y = mx + b. Convert sector angle to radians, and then use kinematics to convert sector angle to handle position in meters. Add the equations from steps 3 and 4 to your code, and test using the Arduino Serial Monitor. Activity: Calibrate Sensor and Actuator 3
4
4 Programming the Hapkit Stanford University Introduction to Haptics © Allison M. Okamura, 2013 Arduino is a single-board microcontroller that makes using electronics in multidisciplinary projects relatively easy The Hapkit board is based on the Arduino design, with some added features The Hapkit board can be programmed using the same Arduino integrated development environment (IDE) as an Arduino board Follow the instructions in the handout to download, install, and test the Arduino software 4
5
5 Arduino Programming Language Components Stanford University Introduction to Haptics © Allison M. Okamura, 2013 Arduino reference materials obtained from http://arduino.cc under a Commons Attribution- ShareAlike 3.0 License.Commons Attribution- ShareAlike 3.0 License StructureVariablesFunctions Basic syntax Arithmetic operators Control structures Comparison Operators Boolean Operators Constants Data types Scope Digital I/O Analog I/O Math Serial communication Defining your own 5
6
6 Structure: Basic Syntax Stanford University Introduction to Haptics © Allison M. Okamura, 2013 Arduino reference materials obtained from http://arduino.cc under a Commons Attribution-ShareAlike 3.0 License.Commons Attribution-ShareAlike 3.0 License Each statement ends in a semicolon. For example: int a = 13; Curly braces always come in pairs; they are used to define the start and end of functions, loops, and conditional statements. For example: while (boolean expression) { statement(s) } Single line comment Multi-line comment Used to give a name to a constant value. For example: #define ledPin 3 ; {} // /* */ #define 6
7
7 Structure: Basic Syntax Stanford University Introduction to Haptics © Allison M. Okamura, 2013 Arduino reference materials obtained from http://arduino.cc under a Commons Attribution- ShareAlike 3.0 License.Commons Attribution- ShareAlike 3.0 License Each statement ends in a semicolon. For example: int a = 13; Curly braces always come in pairs; they are used to define the start and end of functions, loops, and conditional statements. For example: while (boolean expression) { statement(s) } Single line comment Multi-line comment Used to give a name to a constant value. For example: #define ledPin 3 ; {} // /* */ #define 7
8
8 Structure: Arithmetic Operators Stanford University Introduction to Haptics © Allison M. Okamura, 2013 Arduino reference materials obtained from http://arduino.cc under a Commons Attribution-ShareAlike 3.0 License.Commons Attribution-ShareAlike 3.0 License Assignment operator stores the value to the right of the equal sign in the variable to the left of the equal sign: sensorVal = analogRead(FSRPin); Addition, subtraction, multiplication, and division. For example: result = value1 + value2; result = value1 - value2; result = value1 * value2; result = value1 / value2; where value1 and value2 are any variables or constants =+-*/=+-*/ Tips: Choose variable sizes that are large enough to hold the largest calculated result For math that requires fractions, use float variables (but there are drawbacks) Check for order of operations; use parentheses to enforce order 8
9
9 Example Hapkit Program Stanford University Introduction to Haptics © Allison M. Okamura, 2013 Programming Area Code: // Blink the pin 13 LED void setup() { pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); } material courtesy Paulo Blikstein The Arduino programming language is similar to C and Java 9
10
10 Structure: Control structures Stanford University Introduction to Haptics © Allison M. Okamura, 2013 Arduino reference materials obtained from http://arduino.cc under a Commons Attribution-ShareAlike 3.0 License.Commons Attribution-ShareAlike 3.0 License Creates a loop for repetitive operations. for (initialization; condition; increment) { //statement(s); } for 10
11
11 Running a Hapkit Program Stanford University Introduction to Haptics © Allison M. Okamura, 2013 Click File > Upload Clicking Upload sends the code from the computer to the Hapkit board material courtesy Paulo Blikstein or click the Upload button Your code is now running on the Hapkit Board! What is the LED doing? 11
12
12 Programming syntax/hints Stanford University Introduction to Haptics © Allison M. Okamura, 2013 Use // before any text you want to have as a comment (and comment well!) Each statement must end with a ; (semicolon) You must declare variables before you use them Call built-in Arduino functions to perform I/O (input/output) See http://arduino.cc/en/Reference/HomePage for a language reference that describes structure, variables, and functions If you have never programmed before, the easiest way to learn is by looking at and modifying example programs. Don ’ t modify too many things at once before testing your code. Many examples under File > Examples 12
13
13 Understanding the code Stanford University Introduction to Haptics © Allison M. Okamura, 2013 // Blink the pin 13 LED void setup() { pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); } material courtesy Paulo Blikstein void setup() { … } Any code inside the setup function runs once to setup the Arduino void loop() { … } Any code inside the loop function loops over and over again 13
14
14 Understanding the code Stanford University Introduction to Haptics © Allison M. Okamura, 2013 // Blink the pin 13 LED void setup() { pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); } material courtesy Paulo Blikstein void setup() { … } Any code inside the setup function runs once to setup the Arduino void loop() { … } Any code inside the loop function loops over and over again 14
15
15 Understanding the code Stanford University Introduction to Haptics © Allison M. Okamura, 2013 // Blink the pin 13 LED void setup() { pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); } material courtesy Paulo Blikstein pinMode(Pin Number, INPUT or OUTPUT) This tells the Arduino whether the pin is an input (ie. sensor, switch) or an output (i.e. LED, motor). You will connect Pin 13 to an LED. The other pins can be externally connected to whatever you want! 15
16
16 Understanding the code Stanford University Introduction to Haptics © Allison M. Okamura, 2013 // Blink the pin 13 LED void setup() { pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); } material courtesy Paulo Blikstein digitalWrite(Pin Number, HIGH or LOW) This makes the specified pin HIGH (a digital 1) or LOW (a digital 0). The LED is on if it is HIGH and off if it is LOW. We first make the LED turn on by making pin 13 HIGH, then we make it turn off by making pin 13 LOW. Digital 1 = +5 Volts = HIGH Digital 0 = 0 Volts = LOW delay(Milliseconds) This makes the Arduino wait for the specified number of milliseconds. Without the delay, the LED would blink so fast, you wouldn't notice! 16
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.