-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathOdometer.hh
More file actions
68 lines (57 loc) · 2.32 KB
/
Odometer.hh
File metadata and controls
68 lines (57 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright (C) 2021 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 ODOMETER_HH_
#define ODOMETER_HH_
#include <ignition/sensors/Sensor.hh>
#include <ignition/sensors/SensorTypes.hh>
#include <ignition/transport/Node.hh>
namespace custom
{
/// \brief Example sensor that publishes the total distance travelled by a
/// robot, with noise.
class Odometer : public ignition::sensors::Sensor
{
/// \brief Load the sensor with SDF parameters.
/// \param[in] _sdf SDF Sensor parameters.
/// \return True if loading was successful
public: virtual bool Load(const sdf::Sensor &_sdf) override;
/// \brief Update the sensor and generate data
/// \param[in] _now The current time
/// \return True if the update was successfull
public: virtual bool Update(
const std::chrono::steady_clock::duration &_now) override;
/// \brief Set the current postiion of the robot, so the odometer can
/// calculate the distance travelled.
/// \param[in] _pos Current position in world coordinates.
public: void NewPosition(const ignition::math::Vector3d &_pos);
/// \brief Get the latest world postiion of the robot.
/// \return The latest position given to the odometer.
public: const ignition::math::Vector3d &Position() const;
/// \brief Previous position of the robot.
private: ignition::math::Vector3d prevPos{std::nan(""), std::nan(""),
std::nan("")};
/// \brief Latest total distance.
private: double totalDistance{0.0};
/// \brief Noise that will be applied to the sensor data
private: ignition::sensors::NoisePtr noise{nullptr};
/// \brief Node for communication
private: ignition::transport::Node node;
/// \brief Publishes sensor data
private: ignition::transport::Node::Publisher pub;
};
}
#endif