haptic_rendering_funx.h
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
34 #ifndef _HAPTIC_RENDERING_FUNX_H
35 #define _HAPTIC_RENDERING_FUNX_H
36 
37 /*~~~~~~~~~~~~~~~~~
38 || OpenHaptics 3 ||
39 ~~~~~~~~~~~~~~~~~~*/
40 #include <HD/hd.h>
41 #include <HDU/hduVector.h>
42 #include <HDU/hduError.h>
43 #include <HL/hl.h>
44 
45 #include <phua_haptic/types.h>
47 
49 
55 hduVector3Dd CalculateWorkspaceDemoForce(void *pUserData);
56 
62 hduVector3Dd CalculatePlaneDrawingDemoForce(void *pUserData);
63 
69 void Demo2_BuildPlane(void *pUserData);
70 
76 template <typename Type>
78 {
79  // constants
80  static Type overlap = 30.0; //mm
81  static Type limit = 0.25 * overlap; //mm
82  static Type Fmax = 2.5; //N
83  static Type k = Fmax / overlap; //N/mm
84  static Type gamma = 0.2;
85  static Type k2 = 10.0;
86 
87  // calcs
88  Type F;
89 
90  if(x<overlap && x>=limit)
91  F = k * gamma * x;
92  else if(x>0.0 && x<limit)
93  {
94  Type beta = log(-(-exp(limit*3.0)+exp(limit)+Fmax*exp(limit)-exp(limit)*sqrt((exp(limit)+1.0)*(Fmax+gamma*k*limit-gamma*k*overlap)*(Fmax-exp(limit)*2.0+Fmax*exp(limit)+gamma*k*limit-gamma*k*overlap+gamma*k*limit*exp(limit)-gamma*k*overlap*exp(limit)+2.0))+Fmax*exp(limit*3.0)+exp(limit*2.0)*sqrt((exp(limit)+1.0)*(Fmax+gamma*k*limit-gamma*k*overlap)*(Fmax-exp(limit)*2.0+Fmax*exp(limit)+gamma*k*limit-gamma*k*overlap+gamma*k*limit*exp(limit)-gamma*k*overlap*exp(limit)+2.0))+gamma*k*limit*exp(limit)-gamma*k*overlap*exp(limit)+gamma*k*limit*exp(limit*3.0)-gamma*k*overlap*exp(limit*3.0))/(-exp(limit*2.0)+Fmax*exp(limit)*2.0+gamma*k*limit*exp(limit)*2.0-gamma*k*overlap*exp(limit)*2.0+1.0))*(1.0/2.0);
95 
96  Type alpha = pow(cosh(beta - (limit/2.0)),2.0);
97 
98  Type theta = Fmax + tanh(beta)/(pow(tanh(beta - (limit/2.0)),2.0)-1.0);
99 
100  F = alpha * tanh(beta - x) + theta;
101  }
102  else if(x<=0.)
103  F = Fmax + k2 * -x;
104  else
105  F = 0.;
106 
107  return F;
108 }
109 
115 hduVector3Dd Leg_COP_Monitoring(void *pUserData);
116 
122 template <typename Type>
124 {
125  // overlap zone -> define an area where haptics and control overlap
126  static Type overlap_zone = 5.0;
127 
128  // force polynomial variables
129  static Type Fmax = 3.3; // N;
130  static const Type k = Fmax / overlap_zone; // N/mm
131  static const Type k2 = 100.0*k; // N/mm
132  static Type a = 2.0 * Fmax / pow(overlap_zone,3.0);
133  static Type b = -1.0 * 3.0 * Fmax / pow(overlap_zone,2.0);
134 
135  Type F;
136 
137  if(x<=overlap_zone && x>0.0)
138  {
139  F = (a * pow(x,3.) + b * pow(x,2.) + Fmax);
140  }
141  else if(x<=0.0)
142  {
143  F = Fmax + k2 * (-x);
144  }
145  else
146  {
147  F = 0.0;
148  }
149 
150  return F;
151 }
152 
158 template <typename Type>
160 {
161  return exp(-x+1.0);
162 }
163 
169 template <typename Type>
171 {
172  return CalculateTanhForceMagnitude(x);
173 }
174 
175 #endif
176 
hduVector3Dd CalculateWorkspaceDemoForce(void *pUserData)
Function to define the workspace haptic demo force.
types.h file for this module. Contains types and structures used by the application.
hd_hl_apis_aux.h file for this module. Contains includes, prototypes and global vars.
hduVector3Dd Leg_COP_Monitoring(void *pUserData)
Function that tracks the detached leg COP and creates a force vector.
Type CalculatePolyForceMagnitude(Type x)
Function to determine force values using the polynomial force behaviour law.
Type CalculateTanhForceMagnitude(Type x)
Function to determine force values using the tanh customized force behaviour law. ...
Type CalculatePlaneForceMagnitude(Type x)
Function to determine force values of the plane in the plane drawing demo.
miscellaneous.h file for this module. Contains prototypes, includes and defines.
Type CalculateExponentialForceMagnitude(Type x)
Function to determine force values using the exponential force behaviour law.
hduVector3Dd CalculatePlaneDrawingDemoForce(void *pUserData)
Function to define the plane drawing haptic demo force.
void Demo2_BuildPlane(void *pUserData)
Function to define the plane for plane drawing demo.


phua_haptic
Author(s): Pedro Cruz
autogenerated on Mon Mar 2 2015 01:32:36