Cheetah Software
1.0
|
#include <Simulation.h>
Public Member Functions | |
EIGEN_MAKE_ALIGNED_OPERATOR_NEW | Simulation (RobotType robot, Graphics3D *window, SimulatorControlParameters ¶ms, ControlParameters &userParams) |
void | setRobotState (FBModelState< double > &state) |
void | step (double dt, double dtLowLevelControl, double dtHighLevelControl) |
void | addCollisionPlane (double mu, double resti, double height, double sizeX=20, double sizeY=20, double checkerX=40, double checkerY=40, bool addToWindow=true) |
void | addCollisionBox (double mu, double resti, double depth, double width, double height, const Vec3< double > &pos, const Mat3< double > &ori, bool addToWindow=true, bool transparent=true) |
void | addCollisionMesh (double mu, double resti, double grid_size, const Vec3< double > &left_corner_loc, const DMat< double > &height_map, bool addToWindow=true, bool transparent=true) |
void | lowLevelControl () |
void | highLevelControl () |
void | updateGraphics () |
void | runAtSpeed (bool graphics=true) |
void | sendControlParameter (const std::string &name, ControlParameterValue value, ControlParameterValueKind kind, bool isUser) |
void | resetSimTime () |
~Simulation () | |
const FBModelState< double > & | getRobotState () |
void | stop () |
SimulatorControlParameters & | getSimParams () |
RobotControlParameters & | getRobotParams () |
ControlParameters & | getUserParams () |
bool | isRobotConnected () |
void | firstRun () |
void | buildLcmMessage () |
void | loadTerrainFile (const std::string &terrainFileName, bool addGraphics=true) |
Top-level control of a simulation. A simulation includes 1 robot and 1 controller It does not include the graphics window: this must be set with the setWindow method
Definition at line 39 of file Simulation.h.
|
explicit |
Initialize the simulator here. It is not okay to block here waiting for the robot to connect. Use firstRun() instead!
Definition at line 18 of file Simulation.cpp.
References Quadruped< T >::_abadLinkLength, _actuatorModels, _controllerRobotID, Graphics3D::_drawList, Quadruped< T >::_hipLinkLength, _imuSimulator, Quadruped< T >::_kneeLinkLength, _lcm, _model, _quadruped, _robot, _robotControllerState, _robotDataModel, _robotDataSimulator, _robotParams, _sharedMemory, _simParams, _simRobotID, _simulator, _spiCommand, _spiData, _spineBoards, _tau, _tiBoards, DrawList::_visualizationData, _window, FBModelState< T >::bodyOrientation, FBModelState< T >::bodyPosition, FBModelState< T >::bodyVelocity, Quadruped< T >::buildActuatorModels(), Quadruped< T >::buildModel(), CHEETAH_3, CHEETAH_3_DEFAULT_PARAMETERS, SpineBoard::cmd, ori::coordinateRotation(), SharedMemoryObject< T >::createNew(), SpineBoard::data, DEVELOPMENT_SIMULATOR_SHARED_MEMORY_NAME, ControlParameters::generateUnitializedList(), getConfigDirectoryPath(), getLcmUrl(), TI_BoardControl::init(), SpineBoard::init(), ControlParameters::initializeFromYamlFile(), ControlParameters::isFullyInitialized(), ControlParameters::lockMutex(), MINI_CHEETAH, MINI_CHEETAH_DEFAULT_PARAMETERS, FBModelState< T >::q, FBModelState< T >::qd, TI_BoardControl::reset_ti_board_command(), TI_BoardControl::reset_ti_board_data(), SpineBoard::resetCommand(), SpineBoard::resetData(), ori::rotationMatrixToQuaternion(), TI_BoardControl::run_ti_board_iteration(), TI_BoardControl::set_link_lengths(), setRobotState(), DynamicsSimulator< T >::setState(), Graphics3D::setupCheetah3(), Graphics3D::setupMiniCheetah(), and ControlParameters::unlockMutex().
|
inline |
Definition at line 87 of file Simulation.h.
References _imuSimulator, _lcm, _robotDataSimulator, and _simulator.
void Simulation::addCollisionBox | ( | double | mu, |
double | resti, | ||
double | depth, | ||
double | width, | ||
double | height, | ||
const Vec3< double > & | pos, | ||
const Mat3< double > & | ori, | ||
bool | addToWindow = true , |
||
bool | transparent = true |
||
) |
Add an box collision to the simulator
mu | : location of the box |
resti | : restitution coefficient |
depth | : depth (x) of box |
width | : width (y) of box |
height | : height (z) of box |
pos | : position of box |
ori | : orientation of box |
addToWindow | : if true, also adds graphics for the plane |
Definition at line 546 of file Simulation.cpp.
References Graphics3D::_drawList, _simulator, _window, DrawList::addBox(), DynamicsSimulator< T >::addCollisionBox(), Graphics3D::lockGfxMutex(), and Graphics3D::unlockGfxMutex().
void Simulation::addCollisionMesh | ( | double | mu, |
double | resti, | ||
double | grid_size, | ||
const Vec3< double > & | left_corner_loc, | ||
const DMat< double > & | height_map, | ||
bool | addToWindow = true , |
||
bool | transparent = true |
||
) |
Definition at line 559 of file Simulation.cpp.
References Graphics3D::_drawList, _simulator, _window, DynamicsSimulator< T >::addCollisionMesh(), DrawList::addMesh(), Graphics3D::lockGfxMutex(), and Graphics3D::unlockGfxMutex().
void Simulation::addCollisionPlane | ( | double | mu, |
double | resti, | ||
double | height, | ||
double | sizeX = 20 , |
||
double | sizeY = 20 , |
||
double | checkerX = 40 , |
||
double | checkerY = 40 , |
||
bool | addToWindow = true |
||
) |
Add an infinite collision plane to the simulator
mu | : friction of the plane |
resti | : restitution coefficient |
height | : height of plane |
addToWindow | : if true, also adds graphics for the plane |
Definition at line 520 of file Simulation.cpp.
References Graphics3D::_drawList, _simulator, _window, DrawList::addCheckerboard(), DynamicsSimulator< T >::addCollisionPlane(), DrawList::buildDrawList(), Graphics3D::lockGfxMutex(), Graphics3D::unlockGfxMutex(), and DrawList::updateCheckerboard().
void Simulation::buildLcmMessage | ( | ) |
Definition at line 472 of file Simulation.cpp.
References _currentSimTime, FloatingBaseModel< T >::_footIndicesGC, _highLevelIterations, FloatingBaseModel< T >::_pGC, _simLCM, _simulator, _tau, DynamicsSimulator< T >::getContactForce(), DynamicsSimulator< T >::getDState(), DynamicsSimulator< T >::getModel(), DynamicsSimulator< T >::getState(), ori::quaternionToRotationMatrix(), and ori::quatToRPY().
void Simulation::firstRun | ( | ) |
Called before the simulator is run the first time. It's okay to put stuff in here that blocks on having the robot connected.
Definition at line 268 of file Simulation.cpp.
References _connected, ControlParameterCollection::_map, _robotMutex, _robotParams, _sharedMemory, _userParams, _wantStop, ControlParameters::collection, DO_NOTHING, and sendControlParameter().
|
inline |
Definition at line 108 of file Simulation.h.
References _robotParams.
|
inline |
Definition at line 94 of file Simulation.h.
References _simulator, and DynamicsSimulator< T >::getState().
|
inline |
Definition at line 106 of file Simulation.h.
References _simParams.
|
inline |
void Simulation::highLevelControl | ( | ) |
Definition at line 398 of file Simulation.cpp.
References _connected, _highLevelIterations, _imuSimulator, _lcm, _robot, _robotMutex, _running, _sharedMemory, _simLCM, _simParams, _simulator, _spiCommand, _spiData, _tiBoards, _wantStop, _window, buildLcmMessage(), CHEETAH_3, TI_BoardControl::command, TI_BoardControl::data, Graphics3D::getDriverCommand(), DynamicsSimulator< T >::getDState(), DynamicsSimulator< T >::getState(), MINI_CHEETAH, RUN_CONTROLLER, SIM_LCM_NAME, ImuSimulator< T >::updateCheaterState(), and ImuSimulator< T >::updateVectornav().
|
inline |
Definition at line 111 of file Simulation.h.
References _connected, buildLcmMessage(), firstRun(), and loadTerrainFile().
void Simulation::loadTerrainFile | ( | const std::string & | terrainFileName, |
bool | addGraphics = true |
||
) |
Definition at line 638 of file Simulation.cpp.
References addCollisionBox(), addCollisionMesh(), addCollisionPlane(), ori::rpyToRotMat(), and step().
void Simulation::lowLevelControl | ( | ) |
Definition at line 360 of file Simulation.cpp.
References _robot, _simulator, _spiData, _spineBoards, _tiBoards, CHEETAH_3, TI_BoardControl::data, TiBoardData::dq, DynamicsSimulator< T >::getState(), MINI_CHEETAH, TiBoardData::q, FBModelState< T >::q, SpiData::q_abad, SpiData::q_hip, SpiData::q_knee, FBModelState< T >::qd, SpiData::qd_abad, SpiData::qd_hip, and SpiData::qd_knee.
|
inline |
Definition at line 81 of file Simulation.h.
References _currentSimTime, _timeOfNextHighLevelControl, and _timeOfNextLowLevelControl.
void Simulation::runAtSpeed | ( | bool | graphics = true | ) |
Runs the simulator in the current thread until the _running variable is set to false. Updates graphics at 60 fps if desired. Runs simulation at the desired speed
dt |
Definition at line 579 of file Simulation.cpp.
References _currentSimTime, _desiredSimSpeed, _running, _simParams, _wantStop, _window, f(), firstRun(), Timer::getSeconds(), Graphics3D::infoString, Graphics3D::IsPaused(), ControlParameters::lockMutex(), Timer::start(), step(), ControlParameters::unlockMutex(), updateGraphics(), and Graphics3D::wantTurbo().
void Simulation::sendControlParameter | ( | const std::string & | name, |
ControlParameterValue | value, | ||
ControlParameterValueKind | kind, | ||
bool | isUser | ||
) |
Definition at line 216 of file Simulation.cpp.
References _connected, _robotMutex, _running, _sharedMemory, _wantStop, ControlParameterRequest::name, ControlParameterResponse::name, ControlParameterRequest::parameterKind, ControlParameterResponse::parameterKind, ControlParameterRequest::requestKind, ControlParameterRequest::requestNumber, ControlParameterResponse::requestNumber, RUN_CONTROL_PARAMETERS, SET_ROBOT_PARAM_BY_NAME, SET_USER_PARAM_BY_NAME, ControlParameterRequest::toString(), and ControlParameterRequest::value.
|
inline |
Explicitly set the state of the robot
Definition at line 48 of file Simulation.h.
References _simulator, addCollisionBox(), addCollisionMesh(), addCollisionPlane(), highLevelControl(), lowLevelControl(), runAtSpeed(), sendControlParameter(), DynamicsSimulator< T >::setState(), step(), and updateGraphics().
void Simulation::step | ( | double | dt, |
double | dtLowLevelControl, | ||
double | dtHighLevelControl | ||
) |
Take a single timestep of dt seconds
Definition at line 305 of file Simulation.cpp.
References _actuatorModels, _currentSimTime, _robot, _simParams, _simulator, _spineBoards, _tau, _tiBoards, _timeOfNextHighLevelControl, _timeOfNextLowLevelControl, RobotHomingInfo< T >::active_flag, CHEETAH_3, DynamicsSimulator< T >::getState(), highLevelControl(), RobotHomingInfo< T >::kd_ang, RobotHomingInfo< T >::kd_lin, RobotHomingInfo< T >::kp_ang, RobotHomingInfo< T >::kp_lin, lowLevelControl(), MINI_CHEETAH, RobotHomingInfo< T >::position, FBModelState< T >::qd, RobotHomingInfo< T >::rpy, DynamicsSimulator< T >::setHoming(), and DynamicsSimulator< T >::step().
|
inline |
Definition at line 96 of file Simulation.h.
References _connected, _running, _sharedMemory, _wantStop, and EXIT.
void Simulation::updateGraphics | ( | ) |
Updates the graphics from the connected window
Definition at line 805 of file Simulation.cpp.
References _controllerRobotID, Graphics3D::_drawList, _robotControllerState, _robotDataSimulator, _sharedMemory, _simRobotID, _simulator, _window, FBModelState< T >::bodyOrientation, FBModelState< T >::bodyPosition, DynamicsSimulator< T >::forwardKinematics(), FBModelState< T >::q, DynamicsSimulator< T >::setState(), DrawList::updateAdditionalInfo(), and DrawList::updateRobotFromModel().
|
private |
Definition at line 135 of file Simulation.h.
|
private |
Definition at line 143 of file Simulation.h.
|
private |
Definition at line 126 of file Simulation.h.
|
private |
Definition at line 146 of file Simulation.h.
|
private |
Definition at line 145 of file Simulation.h.
|
private |
Definition at line 149 of file Simulation.h.
|
private |
Definition at line 121 of file Simulation.h.
|
private |
Definition at line 141 of file Simulation.h.
|
private |
Definition at line 130 of file Simulation.h.
|
private |
Definition at line 128 of file Simulation.h.
|
private |
Definition at line 140 of file Simulation.h.
|
private |
Definition at line 129 of file Simulation.h.
|
private |
Definition at line 131 of file Simulation.h.
|
private |
Definition at line 134 of file Simulation.h.
|
private |
Definition at line 119 of file Simulation.h.
|
private |
Definition at line 124 of file Simulation.h.
|
private |
Definition at line 142 of file Simulation.h.
|
private |
Definition at line 120 of file Simulation.h.
|
private |
Definition at line 150 of file Simulation.h.
|
private |
Definition at line 122 of file Simulation.h.
|
private |
Definition at line 126 of file Simulation.h.
|
private |
Definition at line 133 of file Simulation.h.
|
private |
Definition at line 136 of file Simulation.h.
|
private |
Definition at line 137 of file Simulation.h.
|
private |
Definition at line 138 of file Simulation.h.
|
private |
Definition at line 132 of file Simulation.h.
|
private |
Definition at line 139 of file Simulation.h.
|
private |
Definition at line 148 of file Simulation.h.
|
private |
Definition at line 147 of file Simulation.h.
|
private |
Definition at line 123 of file Simulation.h.
|
private |
Definition at line 144 of file Simulation.h.
|
private |
Definition at line 127 of file Simulation.h.