📄 ampunits_8cpp-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Copley Motion Library: AmpUnits.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.4 --><div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a></div><div class="nav"><a class="el" href="dir_000000.html">c</a></div><h1>AmpUnits.cpp</h1><a href="AmpUnits_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/************************************************************/</span><a name="l00002"></a>00002 <span class="comment">/* */</span><a name="l00003"></a>00003 <span class="comment">/* Copley Motion Libraries */</span><a name="l00004"></a>00004 <span class="comment">/* */</span><a name="l00005"></a>00005 <span class="comment">/* Author: Stephen Glow */</span><a name="l00006"></a>00006 <span class="comment">/* */</span><a name="l00007"></a>00007 <span class="comment">/* Copyright (c) 2002-2005 Copley Controls Corp. */</span><a name="l00008"></a>00008 <span class="comment">/* http://www.copleycontrols.com */</span><a name="l00009"></a>00009 <span class="comment">/* */</span><a name="l00010"></a>00010 <span class="comment">/************************************************************/</span><a name="l00011"></a>00011 <a name="l00012"></a>00012 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00013"></a>00013 <span class="comment">/** \file</span><a name="l00014"></a>00014 <span class="comment">This file contains the AMP object methods used to handle unit conversions.</span><a name="l00015"></a>00015 <span class="comment">*/</span><a name="l00016"></a>00016 <span class="comment">/***************************************************************************/</span><a name="l00017"></a>00017 <a name="l00018"></a>00018 <span class="preprocessor">#include "<a class="code" href="CML_8h.html">CML.h</a>"</span><a name="l00019"></a>00019 <a name="l00020"></a>00020 <a class="code" href="CML__Settings_8h.html#a13">CML_NAMESPACE_USE</a>();<a name="l00021"></a>00021 <a name="l00022"></a>00022 <span class="comment">// macro used for rounding floats</span><a name="l00023"></a><a class="code" href="AmpUnits_8cpp.html#a0">00023</a> <span class="preprocessor">#define Round(x) ((x>=0) ? (x+0.5) : (x-0.5))</span><a name="l00024"></a>00024 <span class="preprocessor"></span><a name="l00025"></a>00025 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00026"></a>00026 <span class="comment">/**</span><a name="l00027"></a>00027 <span class="comment">Configure the user programmable units.</span><a name="l00028"></a>00028 <span class="comment"></span><a name="l00029"></a>00029 <span class="comment">Unit conversions may be enabled or disabled at compile time through a setting</span><a name="l00030"></a>00030 <span class="comment">in CML_Settings.h. If this feature is disabled, then all position, velocity,</span><a name="l00031"></a>00031 <span class="comment">acceleration & jerk values are passed as 32-bit integers in the amplifier's </span><a name="l00032"></a>00032 <span class="comment">native units:</span><a name="l00033"></a>00033 <span class="comment"></span><a name="l00034"></a>00034 <span class="comment">- Position: Encoder counts</span><a name="l00035"></a>00035 <span class="comment">- Velocity: 0.1 encoder counts / second (i.e. 100 would be 10 counts/sec)</span><a name="l00036"></a>00036 <span class="comment">- Acceleration: 10 counts / second ^ 2 (i.e. 100 would be 1000 counts/sec^2)</span><a name="l00037"></a>00037 <span class="comment">- Jerk: 100 counts / second^3 (i.e. 100 would be 10000 counts/sec^3).</span><a name="l00038"></a>00038 <span class="comment"></span><a name="l00039"></a>00039 <span class="comment">If unit conversions are enabled in CML_Settings.h, then these values are </span><a name="l00040"></a>00040 <span class="comment">passed as double precision floating point values, and this function may be </span><a name="l00041"></a>00041 <span class="comment">used to set a scaling factor for these units. The scaling factor is</span><a name="l00042"></a>00042 <span class="comment">passed to this function as a number of encoder counts / user distance unit.</span><a name="l00043"></a>00043 <span class="comment"></span><a name="l00044"></a>00044 <span class="comment">Velocity units are always equal to distance units / second. Likewise, </span><a name="l00045"></a>00045 <span class="comment">acceleration and jerk units are distance units / second^2 and distance</span><a name="l00046"></a>00046 <span class="comment">units / second^3.</span><a name="l00047"></a>00047 <span class="comment"></span><a name="l00048"></a>00048 <span class="comment">For example, if the motor in question has a 1 micron encoder, then user units</span><a name="l00049"></a>00049 <span class="comment">of meters, meters/sec, meters/sec^2, etc can be selected by passing a value of</span><a name="l00050"></a>00050 <span class="comment">1,000,000 to this function (i.e. the number of microns/meter).</span><a name="l00051"></a>00051 <span class="comment"></span><a name="l00052"></a>00052 <span class="comment">When user units are enabled at compile time, the amplifier defaults to units of </span><a name="l00053"></a>00053 <span class="comment">encoder counts, encoder counts / second, etc.</span><a name="l00054"></a>00054 <span class="comment"></span><a name="l00055"></a>00055 <span class="comment">@param cts The number of encoder counts / user distance unit.</span><a name="l00056"></a>00056 <span class="comment">@return A pointer to an error object, or NULL on success. Note that if user</span><a name="l00057"></a>00057 <span class="comment"> units are disabled in CML_Settings.h, then this function will return</span><a name="l00058"></a>00058 <span class="comment"> an error.</span><a name="l00059"></a>00059 <span class="comment">*/</span><a name="l00060"></a>00060 <span class="comment">/***************************************************************************/</span><a name="l00061"></a><a class="code" href="classAmp.html#z15_0">00061</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classAmp.html#z15_0">Amp::SetCountsPerUnit</a>( <a class="code" href="CML__Utils_8h.html#a11">uunit</a> cts )<a name="l00062"></a>00062 {<a name="l00063"></a>00063 <span class="preprocessor">#ifdef CML_ENABLE_USER_UNITS</span><a name="l00064"></a>00064 <span class="preprocessor"></span> u2lPos = cts; l2uPos = 1.0/u2lPos;<a name="l00065"></a>00065 u2lVel = cts*10.0; l2uVel = 1.0/u2lVel;<a name="l00066"></a>00066 u2lAcc = cts*0.1; l2uAcc = 1.0/u2lAcc;<a name="l00067"></a>00067 u2lJrk = cts*0.01; l2uJrk = 1.0/u2lJrk;<a name="l00068"></a>00068 <a name="l00069"></a>00069 u2mPos = u2lPos; m2uPos = l2uPos;<a name="l00070"></a>00070 u2mVel = u2lVel; m2uVel = l2uVel;<a name="l00071"></a>00071 u2mAcc = u2lAcc; m2uAcc = l2uAcc;<a name="l00072"></a>00072 <span class="keywordflow">return</span> 0;<a name="l00073"></a>00073 <span class="preprocessor">#else</span><a name="l00074"></a>00074 <span class="preprocessor"></span> <span class="keywordflow">return</span> &<a class="code" href="classAmpError.html#s27">AmpError::NoUserUnits</a>;<a name="l00075"></a>00075 <span class="preprocessor">#endif</span><a name="l00076"></a>00076 <span class="preprocessor"></span>}<a name="l00077"></a>00077 <a name="l00078"></a>00078 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00079"></a>00079 <span class="comment">/**</span><a name="l00080"></a>00080 <span class="comment">Configure the user programmable units for a dual encoder system.</span><a name="l00081"></a>00081 <span class="comment">This method provides the same feature as the single encoder version however</span><a name="l00082"></a>00082 <span class="comment">it takes two scaling parameters; a load encoder scaler and a motor encoder</span><a name="l00083"></a>00083 <span class="comment">scaler. These two values are used to scale amplifier parameters based on</span><a name="l00084"></a>00084 <span class="comment">which encoder they refer to.</span><a name="l00085"></a>00085 <span class="comment"></span><a name="l00086"></a>00086 <span class="comment">@param load The load encoder scaling factor. This gives the number of load</span><a name="l00087"></a>00087 <span class="comment"> encoder counts / user position unit.</span><a name="l00088"></a>00088 <span class="comment">@param mtr The motor encoder scaling factor. This gives the number of motor</span><a name="l00089"></a>00089 <span class="comment"> encoder counts / user position unit.</span><a name="l00090"></a>00090 <span class="comment"> </span><a name="l00091"></a>00091 <span class="comment">@return A pointer to an error object, or NULL on success.</span><a name="l00092"></a>00092 <span class="comment">*/</span><a name="l00093"></a>00093 <span class="comment">/***************************************************************************/</span><a name="l00094"></a><a class="code" href="classAmp.html#z15_2">00094</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classAmp.html#z15_0">Amp::SetCountsPerUnit</a>( <a class="code" href="CML__Utils_8h.html#a11">uunit</a> load, <a class="code" href="CML__Utils_8h.html#a11">uunit</a> mtr )<a name="l00095"></a>00095 {<a name="l00096"></a>00096 <span class="preprocessor">#ifdef CML_ENABLE_USER_UNITS</span><a name="l00097"></a>00097 <span class="preprocessor"></span> u2lPos = load; l2uPos = 1.0/u2lPos;<a name="l00098"></a>00098 u2lVel = load* 10.0; l2uVel = 1.0/u2lVel;<a name="l00099"></a>00099 u2lAcc = load* 0.1; l2uAcc = 1.0/u2lAcc;<a name="l00100"></a>00100 u2lJrk = load* 0.01; l2uJrk = 1.0/u2lJrk;<a name="l00101"></a>00101 <a name="l00102"></a>00102 u2mPos = mtr; m2uPos = 1.0/u2mPos;<a name="l00103"></a>00103 u2mVel = mtr* 10.0; m2uVel = 1.0/u2mVel;<a name="l00104"></a>00104 u2mAcc = mtr* 0.1; m2uAcc = 1.0/u2mAcc;<a name="l00105"></a>00105 <span class="keywordflow">return</span> 0;<a name="l00106"></a>00106 <span class="preprocessor">#else</span><a name="l00107"></a>00107 <span class="preprocessor"></span> <span class="keywordflow">return</span> &<a class="code" href="classAmpError.html#s27">AmpError::NoUserUnits</a>;<a name="l00108"></a>00108 <span class="preprocessor">#endif</span><a name="l00109"></a>00109 <span class="preprocessor"></span>}<a name="l00110"></a>00110 <a name="l00111"></a>00111 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00112"></a>00112 <span class="comment">/**</span><a name="l00113"></a>00113 <span class="comment">Get the number of encoder counts / user distance unit. This function is only</span><a name="l00114"></a>00114 <span class="comment">available when user units are selected in CML_Settings.h.</span><a name="l00115"></a>00115 <span class="comment"></span><a name="l00116"></a>00116 <span class="comment">This value defaults to 1.0 (i.e. user distance units are in encoder counts).</span><a name="l00117"></a>00117 <span class="comment">It can be adjusted if some other distance unit is desired.</span><a name="l00118"></a>00118 <span class="comment"></span><a name="l00119"></a>00119 <span class="comment">This value controls velocity, acceleration, and jerk units also. These units</span><a name="l00120"></a>00120 <span class="comment">are always based on a time interval of seconds.</span><a name="l00121"></a>00121 <span class="comment"></span><a name="l00122"></a>00122 <span class="comment">@param cts The count value will be returned here</span><a name="l00123"></a>00123 <span class="comment">@return A pointer to an error object, or NULL on success</span><a name="l00124"></a>00124 <span class="comment">*/</span><a name="l00125"></a>00125 <span class="comment">/***************************************************************************/</span><a name="l00126"></a><a class="code" href="classAmp.html#z15_1">00126</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classAmp.html#z15_1">Amp::GetCountsPerUnit</a>( <a class="code" href="CML__Utils_8h.html#a11">uunit</a> &cts )<a name="l00127"></a>00127 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -