00001 /*************************************************************************** 00002 * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 * 00003 * * 00004 * This file is part of the FreeCAD CAx development system. * 00005 * * 00006 * This library is free software; you can redistribute it and/or * 00007 * modify it under the terms of the GNU Library General Public * 00008 * License as published by the Free Software Foundation; either * 00009 * version 2 of the License, or (at your option) any later version. * 00010 * * 00011 * This library is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00014 * GNU Library General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Library General Public * 00017 * License along with this library; see the file COPYING.LIB. If not, * 00018 * write to the Free Software Foundation, Inc., 59 Temple Place, * 00019 * Suite 330, Boston, MA 02111-1307, USA * 00020 * * 00021 ***************************************************************************/ 00022 00023 00024 #include "PreCompiled.h" 00025 00026 #ifndef _PreComp_ 00027 00028 #endif 00029 00030 #include "kdl_cp/chain.hpp" 00031 #include "kdl_cp/frames_io.hpp" 00032 00033 #include <stdio.h> 00034 #include <iostream> 00035 00036 #include <Base/Console.h> 00037 00038 00039 #include "Simulation.h" 00040 00041 using namespace Robot; 00042 using namespace std; 00043 using namespace KDL; 00044 00045 00046 00047 //=========================================================================== 00048 // Simulation class 00049 //=========================================================================== 00050 00051 00052 00053 Simulation::Simulation(const Robot::Trajectory &Trac,Robot::Robot6Axis &Rob) 00054 :Pos(0.0),Trac(Trac),Rob(Rob) 00055 { 00056 // simulate a trajectory with only one waypoint make no sense! 00057 assert(Trac.getSize() > 1); 00058 00059 00060 startAxis[0] = Rob.getAxis(0); 00061 startAxis[1] = Rob.getAxis(1); 00062 startAxis[2] = Rob.getAxis(2); 00063 startAxis[3] = Rob.getAxis(3); 00064 startAxis[4] = Rob.getAxis(4); 00065 startAxis[5] = Rob.getAxis(5); 00066 00067 setToTime(0); 00068 00069 } 00070 00071 Simulation::~Simulation() 00072 { 00073 } 00074 00075 void Simulation::step(double tick) 00076 { 00077 Pos += tick; 00078 } 00079 00080 void Simulation::setToWaypoint(unsigned int n) 00081 { 00082 00083 00084 } 00085 00086 void Simulation::setToTime(float t) 00087 { 00088 Pos = t; 00089 Base::Placement NeededPos = Trac.getPosition(Pos); 00090 NeededPos = NeededPos *Tool.inverse(); 00091 Rob.setTo(NeededPos); 00092 Axis[0] = Rob.getAxis(0); 00093 Axis[1] = Rob.getAxis(1); 00094 Axis[2] = Rob.getAxis(2); 00095 Axis[3] = Rob.getAxis(3); 00096 Axis[4] = Rob.getAxis(4); 00097 Axis[5] = Rob.getAxis(5); 00098 00099 } 00100 00101 void Simulation::reset(void) 00102 { 00103 Rob.setAxis(0,startAxis[0]); 00104 Rob.setAxis(1,startAxis[1]); 00105 Rob.setAxis(2,startAxis[2]); 00106 Rob.setAxis(3,startAxis[3]); 00107 Rob.setAxis(4,startAxis[4]); 00108 Rob.setAxis(5,startAxis[5]); 00109 00110 Base::Placement NeededPos = Trac.getPosition(0.0); 00111 NeededPos = NeededPos *Tool.inverse(); 00112 Rob.setTo(NeededPos); 00113 00114 Axis[0] = Rob.getAxis(0); 00115 Axis[1] = Rob.getAxis(1); 00116 Axis[2] = Rob.getAxis(2); 00117 Axis[3] = Rob.getAxis(3); 00118 Axis[4] = Rob.getAxis(4); 00119 Axis[5] = Rob.getAxis(5); 00120 00121 }