18 #if defined(MVSIM_HAS_ZMQ) && defined(MVSIM_HAS_PROTOBUF) 19 #include "TimeStampedPose.pb.h" 23 using namespace mvsim;
28 if (!m_b2d_body)
return;
31 m_b2d_body->SetTransform(
b2Vec2(m_q.x, m_q.y), m_q.yaw);
34 m_b2d_body->SetLinearVelocity(
b2Vec2(m_dq.vx, m_dq.vy));
35 m_b2d_body->SetAngularVelocity(m_dq.omega);
41 if (!m_b2d_body)
return;
46 const b2Vec2& pos = m_b2d_body->GetPosition();
55 const b2Vec2& vel = m_b2d_body->GetLinearVelocity();
56 const float32 w = m_b2d_body->GetAngularVelocity();
62 m_isInCollision =
false;
67 m_isInCollision =
true;
70 m_hadCollisionFlag = m_hadCollisionFlag || m_isInCollision;
75 internalHandlePublish(context);
79 [[maybe_unused]]
const mrpt::math::TVector2D& force,
86 std::shared_lock lck(m_q_mtx);
89 local_vel.
rotate(-m_q.yaw);
95 std::shared_lock lck(m_q_mtx);
97 return {m_q.x, m_q.y, m_q.yaw};
104 if (node ==
nullptr)
return false;
107 params[
"publish_pose_topic"] =
TParamEntry(
"%s", &publishPoseTopic_);
108 params[
"publish_pose_period"] =
TParamEntry(
"%lf", &publishPosePeriod_);
110 const std::map<std::string, std::string> varValues = {{
"NAME",
m_name}};
119 void Simulable::internalHandlePublish(
const TSimulContext& context)
121 std::shared_lock lck(m_q_mtx);
124 if (publishPoseTopic_.empty())
return;
129 if (tNow < publishPoseLastTime_ + publishPosePeriod_)
return;
131 publishPoseLastTime_ = tNow;
133 mvsim_msgs::TimeStampedPose msg;
134 msg.set_unixtimestamp(tNow);
137 auto pose = msg.mutable_pose();
141 pose->set_yaw(m_q.yaw);
142 pose->set_pitch(m_q.pitch);
143 pose->set_roll(m_q.roll);
145 client.publishTopic(publishPoseTopic_, msg);
154 #if defined(MVSIM_HAS_ZMQ) && defined(MVSIM_HAS_PROTOBUF) 156 if (!publishPoseTopic_.empty())
std::map< std::string, TParamEntry > TParameterDefinitions
void parse_xmlnode_children_as_param(const rapidxml::xml_node< char > &xml_node, const TParameterDefinitions ¶ms, const std::map< std::string, std::string > &variableNamesValues={}, const char *functionNameContext="")
mrpt::poses::CPose2D getCPose2D() const
Alternative to getPose()
GLubyte GLubyte GLubyte GLubyte w
mrpt::system::TTimeStamp now()
virtual void apply_force(const mrpt::math::TVector2D &force, const mrpt::math::TPoint2D &applyPoint=mrpt::math::TPoint2D(0, 0))
mrpt::math::TTwist2D getVelocityLocal() const
void rotate(const double ang)
virtual void registerOnServer(mvsim::Client &c)
virtual void simul_post_timestep(const TSimulContext &context)
virtual void simul_pre_timestep(const TSimulContext &context)
virtual void poses_mutex_unlock()=0
void advertiseTopic(const std::string &topicName)
virtual void poses_mutex_lock()=0
mvsim::Client & commsClient()