| 1 | |
|---|
| 2 | <!DOCTYPE html |
|---|
| 3 | PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
|---|
| 4 | <html><head> |
|---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
|---|
| 6 | <!-- |
|---|
| 7 | This HTML is auto-generated from an M-file. |
|---|
| 8 | To make changes, update the M-file and republish this document. |
|---|
| 9 | --><title>CalibrateGyro</title><meta name="generator" content="MATLAB 7.9"><meta name="date" content="2009-10-07"><meta name="m-file" content="script_CalibrateGyro"> |
|---|
| 10 | <link type="text/css" rel="stylesheet" href="../../style.css"> |
|---|
| 11 | </head><body><div class="content"><h1>CalibrateGyro</h1><!--introduction--><p>Calibrates the HiTechnic Gyro sensor (measures/sets an offset while in rest)</p><!--/introduction--><h2>Contents</h2><div><ul><li><a href="#2">Syntax</a></li><li><a href="#7">Description</a></li><li><a href="#18">Examples</a></li><li><a href="#22">See also</a></li><li><a href="#24">Signature</a></li></ul></div><h2>Syntax<a name="2"></a></h2><p><tt>offset = CalibrateGyro(port, 'AUTO')</tt></p><p><tt>offset = CalibrateGyro(port, 'AUTO', handle)</tt></p><p><tt>offset = CalibrateGyro(port, 'MANUAL', manualOffset)</tt></p><p><tt>offset = CalibrateGyro(port, 'MANUAL', manualOffset, handle)</tt></p><h2>Description<a name="7"></a></h2><p>In order to use the HiTechnic Gyro Sensor, it has first to be opened using <tt>OpenGyro</tt>. Then <tt>CalibrateGyro</tt> should be called (or a warning will be issued). Only after this you can safely use <tt>GetGyro</tt> to retrieve values.</p><p>This function will set (and return) the new offset (i.e. reading during reast) of the according Gyro sensor. Normally users should use the</p><p><b>automatic</b> calibration mode: <tt>offset = CalibrateGyro(port, 'AUTO')</tt></p><p>The offset will be calculated automatically. During this function the Gyro sensor value will be measured for at least 1 second (or for at least 5 times). During this period, the sensor must be at full rest!</p><p>If you want to save time during your program with a well-known Gyro sensor, or you cannot assure that the sensor is at rest during calibration, you can use the automatic calibration once in the command line and remember the determined offset value. Using manual calibration, you can then set a hardcoded value manually (saving you time and the calibration for this sensor in the future in that specific program).</p><p>Use <tt>CalibrateGyro(port, 'MANUAL', manualOffset)</tt> to achieve this, with a correct offset obtained from automatic calibration. This call won't require that the sensor doesn't move. Also the call is very fast (as compared to at least 1 second in automatic mode). Use integers for <tt>manualOffset</tt>, as the gyro sensor is only accurate to +/- 1 degree per second anyway.</p><p>The last optional argument (for both modes) can be a valid NXT handle. If none is specified, the default handle will be used (call <tt>COM_SetDefaultNXT</tt> to set one).</p><p><b>Note:</b></p><p>Manual calibration only works for one specific sensor (i.e. one unique piece of hardware). Other sensors might have different offsets. Also it could be possible that the offset changes over time or is dependent on your working environment (humidity, temperature, etc).</p><h2>Examples<a name="18"></a></h2><pre class="codeinput"> <span class="comment">% in this example the gyro is used with automatic</span> |
|---|
| 12 | <span class="comment">% calibration, very straight forward</span> |
|---|
| 13 | |
|---|
| 14 | port = SENSOR_2; |
|---|
| 15 | OpenGyro(port); |
|---|
| 16 | CalibrateGyro(port, <span class="string">'AUTO'</span>); |
|---|
| 17 | |
|---|
| 18 | <span class="comment">% now the gyro is ready to be used!</span> |
|---|
| 19 | <span class="comment">% do something, main program etc...</span> |
|---|
| 20 | speed = GetGyro(port); |
|---|
| 21 | |
|---|
| 22 | <span class="comment">% do something else, loop etc...</span> |
|---|
| 23 | <span class="comment">% don't forget to clean up</span> |
|---|
| 24 | CloseSensor(port); |
|---|
| 25 | </pre><pre class="codeinput"> <span class="comment">% in this example we save the time and effort of</span> |
|---|
| 26 | <span class="comment">% automatic calibration each time the main program is run...</span> |
|---|
| 27 | <span class="comment">% on a command window, type:</span> |
|---|
| 28 | h = COM_OpenNXT(); |
|---|
| 29 | COM_SetDefaulNXT(h); |
|---|
| 30 | OpenGyro(SENSOR_1); |
|---|
| 31 | <span class="comment">% now, once the automatic calibration:</span> |
|---|
| 32 | offset = CalibrateGyro(SENSOR_1, <span class="string">'AUTO'</span>); |
|---|
| 33 | <span class="comment">% remember this value...</span> |
|---|
| 34 | </pre><pre class="codeinput"> <span class="comment">% our main program looks like this:</span> |
|---|
| 35 | <span class="comment">% always open gyro first:</span> |
|---|
| 36 | OpenGyro(SENSOR_1); |
|---|
| 37 | <span class="comment">% now use the offset value determined earlier:</span> |
|---|
| 38 | CalibrateGyro(SENSOR_1, <span class="string">'MANUAL'</span>, offset); |
|---|
| 39 | <span class="comment">% ready to use GetGyro now...</span> |
|---|
| 40 | </pre><h2>See also<a name="22"></a></h2><p>OpenGyro, GetGyro, CloseSensor, NXT_SetInputMode, NXT_GetInputValues</p><h2>Signature<a name="24"></a></h2><div><ul><li><b>Author:</b> Linus Atorf (see AUTHORS)</li><li><b>Date:</b> 2009/04/14</li><li><b>Copyright:</b> 2007-2009, RWTH Aachen University</li></ul></div><p class="footer"><br> |
|---|
| 41 | </p></div><!-- |
|---|
| 42 | ##### SOURCE BEGIN ##### |
|---|
| 43 | %% CalibrateGyro |
|---|
| 44 | % Calibrates the HiTechnic Gyro sensor (measures/sets an offset while in rest) |
|---|
| 45 | %% |
|---|
| 46 | %% Syntax |
|---|
| 47 | % |offset = CalibrateGyro(port, 'AUTO')| |
|---|
| 48 | %% |
|---|
| 49 | % |offset = CalibrateGyro(port, 'AUTO', handle)| |
|---|
| 50 | %% |
|---|
| 51 | % |offset = CalibrateGyro(port, 'MANUAL', manualOffset)| |
|---|
| 52 | %% |
|---|
| 53 | % |offset = CalibrateGyro(port, 'MANUAL', manualOffset, handle)| |
|---|
| 54 | %% |
|---|
| 55 | %% Description |
|---|
| 56 | % In order to use the HiTechnic Gyro Sensor, it has first to be opened |
|---|
| 57 | % using |OpenGyro|. Then |CalibrateGyro| should be called (or a warning |
|---|
| 58 | % will be issued). Only after this you can safely use |GetGyro| to |
|---|
| 59 | % retrieve values. |
|---|
| 60 | %% |
|---|
| 61 | % This function will set (and return) the new offset (i.e. reading during |
|---|
| 62 | % reast) of the according Gyro sensor. Normally users should use the |
|---|
| 63 | %% |
|---|
| 64 | % *automatic* calibration mode: |offset = CalibrateGyro(port, 'AUTO')| |
|---|
| 65 | %% |
|---|
| 66 | % The offset will be calculated automatically. During this function the Gyro sensor |
|---|
| 67 | % value will be measured for at least 1 second (or for at least 5 times). During this |
|---|
| 68 | % period, the sensor must be at full rest! |
|---|
| 69 | %% |
|---|
| 70 | % If you want to save time during your program with a well-known Gyro |
|---|
| 71 | % sensor, or you cannot assure that the sensor is at rest during |
|---|
| 72 | % calibration, you can use the automatic calibration once in the command |
|---|
| 73 | % line and remember the determined offset value. Using manual |
|---|
| 74 | % calibration, you can then set a hardcoded value manually (saving you |
|---|
| 75 | % time and the calibration for this sensor in the future in that specific |
|---|
| 76 | % program). |
|---|
| 77 | %% |
|---|
| 78 | % Use |CalibrateGyro(port, 'MANUAL', manualOffset)| to achieve this, with |
|---|
| 79 | % a correct offset obtained from automatic calibration. This call won't |
|---|
| 80 | % require that the sensor doesn't move. Also the call is very fast (as |
|---|
| 81 | % compared to at least 1 second in automatic mode). Use integers for |
|---|
| 82 | % |manualOffset|, as the gyro sensor is only accurate to +/- 1 degree per |
|---|
| 83 | % second anyway. |
|---|
| 84 | %% |
|---|
| 85 | % The last optional argument (for both modes) can be a valid NXT handle. If none is |
|---|
| 86 | % specified, the default handle will be used (call |COM_SetDefaultNXT| to |
|---|
| 87 | % set one). |
|---|
| 88 | %% |
|---|
| 89 | %% |
|---|
| 90 | % *Note:* |
|---|
| 91 | %% |
|---|
| 92 | % Manual calibration only works for one specific sensor (i.e. one unique |
|---|
| 93 | % piece of hardware). Other sensors might have different offsets. Also it |
|---|
| 94 | % could be possible that the offset changes over time or is dependent on |
|---|
| 95 | % your working environment (humidity, temperature, etc). |
|---|
| 96 | %% |
|---|
| 97 | %% Examples |
|---|
| 98 | % in this example the gyro is used with automatic |
|---|
| 99 | % calibration, very straight forward |
|---|
| 100 | |
|---|
| 101 | port = SENSOR_2; |
|---|
| 102 | OpenGyro(port); |
|---|
| 103 | CalibrateGyro(port, 'AUTO'); |
|---|
| 104 | |
|---|
| 105 | % now the gyro is ready to be used! |
|---|
| 106 | % do something, main program etc... |
|---|
| 107 | speed = GetGyro(port); |
|---|
| 108 | |
|---|
| 109 | % do something else, loop etc... |
|---|
| 110 | % don't forget to clean up |
|---|
| 111 | CloseSensor(port); |
|---|
| 112 | %% |
|---|
| 113 | % in this example we save the time and effort of |
|---|
| 114 | % automatic calibration each time the main program is run... |
|---|
| 115 | % on a command window, type: |
|---|
| 116 | h = COM_OpenNXT(); |
|---|
| 117 | COM_SetDefaulNXT(h); |
|---|
| 118 | OpenGyro(SENSOR_1); |
|---|
| 119 | % now, once the automatic calibration: |
|---|
| 120 | offset = CalibrateGyro(SENSOR_1, 'AUTO'); |
|---|
| 121 | % remember this value... |
|---|
| 122 | %% |
|---|
| 123 | % our main program looks like this: |
|---|
| 124 | % always open gyro first: |
|---|
| 125 | OpenGyro(SENSOR_1); |
|---|
| 126 | % now use the offset value determined earlier: |
|---|
| 127 | CalibrateGyro(SENSOR_1, 'MANUAL', offset); |
|---|
| 128 | % ready to use GetGyro now... |
|---|
| 129 | %% |
|---|
| 130 | %% See also |
|---|
| 131 | % OpenGyro, GetGyro, CloseSensor, NXT_SetInputMode, NXT_GetInputValues |
|---|
| 132 | %% |
|---|
| 133 | %% Signature |
|---|
| 134 | %% |
|---|
| 135 | % * *Author:* Linus Atorf (see AUTHORS) |
|---|
| 136 | % * *Date:* 2009/04/14 |
|---|
| 137 | % * *Copyright:* 2007-2009, RWTH Aachen University |
|---|
| 138 | % |
|---|
| 139 | |
|---|
| 140 | ##### SOURCE END ##### |
|---|
| 141 | --></body></html> |
|---|