📄 amppvt_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: AmpPVT.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>AmpPVT.cpp</h1><a href="AmpPVT_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 <span class="comment"></span><a name="l00012"></a>00012 <span class="comment">/** \file</span><a name="l00013"></a>00013 <span class="comment"> This file contains the code used by the Amp object</span><a name="l00014"></a>00014 <span class="comment"> to stream PVT trajectory profiles over the CANopen </span><a name="l00015"></a>00015 <span class="comment"> network.</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">/**************************************************</span><a name="l00023"></a>00023 <span class="comment"> * PVT buffer errors</span><a name="l00024"></a>00024 <span class="comment"> **************************************************/</span><a name="l00025"></a><a class="code" href="AmpPVT_8cpp.html#a0">00025</a> <span class="preprocessor">#define PVTERR_SEQUENCE 0x01</span><a name="l00026"></a><a class="code" href="AmpPVT_8cpp.html#a1">00026</a> <span class="preprocessor"></span><span class="preprocessor">#define PVTERR_OVERFLOW 0x02</span><a name="l00027"></a><a class="code" href="AmpPVT_8cpp.html#a2">00027</a> <span class="preprocessor"></span><span class="preprocessor">#define PVTERR_UNDERFLOW 0x04</span><a name="l00028"></a>00028 <span class="preprocessor"></span><a name="l00029"></a>00029 <span class="comment">/**************************************************</span><a name="l00030"></a>00030 <span class="comment"> * PVT buffer status bit mapping</span><a name="l00031"></a>00031 <span class="comment"> **************************************************/</span><a name="l00032"></a><a class="code" href="AmpPVT_8cpp.html#a3">00032</a> <span class="preprocessor">#define PVTSTAT_NEXTID 0x0000FFFF</span><a name="l00033"></a><a class="code" href="AmpPVT_8cpp.html#a4">00033</a> <span class="preprocessor"></span><span class="preprocessor">#define PVTSTAT_FREECT 0x00FF0000</span><a name="l00034"></a><a class="code" href="AmpPVT_8cpp.html#a5">00034</a> <span class="preprocessor"></span><span class="preprocessor">#define PVTSTAT_ERROR 0x7F000000</span><a name="l00035"></a><a class="code" href="AmpPVT_8cpp.html#a6">00035</a> <span class="preprocessor"></span><span class="preprocessor">#define PVTSTAT_EMPTY 0x80000000</span><a name="l00036"></a>00036 <span class="preprocessor"></span><a name="l00037"></a>00037 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00038"></a>00038 <span class="comment">/**</span><a name="l00039"></a>00039 <span class="comment"> Format a PVT trajectory segment. The position, velocity and time information</span><a name="l00040"></a>00040 <span class="comment"> passed to the function are organized into the proper format and stored in the</span><a name="l00041"></a>00041 <span class="comment"> passed buffer. The buffer is assumed to be at least 8 bytes long.</span><a name="l00042"></a>00042 <span class="comment"></span><a name="l00043"></a>00043 <span class="comment"> @param pos Position at start of segment (encoder counts)</span><a name="l00044"></a>00044 <span class="comment"> @param vel Velocity at start of segment (0.1 counts/sec)</span><a name="l00045"></a>00045 <span class="comment"> @param time Time till next segment (milliseconds)</span><a name="l00046"></a>00046 <span class="comment"> @param buff Points to the buffer where the message will be stored.</span><a name="l00047"></a>00047 <span class="comment"> @return An error object</span><a name="l00048"></a>00048 <span class="comment"> */</span><a name="l00049"></a>00049 <span class="comment">/***************************************************************************/</span><a name="l00050"></a><a class="code" href="classAmp.html#b5">00050</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classAmp.html#b5">Amp::FormatPvtSeg</a>( <a class="code" href="CML__Utils_8h.html#a9">int32</a> pos, <a class="code" href="CML__Utils_8h.html#a9">int32</a> vel, <a class="code" href="CML__Utils_8h.html#a6">uint8</a> time, <a class="code" href="CML__Utils_8h.html#a6">uint8</a> *buff )<a name="l00051"></a>00051 {<a name="l00052"></a>00052 <a class="code" href="CML_8h.html#a0">cml</a>.<a class="code" href="classCopleyMotionLibrary.html#a8">Debug</a>( <span class="stringliteral">"Amp %d PVT Segment: %-10ld %-10ld %3d\n"</span>, <a class="code" href="classNode.html#a38">GetNodeID</a>(), pos, vel, time );<a name="l00053"></a>00053 <a name="l00054"></a>00054 <span class="comment">// Save the lowest 3 bits of the segment ID. This allows the</span><a name="l00055"></a>00055 <span class="comment">// amplifier to identify missing profile segments.</span><a name="l00056"></a>00056 buff[0] = 7 & pvtSegID;<a name="l00057"></a>00057 <a name="l00058"></a>00058 <span class="comment">// If position is more then 24 bits then we will have to send a </span><a name="l00059"></a>00059 <span class="comment">// relative move segment. I'll just find the difference between </span><a name="l00060"></a>00060 <span class="comment">// this position and the last one sent.</span><a name="l00061"></a>00061 <span class="keywordflow">if</span>( pos > 0x007FFFFF || -pos > 0x007FFFFF )<a name="l00062"></a>00062 {<a name="l00063"></a>00063 pos -= pvtLastPos;<a name="l00064"></a>00064 <a name="l00065"></a>00065 <span class="comment">// if the result is still more then 24 bits, return an error</span><a name="l00066"></a>00066 <span class="keywordflow">if</span>( pos > 0x007FFFFF || -pos > 0x007FFFFF )<a name="l00067"></a>00067 <span class="keywordflow">return</span> &<a class="code" href="classAmpError.html#s10">AmpError::pvtSegPos</a>;<a name="l00068"></a>00068 <a name="l00069"></a>00069 <span class="comment">// mark the segment as relative</span><a name="l00070"></a>00070 buff[0] |= 0x10;<a name="l00071"></a>00071 }<a name="l00072"></a>00072 <a name="l00073"></a>00073 <span class="comment">// If velocity is more then 24-bits, send it in lower resolution</span><a name="l00074"></a>00074 <span class="keywordflow">if</span>( vel > 0x007FFFFF )<a name="l00075"></a>00075 {<a name="l00076"></a>00076 vel = (vel+50)/100;<a name="l00077"></a>00077 buff[0] |= 0x08;<a name="l00078"></a>00078 <a name="l00079"></a>00079 <span class="keywordflow">if</span>( vel > 0x007FFFFF )<a name="l00080"></a>00080 <span class="keywordflow">return</span> &<a class="code" href="classAmpError.html#s11">AmpError::pvtSegVel</a>;<a name="l00081"></a>00081 }<a name="l00082"></a>00082 <span class="keywordflow">else</span> <span class="keywordflow">if</span>( -vel > 0x007FFFFF )<a name="l00083"></a>00083 {<a name="l00084"></a>00084 vel = (vel-50)/100;<a name="l00085"></a>00085 buff[0] |= 0x08;<a name="l00086"></a>00086 <a name="l00087"></a>00087 <span class="keywordflow">if</span>( -vel > 0x007FFFFF )<a name="l00088"></a>00088 <span class="keywordflow">return</span> &<a class="code" href="classAmpError.html#s11">AmpError::pvtSegVel</a>;<a name="l00089"></a>00089 }<a name="l00090"></a>00090 <a name="l00091"></a>00091 <span class="comment">// Format the message and return </span><a name="l00092"></a>00092 buff[1] = time;<a name="l00093"></a>00093 buff[2] = pos;<a name="l00094"></a>00094 buff[3] = pos>>8;<a name="l00095"></a>00095 buff[4] = pos>>16;<a name="l00096"></a>00096 buff[5] = vel;<a name="l00097"></a>00097 buff[6] = vel>>8;<a name="l00098"></a>00098 buff[7] = vel>>16;<a name="l00099"></a>00099 <a name="l00100"></a>00100 <span class="keywordflow">return</span> 0;<a name="l00101"></a>00101 }<a name="l00102"></a>00102 <a name="l00103"></a>00103 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00104"></a>00104 <span class="comment">/**</span><a name="l00105"></a>00105 <span class="comment"> Format a PT trajectory segment. The position and time information</span><a name="l00106"></a>00106 <span class="comment"> passed to the function are organized into the proper format and stored in the</span><a name="l00107"></a>00107 <span class="comment"> passed buffer. The buffer is assumed to be at least 8 bytes long.</span><a name="l00108"></a>00108 <span class="comment"></span><a name="l00109"></a>00109 <span class="comment"> @param pos Position at start of segment (encoder counts)</span><a name="l00110"></a>00110 <span class="comment"> @param time Time till next segment (milliseconds)</span><a name="l00111"></a>00111 <span class="comment"> @param buff Points to the buffer where the message will be stored.</span><a name="l00112"></a>00112 <span class="comment"> @return An error object</span><a name="l00113"></a>00113 <span class="comment"> */</span><a name="l00114"></a>00114 <span class="comment">/***************************************************************************/</span><a name="l00115"></a><a class="code" href="classAmp.html#b6">00115</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classAmp.html#b6">Amp::FormatPtSeg</a>( <a class="code" href="CML__Utils_8h.html#a9">int32</a> pos, <a class="code" href="CML__Utils_8h.html#a6">uint8</a> time, <a class="code" href="CML__Utils_8h.html#a6">uint8</a> *buff )<a name="l00116"></a>00116 {<a name="l00117"></a>00117 <a class="code" href="CML_8h.html#a0">cml</a>.<a class="code" href="classCopleyMotionLibrary.html#a8">Debug</a>( <span class="stringliteral">"Amp %d PT Segment: %-10ld %3d\n"</span>, <a class="code" href="classNode.html#a38">GetNodeID</a>(), pos, time );<a name="l00118"></a>00118 <a name="l00119"></a>00119 <span class="comment">// Save the lowest 3 bits of the segment ID. This allows the</span><a name="l00120"></a>00120 <span class="comment">// amplifier to identify missing profile segments.</span><a name="l00121"></a>00121 buff[0] = 7 & pvtSegID;<a name="l00122"></a>00122 <a name="l00123"></a>00123 <span class="comment">// PT points are always passed using buffer format code 5</span><a name="l00124"></a>00124 buff[0] |= (5<<3);<a name="l00125"></a>00125 <a name="l00126"></a>00126 <span class="comment">// Format the message and return </span><a name="l00127"></a>00127 buff[1] = time;<a name="l00128"></a>00128 buff[2] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(pos);<a name="l00129"></a>00129 buff[3] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(pos>>8);<a name="l00130"></a>00130 buff[4] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(pos>>16);<a name="l00131"></a>00131 buff[5] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(pos>>24);<a name="l00132"></a>00132 <a name="l00133"></a>00133 <span class="keywordflow">return</span> 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -