00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "WrenchSensor.hpp"
00024 #include <kdl/frames_io.hpp>
00025 #include <rtt/Logger.hpp>
00026
00027 #if defined (OROPKG_OS_LXRT)
00028 #include <hardware/wrench/drivers/jr3_lxrt_user.h>
00029 #endif
00030
00031 #define CUTOFF_FREQUENCY_FILTER1 500.0
00032 #define CUTOFF_FREQUENCY_FILTER2 125.0
00033 #define CUTOFF_FREQUENCY_FILTER3 31.25
00034 #define CUTOFF_FREQUENCY_FILTER4 7.813
00035 #define CUTOFF_FREQUENCY_FILTER5 1.953
00036 #define CUTOFF_FREQUENCY_FILTER6 0.4883
00037
00038
00039
00040 #define MAX_LOAD 12000
00041
00042 namespace OCL
00043 {
00044 using namespace RTT;
00045 using namespace std;
00046 using namespace KDL;
00047
00048 WrenchSensor::WrenchSensor(std::string name)
00049 : RTT::TaskContext(name,PreOperational),
00050 outdatPort("WrenchData"),
00051 maximumLoadEvent("maximumLoadEvent"),
00052 maxMeasurement_mtd( "maxMeasurement", &WrenchSensor::maxMeasurement, this),
00053 minMeasurement_mtd( "minMeasurement", &WrenchSensor::minMeasurement, this),
00054 zeroMeasurement_mtd( "zeroMeasurement", &WrenchSensor::zeroMeasurement, this),
00055 chooseFilter_cmd( "chooseFilter", &WrenchSensor::chooseFilter,
00056 &WrenchSensor::chooseFilterDone, this),
00057 setOffset_cmd( "setOffset", &WrenchSensor::setOffset,
00058 &WrenchSensor::setOffsetDone, this),
00059 addOffset_cmd( "addOffset", &WrenchSensor::addOffset,
00060 &WrenchSensor::setOffsetDone, this),
00061 offset("offset","Offset for zero-measurement",Wrench::Zero()),
00062 dsp_prop("dsp","connection socket, can be 0 or 1",0),
00063 filter_period_prop("filterperiod","period of filter for measurements",1.0/(2*CUTOFF_FREQUENCY_FILTER6)),
00064 filterToReadFrom(6)
00065 {
00066 this->ports()->addPort( &outdatPort );
00067 this->properties()->addProperty(&offset);
00068 this->properties()->addProperty(&dsp_prop);
00069 this->properties()->addProperty(&filter_period_prop);
00070
00074 this->methods()->addMethod( &minMeasurement_mtd, "Gets the minimum measurement value." );
00075 this->methods()->addMethod( &maxMeasurement_mtd, "Gets the maximum measurement value." );
00076 this->methods()->addMethod( &zeroMeasurement_mtd, "Gets the zero measurement value." );
00077
00078 this->commands()->addCommand( &chooseFilter_cmd, "Command to choose a different filter","p","periodValue" );
00079 this->commands()->addCommand( &setOffset_cmd, "Command to set the zero offset","o","offset wrench" );
00080 this->commands()->addCommand( &addOffset_cmd, "Command to add an offset","o","offset wrench" );
00081
00082 this->events()->addEvent(&maximumLoadEvent, "Maximum Load","message","Information about event");
00083
00084 }
00085
00086 bool WrenchSensor::configureHook()
00087 {
00088 dsp = dsp_prop.value();
00089 #if defined (OROPKG_OS_LXRT)
00090 chooseFilter(filter_period_prop.value());
00091 if(!JR3DSP_check_sensor_and_DSP(dsp)){
00092 log(Error)<<"WrenchSensor not plugged in connected!!!!"<<endlog();
00093 return false;
00094 }
00095
00096 JR3DSP_set_units(1, dsp);
00097
00098 JR3DSP_get_full_scale(&full_scale, dsp);
00099
00100 log(Info) << "WrenchSensor - Full scale: ("
00101 << (double) full_scale.Fx << ", " << (double) full_scale.Fy << ", " << (double) full_scale.Fz << ", "
00102 << (double) full_scale.Tx << ", " << (double) full_scale.Ty << ", " << (double) full_scale.Tz
00103 << ")" << endlog();
00104 #else
00105 full_scale.Fx=100;
00106 full_scale.Fy=100;
00107 full_scale.Fz=100;
00108 full_scale.Tx=100;
00109 full_scale.Ty=100;
00110 full_scale.Tz=100;
00111 #endif
00112 return true;
00113
00114 }
00115
00116
00117 Wrench WrenchSensor::maxMeasurement() const
00118 {
00119 return Wrench( Vector((double)full_scale.Fx , (double)full_scale.Fy , (double)full_scale.Fz),
00120 Vector((double)full_scale.Tx / 10, (double)full_scale.Fy / 10, (double)full_scale.Fz / 10) );
00121 }
00122
00123 Wrench WrenchSensor::minMeasurement() const
00124 {
00125 return Wrench( Vector(-(double)full_scale.Fx , -(double)full_scale.Fy , -(double)full_scale.Fz),
00126 Vector(-(double)full_scale.Tx / 10, -(double)full_scale.Fy / 10, -(double)full_scale.Fz / 10) );
00127 }
00128
00129 Wrench WrenchSensor::zeroMeasurement() const
00130 {
00131 return Wrench(Vector(0,0,0), Vector(0,0,0));
00132 }
00133
00134 bool WrenchSensor::chooseFilter(double period)
00135 {
00136 #if defined (OROPKG_OS_LXRT)
00137
00138 if ( period < 1.0/(2*CUTOFF_FREQUENCY_FILTER1)) filterToReadFrom = 1;
00139 else if ( period < 1.0/(2*CUTOFF_FREQUENCY_FILTER2)) filterToReadFrom = 2;
00140 else if ( period < 1.0/(2*CUTOFF_FREQUENCY_FILTER3)) filterToReadFrom = 3;
00141 else if ( period < 1.0/(2*CUTOFF_FREQUENCY_FILTER4)) filterToReadFrom = 4;
00142 else if ( period < 1.0/(2*CUTOFF_FREQUENCY_FILTER5)) filterToReadFrom = 5;
00143 else if ( period < 1.0/(2*CUTOFF_FREQUENCY_FILTER6)) filterToReadFrom = 6;
00144 else
00145 {
00146 log(Warning) << "(WrenchSensor) Sample to low to garantee no aliasing!" << endlog();
00147 return false;
00148 }
00149 #endif
00150 log(Info) << "WrenchSensor - ChooseFilter: " << filterToReadFrom << endlog();
00151 return true;
00152 }
00153
00154 bool WrenchSensor::chooseFilterDone() const
00155 {
00156 return true;
00157 }
00158
00159
00160 bool WrenchSensor::setOffset(Wrench off)
00161 {
00162 offset.value()=off;
00163 return true;
00164 }
00165
00166 bool WrenchSensor::addOffset(Wrench off)
00167 {
00168 offset.value()+=off;
00169 return true;
00170 }
00171
00172 bool WrenchSensor::setOffsetDone() const
00173 {
00174 return true;
00175 }
00176
00181 bool WrenchSensor::startHook() {
00182 this->update();
00183 return true;
00184 }
00185
00189 void WrenchSensor::updateHook() {
00190 #if defined (OROPKG_OS_LXRT)
00191 JR3DSP_get_data(&write_struct, filterToReadFrom, dsp);
00192
00193
00194 if ( (write_struct.Fx > MAX_LOAD) || (write_struct.Fx < -MAX_LOAD)
00195 || (write_struct.Fy > MAX_LOAD) || (write_struct.Fy < -MAX_LOAD)
00196 || (write_struct.Fz > MAX_LOAD) || (write_struct.Fz < -MAX_LOAD)
00197 || (write_struct.Tx > MAX_LOAD) || (write_struct.Tx < -MAX_LOAD)
00198 || (write_struct.Ty > MAX_LOAD) || (write_struct.Ty < -MAX_LOAD)
00199 || (write_struct.Tz > MAX_LOAD) || (write_struct.Tz < -MAX_LOAD) )
00200 maximumLoadEvent("Maximum load of wrench sensor exceeded");
00201 #else
00202 write_struct.Fx = 0;
00203 write_struct.Fy = 0;
00204 write_struct.Fz = 0;
00205 write_struct.Tx = 0;
00206 write_struct.Ty = 0;
00207 write_struct.Tz = 0;
00208 #endif
00209
00210
00211
00212
00213
00214 writeBuffer(0) = (double)write_struct.Fx * (double) full_scale.Fx / 16384.0;
00215 writeBuffer(1) = - (double)write_struct.Fy * (double) full_scale.Fy / 16384.0;
00216 writeBuffer(2) = (double)write_struct.Fz * (double) full_scale.Fz / 16384.0;
00217
00218 writeBuffer(3) = (double)write_struct.Tx * (double) full_scale.Tx / 16384.0 / 10;
00219 writeBuffer(4) = - (double)write_struct.Ty * (double) full_scale.Ty / 16384.0 / 10;
00220 writeBuffer(5) = (double)write_struct.Tz * (double) full_scale.Tz / 16384.0 / 10;
00221
00222 outdatPort.Set( writeBuffer - offset.value() );
00223 }
00224
00228 void WrenchSensor::stopHook() {
00229 marshalling()->writeProperties(this->getName()+".cpf");
00230 }
00231
00232 }
00233
00234
00235
00236