##

ModelState.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GAZEBO_PHYSICS_MODELSTATE_HH_
#define GAZEBO_PHYSICS_MODELSTATE_HH_
#include <vector>
#include <string>
#include <boost/regex.hpp>
#include <ignition/math/Pose3.hh>
#include <ignition/math/Vector3.hh>
#include "gazebo/physics/State.hh"
#include "gazebo/physics/LinkState.hh"
#include "gazebo/physics/JointState.hh"
#include "gazebo/util/system.hh"
namespace gazebo
{
namespace physics
{
class GZ_PHYSICS_VISIBLE ModelState : public State
{
public: ModelState();
public: ModelState(const ModelPtr _model, const common::Time &_realTime,
const common::Time &_simTime, const uint64_t _iterations);
public: explicit ModelState(const ModelPtr _model);
public: explicit ModelState(const sdf::ElementPtr _sdf);
public: virtual ~ModelState();
public: void Load(const ModelPtr _model, const common::Time &_realTime,
const common::Time &_simTime, const uint64_t _iterations);
public: virtual void Load(const sdf::ElementPtr _elem);
public: const ignition::math::Pose3d &Pose() const;
public: const ignition::math::Vector3d &Scale() const;
public: bool IsZero() const;
public: unsigned int GetLinkStateCount() const;
public: LinkState_M GetLinkStates(const boost::regex &_regex) const;
public: JointState_M GetJointStates(const boost::regex &_regex) const;
public: LinkState GetLinkState(const std::string &_linkName) const;
public: bool HasLinkState(const std::string &_linkName) const;
public: const LinkState_M &GetLinkStates() const;
public: unsigned int GetJointStateCount() const;
public: JointState GetJointState(unsigned int _index) const;
public: JointState GetJointState(const std::string &_jointName) const;
public: const JointState_M &GetJointStates() const;
public: bool HasJointState(const std::string &_jointName) const;
public: unsigned int NestedModelStateCount() const;
public: ModelState NestedModelState(const std::string &_modelName) const;
public: bool HasNestedModelState(const std::string &_modelName) const;
public: const ModelState_M &NestedModelStates() const;
public: void FillSDF(sdf::ElementPtr _sdf);
public: virtual void SetWallTime(const common::Time &_time);
public: virtual void SetRealTime(const common::Time &_time);
public: virtual void SetSimTime(const common::Time &_time);
public: virtual void SetIterations(const uint64_t _iterations);
public: ModelState &operator=(const ModelState &_state);
public: ModelState operator-(const ModelState &_state) const;
public: ModelState operator+(const ModelState &_state) const;
public: inline friend std::ostream &operator<<(std::ostream &_out,
const gazebo::physics::ModelState &_state)
{
ignition::math::Vector3d euler(_state.pose.Rot().Euler());
_out.unsetf(std::ios_base::floatfield);
_out << std::setprecision(3)
<< "<model name='" << _state.GetName() << "'>"
<< "<pose>"
<< ignition::math::precision(_state.pose.Pos().X(), 4) << " "
<< ignition::math::precision(_state.pose.Pos().Y(), 4) << " "
<< ignition::math::precision(_state.pose.Pos().Z(), 4) << " "
<< ignition::math::precision(euler.X(), 4) << " "
<< ignition::math::precision(euler.Y(), 4) << " "
<< ignition::math::precision(euler.Z(), 4) << " "
<< "</pose>";
// Only record scale if it is not the default value of [1, 1, 1].
if (_state.scale != ignition::math::Vector3d::One)
_out << "<scale>" << _state.scale << "</scale>";
for (LinkState_M::const_iterator iter =
_state.linkStates.begin(); iter != _state.linkStates.end();
++iter)
{
_out << iter->second;
}
for (const auto &ms : _state.modelStates)
{
_out << ms.second;
}
// Output the joint information
// for (JointState_M::const_iterator iter =
// _state.jointStates.begin(); iter != _state.jointStates.end();
// ++iter)
// {
// _out << iter->second;
// }
_out << "</model>";
return _out;
}
private: ignition::math::Pose3d pose;
private: ignition::math::Vector3d scale;
private: LinkState_M linkStates;
private: JointState_M jointStates;
private: ModelState_M modelStates;
};
}
}
#endif
gazebo::physics::ModelState::NestedModelStateCount
unsigned int NestedModelStateCount() const
Get the number of model states.
gazebo::physics::ModelState::GetJointStateCount
unsigned int GetJointStateCount() const
Get the number of joint states.
gazebo::physics::ModelState::SetRealTime
virtual void SetRealTime(const common::Time &_time)
Set the real time when this state was generated.
gazebo::physics::ModelState_M
std::map< std::string, ModelState > ModelState_M
Definition: PhysicsTypes.hh:233
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::common::Time
A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec.
Definition: Time.hh:47
gazebo::physics::JointState
keeps track of state of a physics::Joint
Definition: JointState.hh:36
gazebo::physics::ModelPtr
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
gazebo::physics::ModelState::HasJointState
bool HasJointState(const std::string &_jointName) const
Return true if there is a joint with the specified name.
gazebo::physics::ModelState::GetLinkState
LinkState GetLinkState(const std::string &_linkName) const
Get a link state by Link name.
gazebo::physics::ModelState::NestedModelState
ModelState NestedModelState(const std::string &_modelName) const
Get a model state by model name.
gazebo::physics::ModelState::Pose
const ignition::math::Pose3d & Pose() const
Get the stored model pose.
gazebo::physics::ModelState::HasLinkState
bool HasLinkState(const std::string &_linkName) const
Return true if there is a link with the specified name.
system.hh
gazebo::physics::ModelState::operator=
ModelState & operator=(const ModelState &_state)
Assignment operator.
gazebo::physics::ModelState::IsZero
bool IsZero() const
Return true if the values in the state are zero.
gazebo::physics::LinkState
Store state information of a physics::Link object.
Definition: LinkState.hh:47
State.hh
gazebo::physics::ModelState::SetWallTime
virtual void SetWallTime(const common::Time &_time)
Set the wall time when this state was generated.
gazebo::physics::ModelState::Load
void Load(const ModelPtr _model, const common::Time &_realTime, const common::Time &_simTime, const uint64_t _iterations)
Load state from Model pointer.
gazebo::physics::State::GetName
std::string GetName() const
Get the name associated with this State.
gazebo::physics::ModelState::NestedModelStates
const ModelState_M & NestedModelStates() const
Get the nested model states.
gazebo::physics::ModelState::GetLinkStates
const LinkState_M & GetLinkStates() const
Get the link states.
gazebo::physics::ModelState::GetJointStates
const JointState_M & GetJointStates() const
Get the joint states.
gazebo::physics::ModelState
Store state information of a physics::Model object.
Definition: ModelState.hh:48
gazebo::physics::ModelState::FillSDF
void FillSDF(sdf::ElementPtr _sdf)
Populate a state SDF element with data from the object.
gazebo::physics::ModelState::GetJointState
JointState GetJointState(unsigned int _index) const
Get a Joint state.
LinkState.hh
gazebo::physics::State
State of an entity.
Definition: State.hh:43
gazebo::physics::ModelState::operator-
ModelState operator-(const ModelState &_state) const
Subtraction operator.
gazebo::physics::ModelState::~ModelState
virtual ~ModelState()
Destructor.
gazebo::physics::ModelState::HasNestedModelState
bool HasNestedModelState(const std::string &_modelName) const
Return true if there is a nested model with the specified name.
gazebo::physics::ModelState::SetIterations
virtual void SetIterations(const uint64_t _iterations)
Set the simulation iterations when this state was generated.
gazebo::physics::ModelState::ModelState
ModelState()
Default constructor.
gazebo::physics::JointState_M
std::map< std::string, JointState > JointState_M
Definition: PhysicsTypes.hh:245
gazebo::physics::ModelState::SetSimTime
virtual void SetSimTime(const common::Time &_time)
Set the sim time when this state was generated.
gazebo::physics::LinkState_M
std::map< std::string, LinkState > LinkState_M
Definition: PhysicsTypes.hh:241
gazebo::physics::ModelState::operator<<
friend std::ostream & operator<<(std::ostream &_out, const gazebo::physics::ModelState &_state)
Stream insertion operator.
Definition: ModelState.hh:243
gazebo::physics::ModelState::operator+
ModelState operator+(const ModelState &_state) const
Addition operator.
JointState.hh
gazebo::physics::ModelState::Scale
const ignition::math::Vector3d & Scale() const
Get the stored model scale.
gazebo::physics::ModelState::GetLinkStateCount
unsigned int GetLinkStateCount() const
Get the number of link states.