Skip to content

Commit 09e14fd

Browse files
mats4cassava
authored andcommitted
models: Add brake, steering, wheel, and powertrain sensors
This just extends the package with extra components and is therefore backwards compatible
1 parent a745edc commit 09e14fd

File tree

6 files changed

+396
-0
lines changed

6 files changed

+396
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2022 Robert Bosch GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
*/
18+
/**
19+
* \file cloe/component/brake_sensor.hpp
20+
*/
21+
22+
#pragma once
23+
#ifndef CLOE_COMPONENT_BRAKE_SENSOR_HPP_
24+
#define CLOE_COMPONENT_BRAKE_SENSOR_HPP_
25+
26+
#include <cloe/component.hpp> // for Component, Json
27+
28+
namespace cloe {
29+
30+
class BrakeSensor : public Component {
31+
public:
32+
using Component::Component;
33+
BrakeSensor() : Component("brake_sensor") {}
34+
virtual ~BrakeSensor() noexcept = default;
35+
36+
/**
37+
* Return the position of the brake pedal with no unit.
38+
*
39+
* The range goes from 0 (unpressed) to 1 (fully pressed).
40+
*/
41+
virtual double pedal_position_brake() const = 0;
42+
43+
/**
44+
* Return sensor state as JSON.
45+
*/
46+
Json active_state() const override {
47+
return Json{{"pedal_position_brake", pedal_position_brake()}};
48+
}
49+
};
50+
51+
/**
52+
* NopBrakeSensor is an example no-op implementation of BrakeSensor.
53+
*/
54+
class NopBrakeSensor : public BrakeSensor {
55+
public:
56+
using BrakeSensor::BrakeSensor;
57+
NopBrakeSensor() : BrakeSensor("nop_brake_sensor") {}
58+
virtual ~NopBrakeSensor() noexcept {};
59+
60+
double pedal_position_brake() const override { return pedal_position_brake_; }
61+
62+
void reset() override { pedal_position_brake_ = 0.0; }
63+
64+
protected:
65+
double pedal_position_brake_{0.0};
66+
};
67+
68+
} // namespace cloe
69+
70+
#endif // CLOE_COMPONENT_BRAKE_SENSOR_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright 2022 Robert Bosch GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
*/
18+
/**
19+
* \file cloe/component/powertrain_sensor.hpp
20+
*/
21+
22+
#pragma once
23+
#ifndef CLOE_COMPONENT_POWERTRAIN_SENSOR_HPP_
24+
#define CLOE_COMPONENT_POWERTRAIN_SENSOR_HPP_
25+
26+
#include <cloe/component.hpp> // for Component, Json
27+
28+
namespace cloe {
29+
30+
class PowertrainSensor : public Component {
31+
public:
32+
using Component::Component;
33+
PowertrainSensor() : Component("powertrain_sensor") {}
34+
virtual ~PowertrainSensor() noexcept = default;
35+
36+
/**
37+
* Return the position of the acceleration pedal with no unit.
38+
*
39+
* The range goes from 0 (unpressed) to 1 (fully pressed).
40+
*/
41+
virtual double pedal_position_acceleration() const = 0;
42+
43+
/**
44+
* Return the gear transmission.
45+
*
46+
* The sign of this field is linked to the mode of the gear
47+
* - positive: driving forward (e.g. a value of 3 means the third gear in driving forward mode)
48+
* - 0: means that the gear lever is in neutral position
49+
* - negative: reverse mode (e.g. a value of -1 means the first gear in reverse mode)
50+
* - int max: means that the transmission is in parking position (can be accessed via std::numeric_limits<int>::max())
51+
*/
52+
virtual int gear_transmission() const = 0;
53+
54+
/**
55+
* Return sensor state as JSON.
56+
*/
57+
Json active_state() const override {
58+
return Json{
59+
{"pedal_position_acceleration", pedal_position_acceleration()},
60+
{"gear_transmission", gear_transmission()},
61+
};
62+
}
63+
};
64+
65+
/**
66+
* NopPowertrainSensor is an example no-op implementation of PowertrainSensor.
67+
*/
68+
class NopPowertrainSensor : public PowertrainSensor {
69+
public:
70+
using PowertrainSensor::PowertrainSensor;
71+
NopPowertrainSensor() : PowertrainSensor("nop_powertrain_sensor") {}
72+
virtual ~NopPowertrainSensor() noexcept {};
73+
74+
double pedal_position_acceleration() const override { return pedal_position_acceleration_; }
75+
76+
int gear_transmission() const override { return gear_transmission_; }
77+
78+
void reset() override {
79+
pedal_position_acceleration_ = 0.0;
80+
gear_transmission_ = 0;
81+
}
82+
83+
protected:
84+
double pedal_position_acceleration_{0.0};
85+
int gear_transmission_{0};
86+
};
87+
88+
} // namespace cloe
89+
90+
#endif // CLOE_COMPONENT_POWERTRAIN_SENSOR_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2022 Robert Bosch GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
*/
18+
/**
19+
* \file cloe/component/steering_sensor.hpp
20+
*/
21+
22+
#pragma once
23+
#ifndef CLOE_COMPONENT_STEERING_SENSOR_HPP_
24+
#define CLOE_COMPONENT_STEERING_SENSOR_HPP_
25+
26+
#include <cloe/component.hpp> // for Component, Json
27+
28+
namespace cloe {
29+
30+
class SteeringSensor : public Component {
31+
public:
32+
using Component::Component;
33+
SteeringSensor() : Component("steering_sensor") {}
34+
virtual ~SteeringSensor() noexcept = default;
35+
36+
/**
37+
* Return curvature of ego vehicle track in [1/m].
38+
*/
39+
virtual double curvature() const = 0;
40+
41+
/**
42+
* Return sensor state as JSON.
43+
*/
44+
Json active_state() const override {
45+
return Json{
46+
{"curvature", curvature()},
47+
};
48+
}
49+
};
50+
51+
/**
52+
* NopSteeringSensor is an example no-op implementation of SteeringSensor.
53+
*/
54+
class NopSteeringSensor : public SteeringSensor {
55+
public:
56+
using SteeringSensor::SteeringSensor;
57+
NopSteeringSensor() : SteeringSensor("nop_steering_sensor") {}
58+
virtual ~NopSteeringSensor() noexcept {};
59+
60+
double curvature() const override { return curvature_; }
61+
void reset() override { curvature_ = 0.0; }
62+
63+
protected:
64+
double curvature_{0.0};
65+
};
66+
67+
} // namespace cloe
68+
69+
#endif // CLOE_COMPONENT_STEERING_SENSOR_HPP_
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2022 Robert Bosch GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
*/
18+
/**
19+
* \file cloe/component/wheel.hpp
20+
*/
21+
22+
#pragma once
23+
#ifndef CLOE_COMPONENT_WHEEL_HPP_
24+
#define CLOE_COMPONENT_WHEEL_HPP_
25+
26+
#include <fable/json.hpp> // for to_json
27+
28+
namespace cloe {
29+
30+
struct Wheel {
31+
/// Rotational angle of wheel around y-axis in [rad].
32+
double rotation{0.0};
33+
34+
/// Translative velocity of the wheel in [m/s].
35+
double velocity{0.0};
36+
37+
/// Compression of the spring in [m].
38+
double spring_compression{0.0};
39+
40+
friend void to_json(Json& j, const Wheel& w) {
41+
j = Json{
42+
{"rotation", w.rotation},
43+
{"velocity", w.velocity},
44+
{"spring_compression", w.spring_compression},
45+
};
46+
}
47+
};
48+
49+
} // namespace cloe
50+
51+
#endif // CLOE_COMPONENT_WHEEL_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright 2022 Robert Bosch GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
*/
18+
/**
19+
* \file cloe/component/wheel_sensor.hpp
20+
*/
21+
22+
#pragma once
23+
#ifndef CLOE_COMPONENT_WHEEL_SENSOR_HPP_
24+
#define CLOE_COMPONENT_WHEEL_SENSOR_HPP_
25+
26+
#include <cloe/component.hpp> // for Component, Json
27+
#include <cloe/component/wheel.hpp> // for Wheel
28+
29+
namespace cloe {
30+
31+
class WheelSensor : public Component {
32+
public:
33+
using Component::Component;
34+
WheelSensor() : Component("wheel_sensor") {}
35+
virtual ~WheelSensor() noexcept = default;
36+
37+
/**
38+
* Return front left wheel.
39+
*/
40+
virtual Wheel wheel_fl() const = 0;
41+
42+
/**
43+
* Return front right wheel.
44+
*/
45+
virtual Wheel wheel_fr() const = 0;
46+
47+
/**
48+
* Return rear left wheel.
49+
*/
50+
virtual Wheel wheel_rl() const = 0;
51+
52+
/**
53+
* Return rear right wheel.
54+
*/
55+
virtual Wheel wheel_rr() const = 0;
56+
57+
/**
58+
* Return sensor state as JSON.
59+
*/
60+
Json active_state() const override {
61+
return Json{
62+
{"wheel_fl", wheel_fl()},
63+
{"wheel_fr", wheel_fr()},
64+
{"wheel_rl", wheel_rl()},
65+
{"wheel_rr", wheel_rr()},
66+
};
67+
}
68+
};
69+
70+
/**
71+
* NopWheelSensor is an example no-op implementation of WheelSensor.
72+
*/
73+
class NopWheelSensor : public WheelSensor {
74+
public:
75+
using WheelSensor::WheelSensor;
76+
NopWheelSensor() : WheelSensor("nop_wheel_sensor") {}
77+
virtual ~NopWheelSensor() noexcept {};
78+
79+
Wheel wheel_fl() const override { return wheel_fl_; };
80+
Wheel wheel_fr() const override { return wheel_fr_; };
81+
Wheel wheel_rl() const override { return wheel_rl_; };
82+
Wheel wheel_rr() const override { return wheel_rr_; };
83+
84+
void reset() override {
85+
wheel_fl_ = Wheel();
86+
wheel_fr_ = Wheel();
87+
wheel_rl_ = Wheel();
88+
wheel_rr_ = Wheel();
89+
}
90+
91+
protected:
92+
Wheel wheel_fl_{};
93+
Wheel wheel_fr_{};
94+
Wheel wheel_rl_{};
95+
Wheel wheel_rr_{};
96+
};
97+
98+
} // namespace cloe
99+
100+
#endif // CLOE_COMPONENT_WHEEL_SENSOR_HPP_

0 commit comments

Comments
 (0)