Introduction to Haptics Introduction to the Hapkit board

Introduction to Haptics Introduction to the Hapkit board Allison M. Okamura Stanford University 1

Activity: Calibrate Sensor and Actuator 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) 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 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); Stanford 2 University Okamura, 2013 Introduction to Haptics 2 © Allison M.

Activity: Calibrate Sensor and Actuator 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) • MR sensor calibration: Use angle markings on your Hapkit sector, the Serial Monitor (SM), and rhandle to determine xhandle. • 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. Stanford 3 University Okamura, 2013 Introduction to Haptics 3 © Allison M.

Programming the Hapkit 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 Stanford 4 University Okamura, 2013 Introduction to Haptics 4 © Allison M.

Arduino Programming Language Components Structure Variables Functions Basic syntax Constants Digital I/O Arithmetic operators Data types Analog I/O Control structures Scope Math Comparison Operators Serial communication Boolean Operators Defining your own 5 Stanford University Okamura, 2013 Arduino reference materials obtained from http: //arduino. cc under a Commons Attribution. Share. Alike 3. 0 License. Introduction to Haptics 5 © Allison M.

Structure: Basic Syntax ; 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 led. Pin 3 #define Stanford 6 University Okamura, 2013 Arduino reference materials obtained from http: //arduino. cc under a Commons Attribution-Share. Alike 3. 0 License. Introduction to Haptics 6 © Allison M.

Structure: Basic Syntax ; 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 led. Pin 3 Arduino reference materials obtained from http: //arduino. cc under a Commons Attribution. Stanford 7 University Okamura, 2013 Share. Alike 3. 0 License. Introduction to Haptics 7 © Allison M.

Structure: Arithmetic Operators = Assignment operator stores the value to the right of the equal sign in the variable to the left of the equal sign: + sensor. Val = analog. Read(FSRPin); - Addition, subtraction, multiplication, and division. For * example: result = value 1 + value 2; result = value 1 - value 2; / result = value 1 * value 2; result = value 1 / value 2; where value 1 and value 2 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 Stanford 8 University Okamura, 2013 Arduino reference materials obtained from http: //arduino. cc under a Commons Attribution-Share. Alike 3. 0 License. Introduction to Haptics 8 © Allison M.

Example Hapkit Program Code: Programming Area Stanford 9 University Okamura, 2013 // Blink the pin 13 LED void setup() { pin. Mode(13, OUTPUT); } void loop() { digital. Write(13, HIGH); delay(1000); digital. Write(13, LOW); delay(1000); } The Arduino programming language is similar to C and material courtesy Paulo Blikstein Java Introduction to Haptics 9 © Allison M.

Structure: Control structures for Creates a loop for repetitive operations. for (initialization; condition; increment) { //statement(s); Stanford 10 University Okamura, 2013 } Arduino reference materials obtained from http: //arduino. cc under a Commons Attribution-Share. Alike 3. 0 License. Introduction to Haptics 10 © Allison M.

Running a Hapkit Program Click File > Upload Clicking Upload sends the code from the computer to the Hapkit board Stanford 11 University Okamura, 2013 or click the Upload button Your code is now running on the Hapkit Board! What is the LED doing? Introduction to Haptics 11 material courtesy Paulo Blikstein © Allison M.

Programming syntax/hints • 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/Home. Page 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 12 Stanford University File > Examples Introduction to Haptics © Allison M. 12 Okamura, 2013

Understanding the code // Blink the pin 13 LED void setup() { pin. Mode(13, OUTPUT); } void loop() { digital. Write(13, HIGH); delay(1000); digital. Write(13, LOW); delay(1000); } Stanford 13 University Okamura, 2013 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 Introduction to Haptics 13 material courtesy Paulo Blikstein © Allison M.

Understanding the code // Blink the pin 13 LED void setup() { pin. Mode(13, OUTPUT); } void loop() { digital. Write(13, HIGH); delay(1000); digital. Write(13, LOW); delay(1000); } Stanford 14 University Okamura, 2013 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 Introduction to Haptics 14 material courtesy Paulo Blikstein © Allison M.

Understanding the code // Blink the pin 13 LED void setup() { pin. Mode(13, OUTPUT); } void loop() { digital. Write(13, HIGH); delay(1000); digital. Write(13, LOW); delay(1000); } Stanford 15 University Okamura, 2013 pin. Mode(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! Introduction to Haptics 15 material courtesy Paulo Blikstein © Allison M.

Understanding the code // Blink the pin 13 LED void setup() { pin. Mode(13, OUTPUT); } void loop() { digital. Write(13, HIGH); delay(1000); digital. Write(13, LOW); delay(1000); } Stanford 16 University Okamura, 2013 digital. Write(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! material courtesy Paulo Blikstein Introduction to Haptics 16 © Allison M.
- Slides: 16