00001 #include <rtt/RTT.hpp>
00002
00003 #if defined (OROPKG_OS_LXRT)
00004 #include <rtt/PeriodicActivity.hpp>
00005
00006 #include "IP_Encoder_6_EncInterface.hpp"
00007 #include "drivers/LiAS_lxrt_user.h"
00008
00009 using namespace RTT;
00010
00011 IP_Encoder_6_Task::IP_Encoder_6_Task( Seconds period )
00012 : PeriodicActivity(0, period )
00013 , _virtual_encoder_1("encoder1"), _virtual_encoder_2("encoder2"), _virtual_encoder_3("encoder3")
00014 , _virtual_encoder_4("encoder4"), _virtual_encoder_5("encoder5"), _virtual_encoder_6("encoder6")
00015 {
00016 for (unsigned int i = 0; i < 6; i++)
00017 {
00018 _virtualEncoder[i] = 0;
00019 _prevEncoderValue[i] = 0;
00020 }
00021
00022 _virtual_encoder_1.Set(_virtualEncoder[0]);
00023 _virtual_encoder_2.Set(_virtualEncoder[1]);
00024 _virtual_encoder_3.Set(_virtualEncoder[2]);
00025 _virtual_encoder_4.Set(_virtualEncoder[3]);
00026 _virtual_encoder_5.Set(_virtualEncoder[4]);
00027 _virtual_encoder_6.Set(_virtualEncoder[5]);
00028 }
00029
00030
00031
00032 bool IP_Encoder_6_Task::initialize()
00033 {
00034
00035 for (unsigned int i = 0; i< 6; i++)
00036 {
00037
00038 _prevEncoderValue[i] = IP_Encoder_6_get_counter_channel( i+1 );
00039
00040
00041 if (_prevEncoderValue[i] == 0xffff) _prevEncoderValue[i] = IP_Encoder_6_get_counter_channel( i+1 );
00042 }
00043
00044 return true;
00045 }
00046
00047
00048
00049 void IP_Encoder_6_Task::step()
00050 {
00051 #if TEST_ENCODERS
00052 static int counter(0);
00053 counter++;
00054 if (counter == 100)
00055 {
00056 printf("Encoder: [%ld %ld %ld %ld %ld %ld ] ticks\n", _virtualEncoder[0], _virtualEncoder[1], _virtualEncoder[2],
00057 _virtualEncoder[3], _virtualEncoder[4], _virtualEncoder[5]);
00058 counter = 0;
00059 }
00060 #endif
00061 for (unsigned int i = 0; i< 6; i++)
00062 {
00063
00064 unsigned short curPos = IP_Encoder_6_get_counter_channel( i+1 );
00065
00066
00067 if (curPos == 0xffff) curPos = IP_Encoder_6_get_counter_channel( i+1 );
00068
00069
00070 int delta = (int) curPos - (int)_prevEncoderValue[i];
00071
00072
00073
00074 if (delta > 32768) delta -= 65536;
00075 if (delta < -32768) delta += 65536;
00076
00077
00078 _prevEncoderValue[i] = curPos;
00079
00080 _virtualEncoder[i] += delta;
00081 }
00082
00083 _virtual_encoder_1.Set(_virtualEncoder[0]);
00084 _virtual_encoder_2.Set(_virtualEncoder[1]);
00085 _virtual_encoder_3.Set(_virtualEncoder[2]);
00086 _virtual_encoder_4.Set(_virtualEncoder[3]);
00087 _virtual_encoder_5.Set(_virtualEncoder[4]);
00088 _virtual_encoder_6.Set(_virtualEncoder[5]);
00089 }
00090
00091
00092
00093 void IP_Encoder_6_Task::positionSet(unsigned int encoderNr, int pos)
00094 {
00095
00096 _virtualEncoder[encoderNr] = pos;
00097
00098 _prevEncoderValue[encoderNr] = IP_Encoder_6_get_counter_channel( encoderNr + 1 );
00099
00100 switch ( encoderNr )
00101 {
00102 case 0 : _virtual_encoder_1.Set(_virtualEncoder[0]); break;
00103 case 1 : _virtual_encoder_2.Set(_virtualEncoder[1]); break;
00104 case 2 : _virtual_encoder_3.Set(_virtualEncoder[2]); break;
00105 case 3 : _virtual_encoder_4.Set(_virtualEncoder[3]); break;
00106 case 4 : _virtual_encoder_5.Set(_virtualEncoder[4]); break;
00107 case 5 : _virtual_encoder_6.Set(_virtualEncoder[5]); break;
00108 }
00109 }
00110
00111
00112 void IP_Encoder_6_Task::turnSet(unsigned int encoderNr, int turn)
00113 {
00114
00115 }
00116
00117
00118
00119 const int IP_Encoder_6_Task::positionGet(unsigned int encoderNr) const
00120 {
00121 switch ( encoderNr )
00122 {
00123 case 0 : return _virtual_encoder_1.Get();
00124 case 1 : return _virtual_encoder_2.Get();
00125 case 2 : return _virtual_encoder_3.Get();
00126 case 3 : return _virtual_encoder_4.Get();
00127 case 4 : return _virtual_encoder_5.Get();
00128 case 5 : return _virtual_encoder_6.Get();
00129 }
00130 return 0;
00131 };
00132
00133
00134
00135 const int IP_Encoder_6_Task::turnGet(unsigned int encoderNr) const
00136 {
00137
00138 return 0;
00139 };
00140
00141
00142
00143
00144 IP_Encoder_6_EncInterface::IP_Encoder_6_EncInterface( IP_Encoder_6_Task& IP_encoder_task, const unsigned int& encoder_nr, const std::string& name )
00145 : EncoderInterface( name )
00146 {
00147 _encoder_nr = encoder_nr;
00148 _encoder_task = &IP_encoder_task;
00149 }
00150
00151
00152
00153 IP_Encoder_6_EncInterface::IP_Encoder_6_EncInterface( IP_Encoder_6_Task& IP_encoder_task, const unsigned int& encoder_nr )
00154 {
00155 _encoder_nr = encoder_nr;
00156 _encoder_task = &IP_encoder_task;
00157 }
00158
00159 #endif