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 <QTimer>
00030 #include "TrajectorySimulate.h"
00031 #include <Gui/Application.h>
00032 #include <Gui/Document.h>
00033 #include <Gui/BitmapFactory.h>
00034 #include <Gui/ViewProvider.h>
00035 #include <Gui/WaitCursor.h>
00036 #include <Base/Console.h>
00037 #include <Gui/Selection.h>
00038
00039 #include <Mod/Robot/App/Waypoint.h>
00040
00041
00042 using namespace RobotGui;
00043 using namespace Gui;
00044
00045 TrajectorySimulate::TrajectorySimulate(Robot::RobotObject *pcRobotObject,Robot::TrajectoryObject *pcTrajectoryObject,QWidget *parent)
00046 : QDialog( parent),
00047 sim(pcTrajectoryObject->Trajectory.getValue(),pcRobotObject->getRobot()),
00048 Run(false),
00049 block(false),
00050 timePos(0.0)
00051 {
00052 this->setupUi(this);
00053 QMetaObject::connectSlotsByName(this);
00054
00055
00056 sim.Tool = pcRobotObject->Tool.getValue();
00057
00058 trajectoryTable->setSortingEnabled(false);
00059
00060 Robot::Trajectory trac = pcTrajectoryObject->Trajectory.getValue();
00061 trajectoryTable->setRowCount(trac.getSize());
00062 duration = trac.getDuration();
00063 timeSpinBox->setMaximum(duration);
00064
00065 for(unsigned int i=0;i<trac.getSize();i++){
00066 Robot::Waypoint pt = trac.getWaypoint(i);
00067 switch(pt.Type){
00068 case Robot::Waypoint::UNDEF: trajectoryTable->setItem(i, 0, new QTableWidgetItem(QString::fromAscii("UNDEF")));break;
00069 case Robot::Waypoint::CIRC: trajectoryTable->setItem(i, 0, new QTableWidgetItem(QString::fromAscii("CIRC")));break;
00070 case Robot::Waypoint::PTP: trajectoryTable->setItem(i, 0, new QTableWidgetItem(QString::fromAscii("PTP")));break;
00071 case Robot::Waypoint::LINE: trajectoryTable->setItem(i, 0, new QTableWidgetItem(QString::fromAscii("LIN")));break;
00072 default: trajectoryTable->setItem(i, 0, new QTableWidgetItem(QString::fromAscii("UNDEF")));break;
00073 }
00074 trajectoryTable->setItem(i, 1, new QTableWidgetItem(QString::fromUtf8(pt.Name.c_str())));
00075 if(pt.Cont)
00076 trajectoryTable->setItem(i, 2, new QTableWidgetItem(QString::fromAscii("|")));
00077 else
00078 trajectoryTable->setItem(i, 2, new QTableWidgetItem(QString::fromAscii("-")));
00079 trajectoryTable->setItem(i, 3, new QTableWidgetItem(QString::number(pt.Velocity)));
00080 trajectoryTable->setItem(i, 4, new QTableWidgetItem(QString::number(pt.Accelaration)));
00081
00082 }
00083
00084 QObject::connect(ButtonStepStart ,SIGNAL(clicked()),this,SLOT(start()));
00085 QObject::connect(ButtonStepStop ,SIGNAL(clicked()),this,SLOT(stop()));
00086 QObject::connect(ButtonStepRun ,SIGNAL(clicked()),this,SLOT(run()));
00087 QObject::connect(ButtonStepBack ,SIGNAL(clicked()),this,SLOT(back()));
00088 QObject::connect(ButtonStepForward ,SIGNAL(clicked()),this,SLOT(forward()));
00089 QObject::connect(ButtonStepEnd ,SIGNAL(clicked()),this,SLOT(end()));
00090
00091
00092
00093 timer = new QTimer( this );
00094 timer->setInterval(100);
00095 QObject::connect(timer ,SIGNAL(timeout ()),this,SLOT(timerDone()));
00096
00097 QObject::connect( timeSpinBox ,SIGNAL(valueChanged(double)), this, SLOT(valueChanged(double)) );
00098 QObject::connect( timeSlider ,SIGNAL(valueChanged(int) ), this, SLOT(valueChanged(int)) );
00099
00100
00101 ViewProv = dynamic_cast<ViewProviderRobotObject*>(Gui::Application::Instance->activeDocument()->getViewProvider(pcRobotObject) );
00102
00103 setTo();
00104 }
00105
00106 TrajectorySimulate::~TrajectorySimulate()
00107 {
00108 }
00109
00110 void TrajectorySimulate::setTo(void)
00111 {
00112 sim.setToTime(timePos);
00113 ViewProv->setAxisTo(sim.Axis[0],sim.Axis[1],sim.Axis[2],sim.Axis[3],sim.Axis[4],sim.Axis[5],sim.Rob.getTcp());
00114 }
00115
00116 void TrajectorySimulate::start(void)
00117 {
00118 timePos = 0.0f;
00119 timeSpinBox->setValue(timePos);
00120 timeSlider->setValue(int((timePos/duration)*1000));
00121 setTo();
00122
00123 }
00124 void TrajectorySimulate::stop(void)
00125 {
00126 timer->stop();
00127 Run = false;
00128 }
00129 void TrajectorySimulate::run(void)
00130 {
00131 timer->start();
00132 Run = true;
00133 }
00134 void TrajectorySimulate::back(void)
00135 {
00136 }
00137 void TrajectorySimulate::forward(void)
00138 {
00139 }
00140 void TrajectorySimulate::end(void)
00141 {
00142 timePos = duration;
00143 timeSpinBox->setValue(timePos);
00144 timeSlider->setValue(int((timePos/duration)*1000));
00145 setTo();
00146 }
00147
00148 void TrajectorySimulate::timerDone(void)
00149 {
00150 if(timePos < duration){
00151 timePos += .1f;
00152 timeSpinBox->setValue(timePos);
00153 timeSlider->setValue(int((timePos/duration)*1000));
00154 setTo();
00155 timer->start();
00156 }else{
00157 timer->stop();
00158 Run = false;
00159 }
00160 }
00161
00162 void TrajectorySimulate::valueChanged ( int value )
00163 {
00164 if(!block){
00165 timePos = duration*(value/1000.0);
00166 block=true;
00167 timeSpinBox->setValue(timePos);
00168 block=false;
00169 setTo();
00170 }
00171 }
00172
00173 void TrajectorySimulate::valueChanged ( double value )
00174 {
00175 if(!block){
00176 timePos = value;
00177 block=true;
00178 timeSlider->setValue(int((timePos/duration)*1000));
00179 block=false;
00180 setTo();
00181 }
00182 }
00183
00184
00185 #include "moc_TrajectorySimulate.cpp"