10 #include <mrpt/core/lock_helper.h> 13 #if MVSIM_HAS_ZMQ && MVSIM_HAS_PROTOBUF 14 #include <mvsim/mvsim-msgs/GenericAnswer.pb.h> 15 #include <mvsim/mvsim-msgs/SrvGetPose.pb.h> 16 #include <mvsim/mvsim-msgs/SrvGetPoseAnswer.pb.h> 17 #include <mvsim/mvsim-msgs/SrvSetControllerTwist.pb.h> 18 #include <mvsim/mvsim-msgs/SrvSetControllerTwistAnswer.pb.h> 19 #include <mvsim/mvsim-msgs/SrvSetPose.pb.h> 20 #include <mvsim/mvsim-msgs/SrvSetPoseAnswer.pb.h> 21 #include <mvsim/mvsim-msgs/SrvShutdown.pb.h> 22 #include <mvsim/mvsim-msgs/SrvShutdownAnswer.pb.h> 29 using namespace mvsim;
31 #if MVSIM_HAS_ZMQ && MVSIM_HAS_PROTOBUF 33 mvsim_msgs::SrvSetPoseAnswer World::srv_set_pose(
34 const mvsim_msgs::SrvSetPose& req)
36 mvsim_msgs::SrvSetPoseAnswer ans;
37 ans.set_objectisincollision(
false);
39 const auto sId = req.objectid();
44 if (req.has_relativeincrement() && req.relativeincrement())
46 auto p = mrpt::poses::CPose3D(itV->second->getPose());
47 p = p + mrpt::poses::CPose3D(
48 req.pose().x(), req.pose().y(), req.pose().z(),
49 req.pose().yaw(), req.pose().pitch(),
51 itV->second->setPose(p.asTPose());
53 auto* absPose = ans.mutable_objectglobalpose();
54 absPose->set_x(p.x());
55 absPose->set_y(p.y());
56 absPose->set_z(p.z());
57 absPose->set_yaw(p.yaw());
58 absPose->set_pitch(p.pitch());
59 absPose->set_roll(p.roll());
64 {req.pose().x(), req.pose().y(), req.pose().z(),
65 req.pose().yaw(), req.pose().pitch(), req.pose().roll()});
67 ans.set_success(
true);
68 ans.set_objectisincollision(itV->second->hadCollision());
69 itV->second->resetCollisionFlag();
73 ans.set_success(
false);
78 mvsim_msgs::SrvGetPoseAnswer World::srv_get_pose(
79 const mvsim_msgs::SrvGetPose& req)
83 mvsim_msgs::SrvGetPoseAnswer ans;
84 const auto sId = req.objectid();
85 ans.set_objectisincollision(
false);
90 ans.set_success(
true);
91 const mrpt::math::TPose3D p = itV->second;
92 auto* po = ans.mutable_pose();
97 po->set_pitch(p.pitch);
101 auto* tw = ans.mutable_twist();
109 ans.set_objectisincollision(
114 ans.set_success(
false);
126 mvsim_msgs::SrvSetControllerTwistAnswer World::srv_set_controller_twist(
127 const mvsim_msgs::SrvSetControllerTwist& req)
131 mvsim_msgs::SrvSetControllerTwistAnswer ans;
132 ans.set_success(
false);
134 const auto sId = req.objectid();
141 ans.set_errormessage(
"objectId not found");
145 auto veh = std::dynamic_pointer_cast<
VehicleBase>(itV->second);
148 ans.set_errormessage(
"objectId is not of VehicleBase type");
155 ans.set_errormessage(
156 "objectId vehicle seems not to have any controller");
160 const mrpt::math::TTwist2D
t(
161 req.twistsetpoint().vx(), req.twistsetpoint().vy(),
162 req.twistsetpoint().wz());
165 if (!ctrlAcceptTwist)
167 ans.set_errormessage(
168 "objectId vehicle controller did not accept the twist " 173 ans.set_success(
true);
177 mvsim_msgs::SrvShutdownAnswer World::srv_shutdown(
178 [[maybe_unused]]
const mvsim_msgs::SrvShutdown& req)
180 mvsim_msgs::SrvShutdownAnswer ans;
181 ans.set_accepted(
true);
188 #endif // MVSIM_HAS_ZMQ && MVSIM_HAS_PROTOBUF 192 #if MVSIM_HAS_ZMQ && MVSIM_HAS_PROTOBUF 196 "set_pose", [
this](
const auto& req) {
return srv_set_pose(req); });
200 "get_pose", [
this](
const auto& req) {
return srv_get_pose(req); });
203 mvsim_msgs::SrvSetControllerTwist,
204 mvsim_msgs::SrvSetControllerTwistAnswer>(
205 "set_controller_twist",
206 [
this](
const auto& req) {
return srv_set_controller_twist(req); });
209 mvsim_msgs::SrvShutdown, mvsim_msgs::SrvShutdownAnswer>(
210 "shutdown", [
this](
const auto& req) {
return srv_shutdown(req); });
bool simulator_must_close() const
SimulableList simulableObjects_
virtual bool setTwistCommand([[maybe_unused]] const mrpt::math::TTwist2D &t)
std::mutex simulationStepRunningMtx_
geometry_msgs::TransformStamped t
void advertiseService(const std::string &serviceName, const std::function< OUTPUT_MSG_T(const INPUT_MSG_T &)> &callback)
auto & getListOfSimulableObjectsMtx()
std::recursive_mutex copy_of_objects_dynstate_mtx_
void internal_advertiseServices()
std::map< std::string, mrpt::math::TPose3D > copy_of_objects_dynstate_pose_
Updated in internal_one_step()
std::set< std::string > copy_of_objects_had_collision_
std::mutex reset_collision_flags_mtx_
std::map< std::string, mrpt::math::TTwist2D > copy_of_objects_dynstate_twist_
std::set< std::string > reset_collision_flags_