Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
modules
simulator
include
mvsim
Simulable.h
Go to the documentation of this file.
1
/*+-------------------------------------------------------------------------+
2
| MultiVehicle simulator (libmvsim) |
3
| |
4
| Copyright (C) 2014-2020 Jose Luis Blanco Claraco |
5
| Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6
| Distributed under 3-clause BSD License |
7
| See COPYING |
8
+-------------------------------------------------------------------------+ */
9
10
#pragma once
11
12
#include <
Box2D/Dynamics/b2Body.h
>
13
#include <mrpt/math/TPoint2D.h>
14
#include <mrpt/math/TPose3D.h>
15
#include <
mrpt/poses/CPose2D.h
>
16
#include <
mvsim/basic_types.h
>
17
18
#include <shared_mutex>
19
20
namespace
mvsim
21
{
22
class
Client
;
23
24
class
Simulable
25
{
26
public
:
27
using
Ptr
= std::shared_ptr<Simulable>;
28
31
virtual
void
simul_pre_timestep
(
const
TSimulContext
& context);
32
38
virtual
void
simul_post_timestep
(
const
TSimulContext
& context);
39
40
virtual
void
poses_mutex_lock
() = 0;
41
virtual
void
poses_mutex_unlock
() = 0;
42
46
virtual
void
apply_force
(
47
const
mrpt::math::TVector2D& force,
48
const
mrpt::math::TPoint2D
& applyPoint =
mrpt::math::TPoint2D
(0, 0));
49
51
mrpt::math::TTwist2D
getVelocityLocal
()
const
;
52
55
mrpt::math::TPose3D
getPose
()
const
56
{
57
m_q_mtx.lock_shared();
58
mrpt::math::TPose3D
ret = m_q;
59
m_q_mtx.unlock_shared();
60
return
ret;
61
}
62
63
mrpt::math::TTwist2D
getTwist
()
const
64
{
65
m_q_mtx.lock_shared();
66
mrpt::math::TTwist2D
ret = m_dq;
67
m_q_mtx.unlock_shared();
68
return
ret;
69
}
70
73
void
setPose
(
const
mrpt::math::TPose3D
&
p
)
const
74
{
75
m_q_mtx.lock();
76
const_cast<
mrpt::math::TPose3D
&
>
(m_q) = p;
77
m_q_mtx.unlock();
78
}
79
80
void
setTwist
(
const
mrpt::math::TTwist2D
& dq)
const
81
{
82
m_q_mtx.lock();
83
const_cast<
mrpt::math::TTwist2D
&
>
(m_dq) = dq;
84
m_q_mtx.unlock();
85
}
86
88
mrpt::poses::CPose2D
getCPose2D
()
const
;
89
92
const
mrpt::math::TTwist2D
&
getVelocity
()
const
{
return
m_dq; }
93
95
const
std::string&
getName
()
const
{
return
m_name
; }
96
98
void
setName
(
const
std::string&
s
) {
m_name
= s; }
99
101
bool
isInCollision
()
const
{
return
m_isInCollision; }
102
106
bool
hadCollision
()
const
{
return
m_hadCollisionFlag; }
107
109
void
resetCollisionFlag
() { m_hadCollisionFlag =
false
; }
110
111
virtual
void
registerOnServer
(
mvsim::Client
&
c
);
112
113
const
b2Body
*
b2d_body
()
const
{
return
m_b2d_body; }
114
b2Body
*
b2d_body
() {
return
m_b2d_body; }
115
116
protected
:
118
std::string
m_name
;
119
125
b2Body
* m_b2d_body =
nullptr
;
126
127
bool
parseSimulable(
const
rapidxml::xml_node<char>
* node);
128
129
void
internalHandlePublish(
const
TSimulContext
& context);
130
131
private
:
133
mutable
std::shared_mutex m_q_mtx;
134
136
mrpt::math::TPose3D
m_q = mrpt::math::TPose3D::Identity();
137
139
mrpt::math::TTwist2D
m_dq{0, 0, 0};
140
142
bool
m_isInCollision =
false
;
143
146
bool
m_hadCollisionFlag =
false
;
147
149
std::string publishPoseTopic_;
150
double
publishPosePeriod_ = 100e-3;
151
double
publishPoseLastTime_ = 0;
152
};
153
}
// namespace mvsim
CPose2D.h
mrpt::poses::CPose2D
mvsim::Simulable::setTwist
void setTwist(const mrpt::math::TTwist2D &dq) const
Definition:
Simulable.h:80
mvsim::Simulable::isInCollision
bool isInCollision() const
Definition:
Simulable.h:101
mvsim::Simulable
Definition:
Simulable.h:24
b2Body.h
mvsim::Simulable::setPose
void setPose(const mrpt::math::TPose3D &p) const
Definition:
Simulable.h:73
mvsim::Simulable::Ptr
std::shared_ptr< Simulable > Ptr
Definition:
Simulable.h:27
mvsim
mrpt::math::TTwist2D
mvsim::Client
Definition:
Client.h:47
mvsim::Simulable::b2d_body
b2Body * b2d_body()
Definition:
Simulable.h:114
c
const GLfloat * c
mvsim::Simulable::getCPose2D
mrpt::poses::CPose2D getCPose2D() const
Alternative to getPose()
Definition:
Simulable.cpp:93
mvsim::Simulable::apply_force
virtual void apply_force(const mrpt::math::TVector2D &force, const mrpt::math::TPoint2D &applyPoint=mrpt::math::TPoint2D(0, 0))
Definition:
Simulable.cpp:78
mvsim::Simulable::getPose
mrpt::math::TPose3D getPose() const
Definition:
Simulable.h:55
mvsim::TSimulContext
Definition:
basic_types.h:56
basic_types.h
mrpt::math::TPose3D
s
GLdouble s
b2Body
A rigid body. These are created via b2World::CreateBody.
Definition:
b2Body.h:126
mvsim::Simulable::getName
const std::string & getName() const
Definition:
Simulable.h:95
mvsim::Simulable::getVelocityLocal
mrpt::math::TTwist2D getVelocityLocal() const
Definition:
Simulable.cpp:84
p
GLfloat GLfloat p
mvsim::Simulable::setName
void setName(const std::string &s)
Definition:
Simulable.h:98
mvsim::Simulable::registerOnServer
virtual void registerOnServer(mvsim::Client &c)
Definition:
Simulable.cpp:150
actionlib::SimpleActionClient< actionlib::TestAction >
mvsim::Simulable::simul_post_timestep
virtual void simul_post_timestep(const TSimulContext &context)
Definition:
Simulable.cpp:38
mvsim::Simulable::simul_pre_timestep
virtual void simul_pre_timestep(const TSimulContext &context)
Definition:
Simulable.cpp:25
mvsim::Simulable::poses_mutex_unlock
virtual void poses_mutex_unlock()=0
mvsim::Simulable::getVelocity
const mrpt::math::TTwist2D & getVelocity() const
Definition:
Simulable.h:92
mvsim::Simulable::resetCollisionFlag
void resetCollisionFlag()
Definition:
Simulable.h:109
mvsim::Simulable::poses_mutex_lock
virtual void poses_mutex_lock()=0
mrpt::math::TPoint2D
mvsim::Simulable::hadCollision
bool hadCollision() const
Definition:
Simulable.h:106
rapidxml::xml_node
Definition:
rapidxml.hpp:137
mvsim::Simulable::m_name
std::string m_name
Definition:
Simulable.h:118
mvsim::Simulable::b2d_body
const b2Body * b2d_body() const
Definition:
Simulable.h:113
mvsim::Simulable::getTwist
mrpt::math::TTwist2D getTwist() const
Definition:
Simulable.h:63
mvsim
Author(s):
autogenerated on Fri May 7 2021 03:05:51