11 #include <mrpt/core/lock_helper.h> 12 #include <mrpt/kinematics/CVehicleSimul_DiffDriven.h> 13 #include <mrpt/kinematics/CVehicleSimul_Holo.h> 14 #include <mrpt/obs/CObservation2DRangeScan.h> 15 #include <mvsim/Comms/Client.h> 16 #include <mvsim/mvsim-msgs/GenericObservation.pb.h> 17 #include <mvsim/mvsim-msgs/SrvGetPose.pb.h> 18 #include <mvsim/mvsim-msgs/SrvGetPoseAnswer.pb.h> 19 #include <mvsim/mvsim-msgs/SrvSetControllerTwist.pb.h> 20 #include <mvsim/mvsim-msgs/SrvSetControllerTwistAnswer.pb.h> 46 MRPT_LOG_INFO(
"Connecting to mvsim server...");
49 connection_.subscribeTopic<mvsim_msgs::GenericObservation>(
51 [
this](
const mvsim_msgs::GenericObservation& o) {
onLidar(o); });
53 MRPT_LOG_INFO(
"Connected OK.");
59 mvsim_msgs::SrvGetPose req;
62 mvsim_msgs::SrvGetPoseAnswer ans;
70 vls.
pose.x = ans.pose().x();
71 vls.
pose.y = ans.pose().y();
72 vls.
pose.phi = ans.pose().yaw();
80 mvsim_msgs::SrvGetPose req;
83 mvsim_msgs::SrvGetPoseAnswer ans;
104 const std::optional<CVehicleVelCmd::Ptr>& immediate,
105 const std::optional<EnqueuedMotionCmd>& next)
override 107 if (next.has_value())
110 "Enqueued actions not implemented yet in this wrapper.");
112 if (!immediate.has_value())
121 mvsim_msgs::SrvSetControllerTwist req;
123 auto* tw = req.mutable_twistsetpoint();
128 if (
auto cmdDiff = std::dynamic_pointer_cast<
129 mrpt::kinematics::CVehicleVelCmd_DiffDriven>(immediate.value());
132 tw->set_vx(cmdDiff->lin_vel);
134 tw->set_wz(cmdDiff->ang_vel);
136 else if (
auto cmdHolo = std::dynamic_pointer_cast<
137 mrpt::kinematics::CVehicleVelCmd_Holo>(immediate.value());
140 tw->set_vx(cmdHolo->vel * std::cos(cmdHolo->dir_local));
141 tw->set_vy(cmdHolo->vel * std::sin(cmdHolo->dir_local));
142 tw->set_wz(cmdHolo->rot_speed);
146 MRPT_LOG_ERROR(
"Unhandled class received in motion_execute().");
150 mvsim_msgs::SrvSetControllerTwistAnswer ans;
151 connection_.callService(
"set_controller_twist", req, ans);
153 return ans.success();
177 void onLidar(
const mvsim_msgs::GenericObservation& o)
181 const std::vector<uint8_t> data(
182 o.mrptserializedobservation().begin(),
183 o.mrptserializedobservation().end());
185 mrpt::serialization::CSerializable::Ptr obj;
186 mrpt::serialization::OctetVectorToObject(data, obj);
188 auto lck = mrpt::lockHelper(lastLidarObsMtx_);
190 std::dynamic_pointer_cast<mrpt::obs::CObservation2DRangeScan>(
192 ASSERT_(lastLidarObs_);
197 catch (
const std::exception& e)
199 MRPT_LOG_ERROR_STREAM(e.what());
void stop([[maybe_unused]] const STOP_TYPE stopType) override
Definition: MVSIM_VehicleInterface.h:157
VehicleOdometryState get_odometry() override
Definition: MVSIM_VehicleInterface.h:78
Definition: VehicleOdometryState.h:18
std::mutex lastLidarObsMtx_
Definition: MVSIM_VehicleInterface.h:174
Definition: VehicleMotionInterface.h:52
Definition: bestTrajectory.h:15
mrpt::system::TTimeStamp timestamp
Definition: VehicleLocalizationState.h:33
bool valid
Definition: VehicleOdometryState.h:23
std::string robotName_
Definition: MVSIM_VehicleInterface.h:171
std::string lidarName_
Definition: MVSIM_VehicleInterface.h:172
mrpt::math::TTwist2D odometryVelocityLocal
Definition: VehicleOdometryState.h:33
MVSIM_VehicleInterface()
Definition: MVSIM_VehicleInterface.h:39
std::string frame_id
Definition: VehicleLocalizationState.h:46
mrpt::obs::CObservation2DRangeScan::Ptr lastLidarObs_
Definition: MVSIM_VehicleInterface.h:175
bool pendedActionExists
Definition: VehicleOdometryState.h:43
mvsim::Client connection_
Definition: MVSIM_VehicleInterface.h:170
Definition: LidarSource.h:13
mrpt::obs::CObservation2DRangeScan::Ptr last_lidar_obs() const override
Returns a copy of the last lidar observation.
Definition: MVSIM_VehicleInterface.h:163
bool valid
Definition: VehicleLocalizationState.h:25
STOP_TYPE
Definition: VehicleMotionInterface.h:20
mrpt::math::TPose2D pose
Definition: VehicleLocalizationState.h:29
bool motion_execute(const std::optional< CVehicleVelCmd::Ptr > &immediate, const std::optional< EnqueuedMotionCmd > &next) override
Definition: MVSIM_VehicleInterface.h:103
mrpt::system::TTimeStamp timestamp
Definition: VehicleOdometryState.h:37
void connect()
Definition: MVSIM_VehicleInterface.h:43
mrpt::math::TPose2D odometry
Definition: VehicleOdometryState.h:28
Definition: VehicleLocalizationState.h:20
void onLidar(const mvsim_msgs::GenericObservation &o)
Definition: MVSIM_VehicleInterface.h:177
Definition: MVSIM_VehicleInterface.h:34
VehicleLocalizationState get_localization() override
Definition: MVSIM_VehicleInterface.h:57