Cheetah Software  1.0
SimControlPanel Class Reference

#include <SimControlPanel.h>

+ Inheritance diagram for SimControlPanel:
+ Collaboration diagram for SimControlPanel:

Public Member Functions

 SimControlPanel (QWidget *parent=nullptr)
 
 ~SimControlPanel ()
 

Private Slots

void on_startButton_clicked ()
 
void on_stopButton_clicked ()
 
void on_joystickButton_clicked ()
 
void on_driverButton_clicked ()
 
void on_simulatorTable_cellChanged (int row, int column)
 
void on_saveSimulatorButton_clicked ()
 
void on_loadSimulatorButton_clicked ()
 
void on_robotTable_cellChanged (int row, int column)
 
void on_saveRobotButton_clicked ()
 
void on_loadRobotButton_clicked ()
 
void on_goHomeButton_clicked ()
 
void on_kickButton_clicked ()
 
void on_userControlTable_cellChanged (int row, int column)
 
void on_saveUserButton_clicked ()
 
void on_loadUserButton_clicked ()
 
void on_setTerrainButton_clicked ()
 
void updateTerrainLabel ()
 
void loadSimulationParameters (SimulatorControlParameters &params)
 
void loadRobotParameters (RobotControlParameters &params)
 
void loadUserParameters (ControlParameters &params)
 

Private Member Functions

void updateUiEnable ()
 

Private Attributes

std::thread _simThread
 
bool _started = false
 
Ui::SimControlPanel * ui
 
Simulation_simulation = nullptr
 
PeriodicTaskManager_interfaceTaskManager = nullptr
 
RobotInterface_robotInterface = nullptr
 
Graphics3D_graphicsWindow = nullptr
 
SimulatorControlParameters _parameters
 
ControlParameters _userParameters
 
bool _simulationMode = false
 
bool _firstStart = true
 
bool _ignoreTableCallbacks = false
 
bool _loadedUserSettings = false
 
std::string _terrainFileName
 

Detailed Description

Definition at line 23 of file SimControlPanel.h.

Constructor & Destructor Documentation

SimControlPanel::SimControlPanel ( QWidget *  parent = nullptr)
explicit

Init sim window

Definition at line 45 of file SimControlPanel.cpp.

References _loadedUserSettings, _parameters, _userParameters, DEFAULT_USER_FILE, ControlParameters::defineAndInitializeFromYamlFile(), ControlParameters::generateUnitializedList(), getConfigDirectoryPath(), ControlParameters::initializeFromYamlFile(), ControlParameters::isFullyInitialized(), loadSimulationParameters(), loadUserParameters(), SIMULATOR_DEFAULT_PARAMETERS, ui, updateTerrainLabel(), and updateUiEnable().

46  : QMainWindow(parent),
47  ui(new Ui::SimControlPanel),
48  _userParameters("user-parameters"),
50 
51  ui->setupUi(this); // QT setup
52  updateUiEnable(); // enable/disable buttons as needed.
53  updateTerrainLabel(); // display name of loaded terrain file
54 
55  // attempt to load default user settings.
56  _loadedUserSettings = true;
57 
58  try {
60  } catch (std::runtime_error& ex) {
61  _loadedUserSettings = false;
62  }
63 
64  if(!_loadedUserSettings) {
65  printf("[SimControlPanel] Failed to load default user settings!\n");
66  } else {
67  // display user settings in qtable if we loaded successfully
69  }
70 
71  // load simulator parameters
72  printf("[SimControlPanel] Init simulator parameters...\n");
76  printf(
77  "[ERROR] Simulator parameters are not fully initialized. You forgot: "
78  "\n%s\n",
80  throw std::runtime_error("simulator not initialized");
81  } else {
82  printf("\tsim parameters are all good\n");
83  }
85 }
ControlParameters _userParameters
#define SIMULATOR_DEFAULT_PARAMETERS
SimulatorControlParameters _parameters
std::string getConfigDirectoryPath()
Definition: utilities.cpp:30
#define DEFAULT_TERRAIN_FILE
void loadUserParameters(ControlParameters &params)
Ui::SimControlPanel * ui
void defineAndInitializeFromYamlFile(const std::string &path)
void loadSimulationParameters(SimulatorControlParameters &params)
#define DEFAULT_USER_FILE
void initializeFromYamlFile(const std::string &path)
std::string generateUnitializedList()
std::string _terrainFileName

+ Here is the call graph for this function:

SimControlPanel::~SimControlPanel ( )

Definition at line 87 of file SimControlPanel.cpp.

References _graphicsWindow, _interfaceTaskManager, _robotInterface, _simulation, and ui.

87  {
88  delete _simulation;
89  delete _interfaceTaskManager;
90  delete _robotInterface;
91  delete _graphicsWindow;
92  delete ui;
93 }
Simulation * _simulation
RobotInterface * _robotInterface
PeriodicTaskManager * _interfaceTaskManager
Ui::SimControlPanel * ui
Graphics3D * _graphicsWindow

Member Function Documentation

void SimControlPanel::loadRobotParameters ( RobotControlParameters params)
privateslot

Populate the robot qtable parameters

Definition at line 219 of file SimControlPanel.cpp.

References _ignoreTableCallbacks, ui, and updateQtableWithParameters().

219  {
220  _ignoreTableCallbacks = true;
221  updateQtableWithParameters(params, *ui->robotTable);
222  _ignoreTableCallbacks = false;
223 }
static void updateQtableWithParameters(ControlParameters &params, QTableWidget &table)
Ui::SimControlPanel * ui

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SimControlPanel::loadSimulationParameters ( SimulatorControlParameters params)
privateslot

Populate the simulator qtable parameters

Definition at line 209 of file SimControlPanel.cpp.

References _ignoreTableCallbacks, ui, and updateQtableWithParameters().

210  {
211  _ignoreTableCallbacks = true;
212  updateQtableWithParameters(params, *ui->simulatorTable);
213  _ignoreTableCallbacks = false;
214 }
static void updateQtableWithParameters(ControlParameters &params, QTableWidget &table)
Ui::SimControlPanel * ui

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SimControlPanel::loadUserParameters ( ControlParameters params)
privateslot

Populate the robot qtable parameters

Definition at line 228 of file SimControlPanel.cpp.

References _ignoreTableCallbacks, ui, and updateQtableWithParameters().

228  {
229  _ignoreTableCallbacks = true;
230  updateQtableWithParameters(params, *ui->userControlTable);
231  _ignoreTableCallbacks = false;
232 }
static void updateQtableWithParameters(ControlParameters &params, QTableWidget &table)
Ui::SimControlPanel * ui

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SimControlPanel::on_driverButton_clicked ( )
privateslot

Definition at line 241 of file SimControlPanel.cpp.

241 {}
void SimControlPanel::on_goHomeButton_clicked ( )
privateslot

Definition at line 577 of file SimControlPanel.cpp.

References _simulation, FBModelState< T >::bodyOrientation, FBModelState< T >::bodyPosition, FBModelState< T >::bodyVelocity, FBModelState< T >::q, FBModelState< T >::qd, and Simulation::setRobotState().

577  {
578  printf("go home\n");
579  FBModelState<double> homeState;
580  homeState.bodyOrientation << 1, 0, 0, 0;
581  homeState.bodyPosition = Vec3<double>(0, 0, 0.4);
582  homeState.bodyVelocity = SVec<double>::Zero();
583  homeState.q = DVec<double>(12);
584  homeState.q << -0.05, -0.8, 1.7, 0.05, -0.8, 1.7, -0.05, -0.8, 1.7, 0.05, -0.8, 1.7;
585  homeState.qd = homeState.q;
586 
587  _simulation->setRobotState(homeState);
588 }
Vec3< T > bodyPosition
Simulation * _simulation
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62
void setRobotState(FBModelState< double > &state)
Definition: Simulation.h:48
typename Eigen::Matrix< T, Eigen::Dynamic, 1 > DVec
Definition: cppTypes.h:102
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Quat< T > bodyOrientation

+ Here is the call graph for this function:

void SimControlPanel::on_joystickButton_clicked ( )
privateslot

Attempt to reset the joystick if a new one is connected

Definition at line 237 of file SimControlPanel.cpp.

References _graphicsWindow, and Graphics3D::resetGameController().

237  {
239 }
void resetGameController()
Definition: Graphics3D.h:54
Graphics3D * _graphicsWindow

+ Here is the call graph for this function:

void SimControlPanel::on_kickButton_clicked ( )
privateslot

Definition at line 590 of file SimControlPanel.cpp.

References _simulation, FBModelState< T >::bodyVelocity, Simulation::getRobotState(), Simulation::setRobotState(), and ui.

590  {
591  // velocity of the floating base:
592  SVec<double> kickVelocity;
593  kickVelocity << ui->kickAngularX->text().toDouble(),
594  ui->kickAngularY->text().toDouble(), ui->kickAngularZ->text().toDouble(),
595  ui->kickLinearX->text().toDouble(), ui->kickLinearY->text().toDouble(),
596  ui->kickLinearZ->text().toDouble();
597 
599  state.bodyVelocity += kickVelocity;
600  _simulation->setRobotState(state);
601 }
const FBModelState< double > & getRobotState()
Definition: Simulation.h:94
Simulation * _simulation
SVec< T > bodyVelocity
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62
void setRobotState(FBModelState< double > &state)
Definition: Simulation.h:48
Ui::SimControlPanel * ui

+ Here is the call graph for this function:

void SimControlPanel::on_loadRobotButton_clicked ( )
privateslot

Definition at line 407 of file SimControlPanel.cpp.

References ControlParameterCollection::_map, _robotInterface, _simulation, _simulationMode, ControlParameterCollection::checkIfAllSet(), ControlParameterCollection::clearAllSet(), ControlParameters::collection, createErrorMessage(), ControlParameters::generateUnitializedList(), RobotInterface::getParams(), Simulation::getRobotParams(), ControlParameters::initializeFromYamlFile(), Simulation::isRobotConnected(), loadRobotParameters(), ControlParameters::lockMutex(), RobotInterface::sendControlParameter(), Simulation::sendControlParameter(), and ControlParameters::unlockMutex().

407  {
408  QString fileName = QFileDialog::getOpenFileName(
409  nullptr, ("Load Quadruped Table Values"), "../config", "All Files (*)");
410  if (fileName == nullptr || fileName == "") {
411  createErrorMessage("File name is invalid");
412  return;
413  }
414 
415  if (_simulationMode) {
419  fileName.toStdString());
421  printf(
422  "new settings file %s doesn't contain the following robot "
423  "parameters:\n%s\n",
424  fileName.toStdString().c_str(),
426  throw std::runtime_error("bad new settings file");
427  }
429 
430  if (_simulation->isRobotConnected()) {
431  for (auto& kv : _simulation->getRobotParams().collection._map) {
433  kv.first, kv.second->get(kv.second->_kind), kv.second->_kind, false);
434  }
435  }
437  } else {
440  _robotInterface->getParams().initializeFromYamlFile(fileName.toStdString());
442  printf(
443  "new settings file %s doesn't contain the following robot "
444  "parameters:\n%s\n",
445  fileName.toStdString().c_str(),
447  throw std::runtime_error("bad new settings file");
448  }
450 
451  for (auto& kv : _robotInterface->getParams().collection._map) {
453  kv.first, kv.second->get(kv.second->_kind), kv.second->_kind, false);
454  }
455 
457  }
458 }
Simulation * _simulation
ControlParameterCollection collection
void sendControlParameter(const std::string &name, ControlParameterValue value, ControlParameterValueKind kind, bool isUser)
std::map< std::string, ControlParameter * > _map
RobotInterface * _robotInterface
void loadRobotParameters(RobotControlParameters &params)
bool checkIfAllSet()
are all the control parameters initialized?
RobotControlParameters & getRobotParams()
Definition: Simulation.h:108
RobotControlParameters & getParams()
static void createErrorMessage(const std::string &text)
void initializeFromYamlFile(const std::string &path)
void sendControlParameter(const std::string &name, ControlParameterValue value, ControlParameterValueKind kind, bool isUser)
Definition: Simulation.cpp:216
std::string generateUnitializedList()
bool isRobotConnected()
Definition: Simulation.h:111

+ Here is the call graph for this function:

void SimControlPanel::on_loadSimulatorButton_clicked ( )
privateslot

Load simulation config from file

Definition at line 319 of file SimControlPanel.cpp.

References _parameters, ControlParameterCollection::checkIfAllSet(), ControlParameterCollection::clearAllSet(), ControlParameters::collection, createErrorMessage(), ControlParameters::generateUnitializedList(), ControlParameters::initializeFromYamlFile(), loadSimulationParameters(), and ControlParameters::unlockMutex().

319  {
320  QString fileName = QFileDialog::getOpenFileName(
321  nullptr, ("Load Simulator Table Values"), "../config", "All Files (*)");
322  if (fileName == nullptr || fileName == "") {
323  createErrorMessage("File name is invalid");
324  return;
325  };
327  _parameters.initializeFromYamlFile(fileName.toStdString());
329  printf(
330  "new settings file %s doesn't contain the following simulator "
331  "parameters:\n%s\n",
332  fileName.toStdString().c_str(),
334  throw std::runtime_error("bad new settings file");
335  }
338 }
ControlParameterCollection collection
SimulatorControlParameters _parameters
bool checkIfAllSet()
are all the control parameters initialized?
static void createErrorMessage(const std::string &text)
void loadSimulationParameters(SimulatorControlParameters &params)
void initializeFromYamlFile(const std::string &path)
std::string generateUnitializedList()

+ Here is the call graph for this function:

void SimControlPanel::on_loadUserButton_clicked ( )
privateslot

Definition at line 533 of file SimControlPanel.cpp.

References _loadedUserSettings, ControlParameterCollection::_map, _robotInterface, _simulation, _simulationMode, _started, _userParameters, ControlParameters::collection, createErrorMessage(), ControlParameters::defineAndInitializeFromYamlFile(), ControlParameterCollection::deleteAll(), Simulation::isRobotConnected(), loadUserParameters(), ControlParameters::lockMutex(), RobotInterface::sendControlParameter(), Simulation::sendControlParameter(), and ControlParameters::unlockMutex().

533  {
534  QString fileName = QFileDialog::getOpenFileName(
535  nullptr, ("Load User Table Values"), "../config", "All Files (*)");
536  if (fileName == nullptr || fileName == "") {
537  createErrorMessage("File name is invalid");
538  return;
539  }
540 
544  fileName.toStdString());
547  _loadedUserSettings = true;
548 
549  if(_started) {
550  if (_simulationMode) {
552  for (auto& kv : _userParameters.collection._map) {
554  kv.first, kv.second->get(kv.second->_kind), kv.second->_kind, true);
555  }
556  }
557  } else {
558  for (auto& kv : _userParameters.collection._map) {
560  kv.first, kv.second->get(kv.second->_kind), kv.second->_kind, true);
561  }
562 
563  }
564  }
565 }
Simulation * _simulation
ControlParameterCollection collection
void sendControlParameter(const std::string &name, ControlParameterValue value, ControlParameterValueKind kind, bool isUser)
std::map< std::string, ControlParameter * > _map
ControlParameters _userParameters
RobotInterface * _robotInterface
void loadUserParameters(ControlParameters &params)
static void createErrorMessage(const std::string &text)
void defineAndInitializeFromYamlFile(const std::string &path)
void sendControlParameter(const std::string &name, ControlParameterValue value, ControlParameterValueKind kind, bool isUser)
Definition: Simulation.cpp:216
bool isRobotConnected()
Definition: Simulation.h:111

+ Here is the call graph for this function:

void SimControlPanel::on_robotTable_cellChanged ( int  row,
int  column 
)
privateslot

Definition at line 340 of file SimControlPanel.cpp.

References _ignoreTableCallbacks, _robotInterface, _simulation, _simulationMode, RobotInterface::getParams(), Simulation::getRobotParams(), Simulation::isRobotConnected(), RobotInterface::sendControlParameter(), Simulation::sendControlParameter(), and ui.

340  {
341  if (_ignoreTableCallbacks) return;
342  if (column != 1) {
343  return;
344  }
345 
346  auto cell = ui->robotTable->item(row, 0);
347  std::string cellName = cell->text().toStdString();
348 
349  if (cellName == "") {
350  return;
351  }
352 
353  auto& parameter = (_simulationMode ? _simulation->getRobotParams()
355  .collection.lookup(cellName);
356  ControlParameterValueKind kind = parameter._kind;
357  ControlParameterValue oldValue = parameter.get(kind);
358 
359  bool success = true;
360 
361  try {
362  parameter.setFromString(ui->robotTable->item(row, 1)->text().toStdString());
363  } catch (std::exception& e) {
364  success = false;
365  }
366 
367  if (!success) {
368  printf("[ERROR] invalid data, restoring old data!\n");
369  parameter.set(oldValue, kind);
370 
371  assert(!_ignoreTableCallbacks);
372 
373  _ignoreTableCallbacks = true;
374  ui->robotTable->item(row, 1)->setText(
375  QString(parameter
376  .toString()
377  .c_str()));
378  _ignoreTableCallbacks = false;
379  } else {
380  if (_simulationMode) {
381  if (_simulation->isRobotConnected()) {
383  cellName, parameter.get(parameter._kind), parameter._kind, false);
384  }
385 
386  _ignoreTableCallbacks = true;
387  ui->robotTable->item(row, 1)->setText(
388  QString(parameter.toString().c_str()));
389  _ignoreTableCallbacks = false;
390  } else {
392  cellName, parameter.get(parameter._kind), parameter._kind, false);
393  }
394  }
395 }
Simulation * _simulation
void sendControlParameter(const std::string &name, ControlParameterValue value, ControlParameterValueKind kind, bool isUser)
ControlParameterValueKind
RobotInterface * _robotInterface
RobotControlParameters & getRobotParams()
Definition: Simulation.h:108
RobotControlParameters & getParams()
Ui::SimControlPanel * ui
void sendControlParameter(const std::string &name, ControlParameterValue value, ControlParameterValueKind kind, bool isUser)
Definition: Simulation.cpp:216
bool isRobotConnected()
Definition: Simulation.h:111

+ Here is the call graph for this function:

void SimControlPanel::on_saveRobotButton_clicked ( )
privateslot

Definition at line 397 of file SimControlPanel.cpp.

References _simulation, createErrorMessage(), Simulation::getRobotParams(), and ControlParameters::writeToYamlFile().

397  {
398  QString fileName = QFileDialog::getSaveFileName(
399  nullptr, ("Save Robot Table Values"), "../config", "All Files (*)");
400  if (fileName == nullptr || fileName == "") {
401  createErrorMessage("File name is invalid");
402  return;
403  }
404  _simulation->getRobotParams().writeToYamlFile(fileName.toStdString());
405 }
Simulation * _simulation
void writeToYamlFile(const std::string &path)
RobotControlParameters & getRobotParams()
Definition: Simulation.h:108
static void createErrorMessage(const std::string &text)

+ Here is the call graph for this function:

void SimControlPanel::on_saveSimulatorButton_clicked ( )
privateslot

Save simulation config to file

Definition at line 303 of file SimControlPanel.cpp.

References _parameters, createErrorMessage(), ControlParameters::lockMutex(), ControlParameters::unlockMutex(), and ControlParameters::writeToYamlFile().

303  {
304  QString fileName = QFileDialog::getSaveFileName(
305  nullptr, ("Save Simulator Table Values"), "../config", "All Files (*)");
306  if (fileName == nullptr || fileName == "") {
307  createErrorMessage("File name is invalid");
308  return;
309  }
310 
312  _parameters.writeToYamlFile(fileName.toStdString());
314 }
SimulatorControlParameters _parameters
void writeToYamlFile(const std::string &path)
static void createErrorMessage(const std::string &text)

+ Here is the call graph for this function:

void SimControlPanel::on_saveUserButton_clicked ( )
privateslot

Definition at line 567 of file SimControlPanel.cpp.

References _userParameters, createErrorMessage(), and ControlParameters::writeToYamlFile().

567  {
568  QString fileName = QFileDialog::getSaveFileName(
569  nullptr, ("Save User Table Values"), "../config", "All Files (*)");
570  if (fileName == nullptr || fileName == "") {
571  createErrorMessage("File name is invalid");
572  return;
573  }
574  _userParameters.writeToYamlFile(fileName.toStdString());
575 }
ControlParameters _userParameters
void writeToYamlFile(const std::string &path)
static void createErrorMessage(const std::string &text)

+ Here is the call graph for this function:

void SimControlPanel::on_setTerrainButton_clicked ( )
privateslot

Definition at line 460 of file SimControlPanel.cpp.

References _terrainFileName, createErrorMessage(), and updateTerrainLabel().

460  {
461  QString fileName = QFileDialog::getOpenFileName(
462  nullptr, ("Load Terrain Definition"), "../config", "All Files (*)");
463  if (fileName == nullptr || fileName == "") {
464  createErrorMessage("File name is invalid");
465  return;
466  }
467 
468  _terrainFileName = fileName.toStdString();
470 }
static void createErrorMessage(const std::string &text)
std::string _terrainFileName

+ Here is the call graph for this function:

void SimControlPanel::on_simulatorTable_cellChanged ( int  row,
int  column 
)
privateslot

Respond to a change in the simulator table.

Definition at line 246 of file SimControlPanel.cpp.

References _ignoreTableCallbacks, ControlParameter::_kind, _parameters, ControlParameters::collection, ControlParameterCollection::lookup(), ControlParameter::toString(), and ui.

246  {
247  if (_ignoreTableCallbacks) return;
248 
249  // we only allow values to change, which are in column 1
250  if (column != 1) {
251  return;
252  }
253 
254  // get the name of the parameter....
255  auto cell = ui->simulatorTable->item(row, 0);
256  std::string cellName = cell->text().toStdString();
257 
258  if (cellName == "") {
259  return;
260  }
261 
262  // get the parameters
263  auto& parameter = _parameters.collection.lookup(cellName);
264  ControlParameterValueKind kind = parameter._kind;
265  ControlParameterValue oldValue = parameter.get(kind);
266 
267  bool success = true;
268 
269  // attempt to set, based on string.
270  try {
271  parameter.setFromString(
272  ui->simulatorTable->item(row, 1)->text().toStdString());
273  } catch (std::exception& e) {
274  success = false;
275  }
276 
277  // if it fails (bad user input string), restore to the old value
278  if (!success) {
279  printf("[ERROR] invalid data, restoring old data!\n");
280  // set parameter value
281  parameter.set(oldValue, kind);
282 
283  assert(!_ignoreTableCallbacks);
284 
285  // manually fix the table
286  _ignoreTableCallbacks = true;
287  ui->simulatorTable->item(row, 1)->setText(
288  QString(_parameters.collection.lookup(cellName).toString().c_str()));
289  _ignoreTableCallbacks = false;
290  } else {
291  // this update "rewrites" the value in the table. If it's an integer, it kills any
292  // decimal. If it's a float, it puts in scientific notation if needed.
293  _ignoreTableCallbacks = true;
294  ui->simulatorTable->item(row, 1)->setText(
295  QString(parameter.toString().c_str()));
296  _ignoreTableCallbacks = false;
297  }
298 }
ControlParameterCollection collection
ControlParameterValueKind _kind
ControlParameterValueKind
SimulatorControlParameters _parameters
std::string toString()
ControlParameter & lookup(const std::string &name)
Ui::SimControlPanel * ui

+ Here is the call graph for this function:

void SimControlPanel::on_startButton_clicked ( )
privateslot

Start a simulation/robot run

Definition at line 116 of file SimControlPanel.cpp.

References _graphicsWindow, _interfaceTaskManager, _parameters, _robotInterface, _simThread, _simulation, _simulationMode, _started, _terrainFileName, _userParameters, CHEETAH_3, createErrorMessage(), RobotInterface::getParams(), Simulation::getRobotParams(), Simulation::getSimParams(), loadRobotParameters(), loadSimulationParameters(), Simulation::loadTerrainFile(), MINI_CHEETAH, Simulation::runAtSpeed(), Graphics3D::setAnimating(), RobotInterface::startInterface(), ui, and updateUiEnable().

116  {
117  // get robot type
118  RobotType robotType;
119 
120  if (ui->cheetah3Button->isChecked()) {
121  robotType = RobotType::CHEETAH_3;
122  } else if (ui->miniCheetahButton->isChecked()) {
123  robotType = RobotType::MINI_CHEETAH;
124  } else {
125  createErrorMessage("Error: you must select a robot");
126  return;
127  }
128 
129  // get run type
130  if (!ui->simulatorButton->isChecked() && !ui->robotButton->isChecked()) {
132  "Error: you must select either robot or simulation mode");
133  return;
134  }
135 
136  _simulationMode = ui->simulatorButton->isChecked();
137 
138  // graphics
139  printf("[SimControlPanel] Initialize Graphics...\n");
140  _graphicsWindow = new Graphics3D();
141  _graphicsWindow->show();
142  _graphicsWindow->resize(1280, 720);
143 
144  if (_simulationMode) {
145  // run a simulation
146  printf("[SimControlPanel] Initialize simulator...\n");
150 
151  // terrain
152  printf("[SimControlParameter] Load terrain...\n");
154 
155  // start sim
156  _simThread = std::thread([this]() { _simulation->runAtSpeed(); });
157 
158  // graphics start
160  } else {
161  printf("[SimControlPanel] Init Robot Interface...\n");
168  }
169 
170  _started = true;
171  updateUiEnable();
172 }
Simulation * _simulation
void runAtSpeed(bool graphics=true)
Definition: Simulation.cpp:579
ControlParameters _userParameters
RobotInterface * _robotInterface
SimulatorControlParameters _parameters
void loadRobotParameters(RobotControlParameters &params)
void loadTerrainFile(const std::string &terrainFileName, bool addGraphics=true)
Definition: Simulation.cpp:638
std::thread _simThread
PeriodicTaskManager * _interfaceTaskManager
RobotControlParameters & getRobotParams()
Definition: Simulation.h:108
RobotControlParameters & getParams()
Ui::SimControlPanel * ui
Graphics3D * _graphicsWindow
void setAnimating(bool animating)
Definition: Graphics3D.cpp:331
static void createErrorMessage(const std::string &text)
void loadSimulationParameters(SimulatorControlParameters &params)
RobotType
Definition: cppTypes.h:120
SimulatorControlParameters & getSimParams()
Definition: Simulation.h:106
std::string _terrainFileName

+ Here is the call graph for this function:

void SimControlPanel::on_stopButton_clicked ( )
privateslot

Stop the currently running simulation or robot connection

Definition at line 177 of file SimControlPanel.cpp.

References _graphicsWindow, _interfaceTaskManager, _robotInterface, _simThread, _simulation, _started, Graphics3D::setAnimating(), Simulation::stop(), RobotInterface::stopInterface(), and updateUiEnable().

177  {
178  if (_simulation) {
179  _simulation->stop();
180  _simThread.join();
181  } else {
183  }
184 
185  if (_graphicsWindow) {
187  _graphicsWindow->hide();
188  }
189 
190  delete _interfaceTaskManager;
191  delete _robotInterface;
192  delete _simulation;
193  delete _graphicsWindow;
194 
195  _simulation = nullptr;
196  _graphicsWindow = nullptr;
197  _robotInterface = nullptr;
198  _interfaceTaskManager = nullptr;
199 
200  _started = false;
201  updateUiEnable();
202 }
void stop()
Definition: Simulation.h:96
Simulation * _simulation
RobotInterface * _robotInterface
std::thread _simThread
PeriodicTaskManager * _interfaceTaskManager
Graphics3D * _graphicsWindow
void setAnimating(bool animating)
Definition: Graphics3D.cpp:331

+ Here is the call graph for this function:

void SimControlPanel::on_userControlTable_cellChanged ( int  row,
int  column 
)
privateslot

Definition at line 472 of file SimControlPanel.cpp.

References _ignoreTableCallbacks, ControlParameter::_kind, _robotInterface, _simulation, _simulationMode, _started, _userParameters, ControlParameters::collection, Simulation::isRobotConnected(), ControlParameterCollection::lookup(), RobotInterface::sendControlParameter(), Simulation::sendControlParameter(), and ui.

472  {
473  if (_ignoreTableCallbacks) return;
474  if (column != 1) {
475  return;
476  }
477 
478  auto cell = ui->userControlTable->item(row, 0);
479  std::string cellName = cell->text().toStdString();
480 
481  if (cellName == "") {
482  return;
483  }
484 
485  auto& parameter = _userParameters.collection.lookup(cellName);
486 // auto& parameter = (_simulationMode ? _simulation->getRobotParams()
487 // : _robotInterface->getParams())
488 // .collection.lookup(cellName);
489  ControlParameterValueKind kind = parameter._kind;
490  ControlParameterValue oldValue = parameter.get(kind);
491 
492  bool success = true;
493 
494  try {
495  parameter.setFromString(ui->userControlTable->item(row, 1)->text().toStdString());
496  } catch (std::exception& e) {
497  success = false;
498  }
499 
500  if (!success) {
501  printf("[ERROR] invalid data, restoring old data!\n");
502  parameter.set(oldValue, kind);
503 
504  assert(!_ignoreTableCallbacks);
505 
506  _ignoreTableCallbacks = true;
507  ui->userControlTable->item(row, 1)->setText(
508  QString(_userParameters
509  .collection.lookup(cellName)
510  .toString()
511  .c_str()));
512  _ignoreTableCallbacks = false;
513  } else {
514  if(_started) {
515  if (_simulationMode) {
518  cellName, parameter.get(parameter._kind), parameter._kind, true);
519  }
520 
521  _ignoreTableCallbacks = true;
522  ui->userControlTable->item(row, 1)->setText(
523  QString(parameter.toString().c_str()));
524  _ignoreTableCallbacks = false;
525  } else {
527  cellName, parameter.get(parameter._kind), parameter._kind, true);
528  }
529  }
530  }
531 }
Simulation * _simulation
ControlParameterCollection collection
ControlParameterValueKind _kind
void sendControlParameter(const std::string &name, ControlParameterValue value, ControlParameterValueKind kind, bool isUser)
ControlParameterValueKind
ControlParameters _userParameters
RobotInterface * _robotInterface
ControlParameter & lookup(const std::string &name)
Ui::SimControlPanel * ui
void sendControlParameter(const std::string &name, ControlParameterValue value, ControlParameterValueKind kind, bool isUser)
Definition: Simulation.cpp:216
bool isRobotConnected()
Definition: Simulation.h:111

+ Here is the call graph for this function:

void SimControlPanel::updateTerrainLabel ( )
privateslot

Update the name of the loaded terrain file label

Definition at line 109 of file SimControlPanel.cpp.

References _terrainFileName, and ui.

109  {
110  ui->terrainFileLabel->setText(QString(_terrainFileName.c_str()));
111 }
Ui::SimControlPanel * ui
std::string _terrainFileName

+ Here is the caller graph for this function:

void SimControlPanel::updateUiEnable ( )
private

Enable/disable buttons as needed based on what is running

Definition at line 98 of file SimControlPanel.cpp.

References _started, and ui.

98  {
99  ui->startButton->setEnabled(!_started);
100  ui->stopButton->setEnabled(_started);
101  ui->joystickButton->setEnabled(_started);
102  ui->robotTable->setEnabled(_started);
103  ui->goHomeButton->setEnabled(_started);
104 }
Ui::SimControlPanel * ui

+ Here is the caller graph for this function:

Member Data Documentation

bool SimControlPanel::_firstStart = true
private

Definition at line 83 of file SimControlPanel.h.

Graphics3D* SimControlPanel::_graphicsWindow = nullptr
private

Definition at line 79 of file SimControlPanel.h.

bool SimControlPanel::_ignoreTableCallbacks = false
private

Definition at line 84 of file SimControlPanel.h.

PeriodicTaskManager* SimControlPanel::_interfaceTaskManager = nullptr
private

Definition at line 77 of file SimControlPanel.h.

bool SimControlPanel::_loadedUserSettings = false
private

Definition at line 85 of file SimControlPanel.h.

SimulatorControlParameters SimControlPanel::_parameters
private

Definition at line 80 of file SimControlPanel.h.

RobotInterface* SimControlPanel::_robotInterface = nullptr
private

Definition at line 78 of file SimControlPanel.h.

std::thread SimControlPanel::_simThread
private

Definition at line 73 of file SimControlPanel.h.

Simulation* SimControlPanel::_simulation = nullptr
private

Definition at line 76 of file SimControlPanel.h.

bool SimControlPanel::_simulationMode = false
private

Definition at line 82 of file SimControlPanel.h.

bool SimControlPanel::_started = false
private

Definition at line 74 of file SimControlPanel.h.

std::string SimControlPanel::_terrainFileName
private

Definition at line 86 of file SimControlPanel.h.

ControlParameters SimControlPanel::_userParameters
private

Definition at line 81 of file SimControlPanel.h.

Ui::SimControlPanel* SimControlPanel::ui
private

Definition at line 75 of file SimControlPanel.h.


The documentation for this class was generated from the following files: