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 "RobotObject.h"
00030 #include <App/DocumentObjectPy.h>
00031 #include <Base/Placement.h>
00032
00033 #include <Base/Writer.h>
00034 #include <Base/Reader.h>
00035
00036 using namespace Robot;
00037 using namespace App;
00038
00039 PROPERTY_SOURCE(Robot::RobotObject, App::GeoFeature)
00040
00041
00042 RobotObject::RobotObject()
00043 :block(false)
00044 {
00045 ADD_PROPERTY_TYPE(RobotVrmlFile ,(0),"Robot definition" ,Prop_None,"Included file with the VRML representation of the robot");
00046 ADD_PROPERTY_TYPE(RobotKinematicFile,(0),"Robot definition",Prop_None,"Included file with kinematic definition of the robot Axis");
00047
00048 ADD_PROPERTY_TYPE(Axis1,(0.0),"Robot kinematic",Prop_None,"Axis 1 angle of the robot in degre");
00049 ADD_PROPERTY_TYPE(Axis2,(0.0),"Robot kinematic",Prop_None,"Axis 2 angle of the robot in degre");
00050 ADD_PROPERTY_TYPE(Axis3,(0.0),"Robot kinematic",Prop_None,"Axis 3 angle of the robot in degre");
00051 ADD_PROPERTY_TYPE(Axis4,(0.0),"Robot kinematic",Prop_None,"Axis 4 angle of the robot in degre");
00052 ADD_PROPERTY_TYPE(Axis5,(0.0),"Robot kinematic",Prop_None,"Axis 5 angle of the robot in degre");
00053 ADD_PROPERTY_TYPE(Axis6,(0.0),"Robot kinematic",Prop_None,"Axis 6 angle of the robot in degre");
00054 ADD_PROPERTY_TYPE(Error,("") ,"Robot kinematic",Prop_None,"Robot error while moving");
00055
00056 ADD_PROPERTY_TYPE(Tcp,(Base::Placement()),"Robot kinematic",Prop_None,"Tcp of the robot");
00057 ADD_PROPERTY_TYPE(Base,(Base::Placement()),"Robot kinematic",Prop_None,"Actuall base frame of the robot");
00058 ADD_PROPERTY_TYPE(Tool,(Base::Placement()),"Robot kinematic",Prop_None,"Tool frame of the robot (Tool)");
00059 ADD_PROPERTY_TYPE(ToolShape,(0),"Robot definition",Prop_None,"Link to the Shape is used as Tool");
00060 ADD_PROPERTY_TYPE(ToolBase ,(Base::Placement()),"Robot definition",Prop_None,"Defines where to connect the ToolShape");
00061
00062 ADD_PROPERTY_TYPE(Home ,(0),"Robot kinematic",Prop_None,"Axis position for home");
00063
00064 }
00065
00066 RobotObject::~RobotObject()
00067 {
00068 }
00069
00070 short RobotObject::mustExecute(void) const
00071 {
00072 return 0;
00073 }
00074
00075 PyObject *RobotObject::getPyObject()
00076 {
00077 if (PythonObject.is(Py::_None())){
00078
00079 PythonObject = Py::Object(new DocumentObjectPy(this),true);
00080 }
00081 return Py::new_reference_to(PythonObject);
00082 }
00083
00084
00085 void RobotObject::onChanged(const Property* prop)
00086 {
00087
00088 if(prop == &RobotKinematicFile){
00089
00090 robot.readKinematic(RobotKinematicFile.getValue());
00091 }
00092
00093 if(prop == &Axis1 && !block){
00094 robot.setAxis(0,Axis1.getValue());
00095 block = true;
00096 Tcp.setValue(robot.getTcp());
00097 block = false;
00098 }
00099 if(prop == &Axis2 && !block){
00100 robot.setAxis(1,Axis2.getValue());
00101 block = true;
00102 Tcp.setValue(robot.getTcp());
00103 block = false;
00104 }
00105 if(prop == &Axis3 && !block){
00106 robot.setAxis(2,Axis3.getValue());
00107 block = true;
00108 Tcp.setValue(robot.getTcp());
00109 block = false;
00110 }
00111 if(prop == &Axis4 && !block){
00112 robot.setAxis(3,Axis4.getValue());
00113 block = true;
00114 Tcp.setValue(robot.getTcp());
00115 block = false;
00116 }
00117 if(prop == &Axis5 && !block){
00118 robot.setAxis(4,Axis5.getValue());
00119 block = true;
00120 Tcp.setValue(robot.getTcp());
00121 block = false;
00122 }
00123 if(prop == &Axis6 && !block){
00124 robot.setAxis(5,Axis6.getValue());
00125 block = true;
00126 Tcp.setValue(robot.getTcp());
00127 block = false;
00128 }
00129 if(prop == &Tcp && !block){
00130 robot.setTo(Tcp.getValue());
00131 block = true;
00132 Axis1.setValue((float)robot.getAxis(0));
00133 Axis2.setValue((float)robot.getAxis(1));
00134 Axis3.setValue((float)robot.getAxis(2));
00135 Axis4.setValue((float)robot.getAxis(3));
00136 Axis5.setValue((float)robot.getAxis(4));
00137 Axis6.setValue((float)robot.getAxis(5));
00138 block = false;
00139 }
00140 App::GeoFeature::onChanged(prop);
00141 }
00142
00143 void RobotObject::Save (Base::Writer &writer) const
00144 {
00145 App::GeoFeature::Save(writer);
00146 robot.Save(writer);
00147 }
00148
00149 void RobotObject::Restore(Base::XMLReader &reader)
00150 {
00151 block = true;
00152 App::GeoFeature::Restore(reader);
00153 robot.Restore(reader);
00154
00155
00156 robot.setAxis(0,Axis1.getValue());
00157 robot.setAxis(1,Axis2.getValue());
00158 robot.setAxis(2,Axis3.getValue());
00159 robot.setAxis(3,Axis4.getValue());
00160 robot.setAxis(4,Axis5.getValue());
00161 robot.setAxis(5,Axis6.getValue());
00162 robot.setTo(Tcp.getValue());
00163 Tcp.setValue(robot.getTcp());
00164 block = false;
00165 }
00166