Waypoint.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #ifndef _PreComp_
00027 #endif
00028
00029 #include <Base/Writer.h>
00030 #include <Base/Reader.h>
00031
00032 #include "kdl_cp/chain.hpp"
00033 #include "kdl_cp/chainfksolver.hpp"
00034 #include "kdl_cp/chainfksolverpos_recursive.hpp"
00035 #include "kdl_cp/frames_io.hpp"
00036 #include "kdl_cp/chainiksolver.hpp"
00037 #include "kdl_cp/chainiksolvervel_pinv.hpp"
00038 #include "kdl_cp/chainjnttojacsolver.hpp"
00039 #include "kdl_cp/chainiksolverpos_nr.hpp"
00040
00041 #include "Waypoint.h"
00042
00043 #ifndef M_PI
00044 #define M_PI 3.14159265358979323846
00045 #define M_PI 3.14159265358979323846
00046 #endif
00047
00048 #ifndef M_PI_2
00049 #define M_PI_2 1.57079632679489661923
00050 #endif
00051
00052 using namespace Robot;
00053 using namespace Base;
00054 using namespace KDL;
00055
00056
00057 TYPESYSTEM_SOURCE(Robot::Waypoint , Base::Persistence);
00058
00059 Waypoint::Waypoint( const char* name,
00060 const Base::Placement &endPos,
00061 WaypointType type,
00062 float velocity,
00063 float accelaration,
00064 bool cont,
00065 unsigned int tool,
00066 unsigned int base)
00067
00068 :Name(name),Type(type),Velocity(velocity),Accelaration(accelaration),Cont(cont),Tool(tool),Base(base),EndPos(endPos)
00069 {
00070 }
00071
00072 Waypoint::Waypoint()
00073 :Velocity(1000.0),Accelaration(100.0),Cont(false),Tool(0),Base(0)
00074 {
00075 }
00076
00077 Waypoint::~Waypoint()
00078 {
00079 }
00080
00081 unsigned int Waypoint::getMemSize (void) const
00082 {
00083 return 0;
00084 }
00085
00086 void Waypoint::Save (Writer &writer) const
00087 {
00088 writer.Stream() << writer.ind() << "<Waypoint "
00089 << "name=\"" << Name << "\" "
00090 << "Px=\"" << EndPos.getPosition().x << "\" "
00091 << "Py=\"" << EndPos.getPosition().y << "\" "
00092 << "Pz=\"" << EndPos.getPosition().z << "\" "
00093 << "Q0=\"" << EndPos.getRotation()[0] << "\" "
00094 << "Q1=\"" << EndPos.getRotation()[1] << "\" "
00095 << "Q2=\"" << EndPos.getRotation()[2] << "\" "
00096 << "Q3=\"" << EndPos.getRotation()[3] << "\" "
00097 << "vel=\"" << Velocity << "\" "
00098 << "acc=\"" << Accelaration << "\" "
00099 << "cont=\"" << int((Cont)?1:0) << "\" "
00100 << "tool=\"" << Tool << "\" "
00101 << "base=\"" << Base << "\" ";
00102 if(Type == Waypoint::PTP)
00103 writer.Stream() << " type=\"PTP\"/> ";
00104 else if(Type == Waypoint::LINE)
00105 writer.Stream() << " type=\"LIN\"/> ";
00106 else if(Type == Waypoint::CIRC)
00107 writer.Stream() << " type=\"CIRC\"/> ";
00108 else if(Type == Waypoint::WAIT)
00109 writer.Stream() << " type=\"WAIT\"/> ";
00110 else if(Type == Waypoint::UNDEF)
00111 writer.Stream() << " type=\"UNDEF\"/> ";
00112 writer.Stream()<< std::endl;
00113 }
00114
00115 void Waypoint::Restore(XMLReader &reader)
00116 {
00117
00118 reader.readElement("Waypoint");
00119 Name = reader.getAttribute("name");
00120
00121 EndPos = Base::Placement(Base::Vector3d(reader.getAttributeAsFloat("Px"),
00122 reader.getAttributeAsFloat("Py"),
00123 reader.getAttributeAsFloat("Pz")),
00124 Base::Rotation(reader.getAttributeAsFloat("Q0"),
00125 reader.getAttributeAsFloat("Q1"),
00126 reader.getAttributeAsFloat("Q2"),
00127 reader.getAttributeAsFloat("Q3")));
00128
00129 Velocity = (float) reader.getAttributeAsFloat("vel");
00130 Accelaration = (float) reader.getAttributeAsFloat("acc");
00131 Cont = (reader.getAttributeAsInteger("cont") != 0)?true:false;
00132 Tool = reader.getAttributeAsInteger("tool");
00133 Base = reader.getAttributeAsInteger("base");
00134
00135 std::string type = reader.getAttribute("type");
00136 if(type=="PTP")
00137 Type = Waypoint::PTP;
00138 else if(type=="LIN")
00139 Type = Waypoint::LINE;
00140 else if(type=="CIRC")
00141 Type = Waypoint::CIRC;
00142 else if(type=="WAIT")
00143 Type = Waypoint::WAIT;
00144 else
00145 Type = Waypoint::UNDEF;
00146
00147
00148 }
00149