WaypointPyImp.cpp
Go to the documentation of this file.00001
00002 #include "PreCompiled.h"
00003
00004
00005 #include <Base/PlacementPy.h>
00006 #include <Base/Placement.h>
00007 #include <Base/Exception.h>
00008 #include <Base/UnitsApi.h>
00009
00010 #include "Mod/Robot/App/Waypoint.h"
00011
00012
00013
00014 #include "WaypointPy.h"
00015 #include "WaypointPy.cpp"
00016
00017 using namespace Robot;
00018 using namespace Base;
00019
00020
00021 std::string WaypointPy::representation(void) const
00022 {
00023 double A,B,C;
00024
00025 std::stringstream str;
00026 getWaypointPtr()->EndPos.getRotation().getYawPitchRoll(A,B,C);
00027 str.precision(5);
00028 str << "Waypoint [";
00029 if(getWaypointPtr()->Type == Waypoint::PTP)
00030 str << "PTP ";
00031 else if(getWaypointPtr()->Type == Waypoint::LINE)
00032 str << "LIN ";
00033 else if(getWaypointPtr()->Type == Waypoint::CIRC)
00034 str << "CIRC ";
00035 else if(getWaypointPtr()->Type == Waypoint::WAIT)
00036 str << "WAIT ";
00037 else if(getWaypointPtr()->Type == Waypoint::UNDEF)
00038 str << "UNDEF ";
00039 str << getWaypointPtr()->Name;
00040 str << " (";
00041 str << getWaypointPtr()->EndPos.getPosition().x << ","<< getWaypointPtr()->EndPos.getPosition().y << "," << getWaypointPtr()->EndPos.getPosition().z;
00042 str << ";" << A << "," << B << "," << C << ")";
00043 str << "v=" << getWaypointPtr()->Velocity << " ";
00044 if(getWaypointPtr()->Cont)
00045 str << "Cont ";
00046 if(getWaypointPtr()->Tool != 0)
00047 str << "Tool" << getWaypointPtr()->Tool << " ";
00048 if(getWaypointPtr()->Base != 0)
00049 str << "Tool" << getWaypointPtr()->Base << " ";
00050 str << "]";
00051
00052 return str.str();
00053 }
00054
00055 PyObject *WaypointPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00056 {
00057
00058 return new WaypointPy(new Waypoint);
00059 }
00060
00061
00062 int WaypointPy::PyInit(PyObject* args, PyObject* kwd)
00063 {
00064 PyObject *pos;
00065 char *name="P";
00066 char *type = "PTP";
00067 PyObject *vel = 0;
00068 PyObject *acc = 0;
00069 int cont = 0;
00070 int tool=0;
00071 int base=0;
00072
00073 static char *kwlist[] = {"Pos", "type","name", "vel", "cont", "tool", "base", "acc" ,NULL};
00074
00075 if (!PyArg_ParseTupleAndKeywords(args, kwd, "O!|ssOiiiO", kwlist,
00076 &(Base::PlacementPy::Type), &pos,
00077 &type, &name, &vel, &cont, &tool, &base, &acc ))
00078 return -1;
00079
00080 Base::Placement TempPos = *static_cast<Base::PlacementPy*>(pos)->getPlacementPtr();
00081 getWaypointPtr()->EndPos = TempPos;
00082 getWaypointPtr()->Name = name;
00083 std::string typeStr(type);
00084 if(typeStr=="PTP")
00085 getWaypointPtr()->Type = Waypoint::PTP;
00086 else if(typeStr=="LIN")
00087 getWaypointPtr()->Type = Waypoint::LINE;
00088 else if(typeStr=="CIRC")
00089 getWaypointPtr()->Type = Waypoint::CIRC;
00090 else if(typeStr=="WAIT")
00091 getWaypointPtr()->Type = Waypoint::WAIT;
00092 else
00093 getWaypointPtr()->Type = Waypoint::UNDEF;
00094
00095 if(vel == 0)
00096 switch (getWaypointPtr()->Type){
00097 case Waypoint::PTP:
00098 getWaypointPtr()->Velocity = 100;
00099 break;
00100 case Waypoint::LINE:
00101 getWaypointPtr()->Velocity = 2000;
00102 break;
00103 case Waypoint::CIRC:
00104 getWaypointPtr()->Velocity = 2000;
00105 break;
00106 default:
00107 getWaypointPtr()->Velocity = 0;
00108 }
00109 else
00110 getWaypointPtr()->Velocity = Base::UnitsApi::toDblWithUserPrefs(Base::Velocity,vel);
00111 getWaypointPtr()->Cont = cont?true:false;
00112 getWaypointPtr()->Tool = tool;
00113 getWaypointPtr()->Base = base;
00114 if(acc == 0)
00115 getWaypointPtr()->Accelaration = 100;
00116 else
00117 getWaypointPtr()->Accelaration = Base::UnitsApi::toDblWithUserPrefs(Base::Acceleration,acc);;
00118
00119 return 0;
00120 }
00121
00122
00123 Py::Float WaypointPy::getVelocity(void) const
00124 {
00125 return Py::Float(getWaypointPtr()->Velocity);
00126 }
00127
00128 void WaypointPy::setVelocity(Py::Float arg)
00129 {
00130 getWaypointPtr()->Velocity = (float) arg.operator double();
00131 }
00132
00133
00134 Py::String WaypointPy::getName(void) const
00135 {
00136 return Py::String(getWaypointPtr()->Name.c_str());
00137 }
00138
00139 void WaypointPy::setName(Py::String arg)
00140 {
00141 getWaypointPtr()->Name = arg.as_std_string();
00142 }
00143
00144 Py::String WaypointPy::getType(void) const
00145 {
00146 if(getWaypointPtr()->Type == Waypoint::PTP)
00147 return Py::String("PTP");
00148 else if(getWaypointPtr()->Type == Waypoint::LINE)
00149 return Py::String("LIN");
00150 else if(getWaypointPtr()->Type == Waypoint::CIRC)
00151 return Py::String("CIRC");
00152 else if(getWaypointPtr()->Type == Waypoint::WAIT)
00153 return Py::String("WAIT");
00154 else if(getWaypointPtr()->Type == Waypoint::UNDEF)
00155 return Py::String("UNDEF");
00156 else
00157 throw Base::Exception("Unknown waypoint type! Only: PTP,LIN,CIRC,WAIT are supported.");
00158 }
00159
00160 void WaypointPy::setType(Py::String arg)
00161 {
00162 std::string typeStr(arg.as_std_string());
00163 if(typeStr=="PTP")
00164 getWaypointPtr()->Type = Waypoint::PTP;
00165 else if(typeStr=="LIN")
00166 getWaypointPtr()->Type = Waypoint::LINE;
00167 else if(typeStr=="CIRC")
00168 getWaypointPtr()->Type = Waypoint::CIRC;
00169 else if(typeStr=="WAIT")
00170 getWaypointPtr()->Type = Waypoint::WAIT;
00171 else
00172 throw Base::Exception("Unknown waypoint type! Only: PTP,LIN,CIRC,WAIT are allowed.");
00173 }
00174
00175
00176 Py::Object WaypointPy::getPos(void) const
00177 {
00178 return Py::Object(new PlacementPy(new Placement(getWaypointPtr()->EndPos)),true);
00179 }
00180
00181 void WaypointPy::setPos(Py::Object arg)
00182 {
00183 union PyType_Object pyType = {&(Base::PlacementPy::Type)};
00184 Py::Type PlacementType(pyType.o);
00185 if(arg.isType(PlacementType))
00186 getWaypointPtr()->EndPos = *static_cast<Base::PlacementPy*>((*arg))->getPlacementPtr();
00187 }
00188
00189 Py::Boolean WaypointPy::getCont(void) const
00190 {
00191 return Py::Boolean(getWaypointPtr()->Cont);
00192 }
00193
00194 void WaypointPy::setCont(Py::Boolean arg)
00195 {
00196 getWaypointPtr()->Cont = (bool)arg;
00197 }
00198
00199 Py::Int WaypointPy::getTool(void) const
00200 {
00201 return Py::Int((int)getWaypointPtr()->Tool);
00202 }
00203
00204 void WaypointPy::setTool(Py::Int arg)
00205 {
00206 if((int)arg.operator long() > 0)
00207 getWaypointPtr()->Tool = (int)arg.operator long();
00208 else
00209 Base::Exception("negativ tool not allowed!");
00210 }
00211
00212 Py::Int WaypointPy::getBase(void) const
00213 {
00214 return Py::Int((int)getWaypointPtr()->Base);
00215 }
00216
00217 void WaypointPy::setBase(Py::Int arg)
00218 {
00219 if((int)arg.operator long() > 0)
00220 getWaypointPtr()->Base = (int)arg.operator long();
00221 else
00222 Base::Exception("negativ base not allowed!");
00223 }
00224
00225 PyObject *WaypointPy::getCustomAttributes(const char* ) const
00226 {
00227 return 0;
00228 }
00229
00230 int WaypointPy::setCustomAttributes(const char* , PyObject* )
00231 {
00232 return 0;
00233 }
00234
00235