Skip to content

Commit 40d128e

Browse files
mats4cassava
authored andcommitted
models: Add gearbox, pedal and steering actuator.
This extends the package with extra components and is therefore backwards compatible.
1 parent 91ba06b commit 40d128e

12 files changed

+536
-27
lines changed

engine/src/plugins/nop_simulator.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@
2929

3030
#include <cloe/component/brake_sensor.hpp> // for NopBrakeSensor
3131
#include <cloe/component/ego_sensor.hpp> // for NopEgoSensor
32+
#include <cloe/component/gearbox_actuator.hpp> // for GearboxActuator
3233
#include <cloe/component/lane_sensor.hpp> // for NopLaneSensor
3334
#include <cloe/component/latlong_actuator.hpp> // for LatLongActuator
3435
#include <cloe/component/object_sensor.hpp> // for NopObjectSensor
36+
#include <cloe/component/pedal_actuator.hpp> // for PedalActuator
3537
#include <cloe/component/powertrain_sensor.hpp> // for NopPowertrainSensor
38+
#include <cloe/component/steering_actuator.hpp> // for SteeringActuator
3639
#include <cloe/component/steering_sensor.hpp> // for NopSteeringSensor
3740
#include <cloe/component/wheel_sensor.hpp> // for NopWheelSensor
3841
#include <cloe/handler.hpp> // for ToJson
@@ -68,6 +71,12 @@ struct NopVehicle : public Vehicle {
6871
CloeComponent::DEFAULT_WORLD_SENSOR);
6972
this->new_component(new LatLongActuator(),
7073
CloeComponent::DEFAULT_LATLONG_ACTUATOR);
74+
this->new_component(new GearboxActuator(),
75+
CloeComponent::DEFAULT_GEARBOX_ACTUATOR);
76+
this->new_component(new PedalActuator(),
77+
CloeComponent::DEFAULT_PEDAL_ACTUATOR);
78+
this->new_component(new SteeringActuator(),
79+
CloeComponent::DEFAULT_STEERING_ACTUATOR);
7180
this->new_component(new NopLaneSensor(),
7281
CloeComponent::GROUNDTRUTH_LANE_SENSOR,
7382
CloeComponent::DEFAULT_LANE_SENSOR);

models/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_library(${target}
1717
# find src -type f -name "*.cpp" \! -name "*_test.cpp"
1818
src/cloe/component/lane_boundary.cpp
1919
src/cloe/component/utility/ego_sensor_canon.cpp
20+
src/cloe/component/utility/steering_utils.cpp
2021
src/cloe/utility/actuation_state.cpp
2122
)
2223
add_library(${alias} ALIAS ${target})
@@ -46,7 +47,9 @@ if(BuildTests)
4647

4748
add_executable(test-models
4849
# find src -type f -name "*_test.cpp"
50+
src/cloe/component/gearbox_actuator_test.cpp
4951
src/cloe/component/latlong_actuator_test.cpp
52+
src/cloe/component/utility/steering_utils_test.cpp
5053
src/cloe/utility/actuation_level_test.cpp
5154
)
5255
set_target_properties(test-models PROPERTIES
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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/actuator.hpp
20+
*/
21+
22+
#pragma once
23+
#ifndef CLOE_COMPONENT_ACTUATOR_HPP_
24+
#define CLOE_COMPONENT_ACTUATOR_HPP_
25+
26+
#include <boost/optional.hpp> // for optional
27+
#include <cloe/component.hpp> // for Component
28+
#include <fable/json.hpp> // for Json
29+
30+
namespace cloe {
31+
32+
template <typename T = double>
33+
class Actuator : public Component {
34+
public:
35+
using Component::Component;
36+
virtual ~Actuator() noexcept = default;
37+
38+
virtual void set(T a) { target_ = a; }
39+
virtual bool is_set() { return static_cast<bool>(target_); }
40+
virtual T get() { return *target_; }
41+
42+
Json active_state() const override { return Json{{"target", target_}}; }
43+
44+
Duration process(const Sync& sync) override {
45+
auto t = Component::process(sync);
46+
target_.reset();
47+
return t;
48+
}
49+
50+
void reset() override {
51+
Component::reset();
52+
target_.reset();
53+
}
54+
55+
protected:
56+
boost::optional<T> target_;
57+
};
58+
59+
} // namespace cloe
60+
61+
#endif // CLOE_COMPONENT_ACTUATOR_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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/gearbox_actuator.hpp
20+
*/
21+
22+
#pragma once
23+
#ifndef CLOE_COMPONENT_GEARBOX_ACTUATOR_HPP_
24+
#define CLOE_COMPONENT_GEARBOX_ACTUATOR_HPP_
25+
26+
#include <cloe/component/actuator.hpp> // for Actuator
27+
#include <fable/json.hpp> // for Json
28+
29+
namespace cloe {
30+
31+
struct GearboxRequest {
32+
/*
33+
* Holds the requested gear selector position.
34+
*
35+
* The sign of this field is linked to the mode of the gear
36+
* - positive: driving forward (e.g. a value of 3 means to request the third gear in driving forward mode)
37+
* - 0: means that the gear lever is requested to be in neutral position
38+
* - negative: reverse mode (e.g. a value of -1 means the first gear in reverse mode is requested)
39+
* - int8_t max: means that the transmission is in parking position (can be accessed via std::numeric_limits<int8_t>::max())
40+
*/
41+
int8_t gear_selector{0};
42+
43+
friend void to_json(Json& j, const GearboxRequest& g) {
44+
j = Json{{"gear_selector", g.gear_selector}};
45+
}
46+
};
47+
48+
class GearboxActuator : public Actuator<GearboxRequest> {
49+
public:
50+
using Actuator::Actuator;
51+
GearboxActuator() : Actuator("gearbox_actuator") {}
52+
virtual ~GearboxActuator() noexcept = default;
53+
};
54+
55+
} // namespace cloe
56+
57+
#endif // CLOE_COMPONENT_GEARBOX_ACTUATOR_HPP_

models/include/cloe/component/latlong_actuator.hpp

+1-27
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <fable/json/with_boost.hpp> // for to_json
3131

3232
#include <cloe/component.hpp> // for Component, Json
33+
#include <cloe/component/actuator.hpp> // for Actuator
3334
#include <cloe/utility/actuation_level.hpp> // for ActuationLevel
3435

3536
namespace cloe {
@@ -116,33 +117,6 @@ class LatLongActuator : public Component {
116117
boost::optional<double> target_steering_angle_;
117118
};
118119

119-
template <typename T = double>
120-
class Actuator : public Component {
121-
public:
122-
using Component::Component;
123-
virtual ~Actuator() noexcept = default;
124-
125-
virtual void set(T a) { target_ = a; }
126-
virtual bool is_set() { return static_cast<bool>(target_); }
127-
virtual T get() { return *target_; }
128-
129-
Json active_state() const override { return Json{"target", target_}; }
130-
131-
Duration process(const Sync& sync) override {
132-
auto t = Component::process(sync);
133-
target_.reset();
134-
return t;
135-
}
136-
137-
void reset() override {
138-
Component::reset();
139-
target_.reset();
140-
}
141-
142-
protected:
143-
boost::optional<T> target_;
144-
};
145-
146120
class LongActuator : public Actuator<double> {
147121
public:
148122
using Actuator::Actuator;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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/pedal_actuator.hpp
20+
*/
21+
22+
#pragma once
23+
#ifndef CLOE_COMPONENT_PEDAL_ACTUATOR_HPP_
24+
#define CLOE_COMPONENT_PEDAL_ACTUATOR_HPP_
25+
26+
#include <cloe/component/actuator.hpp> // for Actuator
27+
#include <fable/json.hpp> // for Json
28+
29+
namespace cloe {
30+
31+
struct PedalRequest {
32+
/*
33+
* Requested status of the gas pedal with no unit.
34+
*
35+
* The range goes from 0 (unpressed) to 1 (fully pressed).
36+
*/
37+
double gas_pedal_position{0.0};
38+
39+
/*
40+
* Requested status of the brake pedal with no unit.
41+
*
42+
* The range goes from 0 (unpressed) to 1 (fully pressed).
43+
*/
44+
double brake_pedal_position{0.0};
45+
46+
friend void to_json(Json& j, const PedalRequest& p) {
47+
j = Json{
48+
{"gas_pedal_position", p.gas_pedal_position},
49+
{"brake_pedal_position", p.brake_pedal_position},
50+
};
51+
}
52+
};
53+
54+
class PedalActuator : public Actuator<PedalRequest> {
55+
public:
56+
using Actuator::Actuator;
57+
PedalActuator() : Actuator("pedal_actuator") {}
58+
virtual ~PedalActuator() noexcept = default;
59+
};
60+
61+
} // namespace cloe
62+
63+
#endif // CLOE_COMPONENT_PEDAL_ACTUATOR_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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_actuator.hpp
20+
*/
21+
22+
#pragma once
23+
#ifndef CLOE_COMPONENT_STEERING_ACTUATOR_HPP_
24+
#define CLOE_COMPONENT_STEERING_ACTUATOR_HPP_
25+
26+
#include <cloe/component/actuator.hpp> // for Actuator
27+
#include <fable/json.hpp> // for Json
28+
29+
namespace cloe {
30+
31+
struct SteeringRequest {
32+
/**
33+
* Front center wheel angle with regards to z-Axis in [radians].
34+
*/
35+
double steering_angle_front{0.0};
36+
37+
/**
38+
* Rear center wheel angle with regards to z-Axis in [radians].
39+
*/
40+
double steering_angle_rear{0.0};
41+
42+
friend void to_json(Json& j, const SteeringRequest& s) {
43+
j = Json{
44+
{"steering_angle_front", s.steering_angle_front},
45+
{"steering_angle_rear", s.steering_angle_rear},
46+
};
47+
}
48+
};
49+
50+
class SteeringActuator : public Actuator<SteeringRequest> {
51+
public:
52+
using Actuator::Actuator;
53+
SteeringActuator() : Actuator("steering_actuator") {}
54+
virtual ~SteeringActuator() noexcept = default;
55+
};
56+
57+
} // namespace cloe
58+
59+
#endif // CLOE_COMPONENT_STEERING_ACTUATOR_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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/utility/steering_utils.hpp
20+
*/
21+
22+
#pragma once
23+
#ifndef CLOE_COMPONENT_UTILITY_STEERING_UTILS_HPP_
24+
#define CLOE_COMPONENT_UTILITY_STEERING_UTILS_HPP_
25+
26+
namespace cloe {
27+
namespace utility {
28+
29+
struct Geometry {
30+
/// Distance between the front and the rear axle in [m].
31+
double wheel_base{0.0};
32+
33+
/// Distance between the left wheel and the right wheel in [m].
34+
double track_base{0.0};
35+
};
36+
37+
enum class WheelId : unsigned int { FrontLeft = 0, FrontRight, RearLeft, RearRight };
38+
39+
/**
40+
* This function translates a steering angle from the center of the axle to the individual steering angle of a wheel.
41+
*
42+
* This function is based on the Ackermann steering geometry, see [https://en.wikipedia.org/wiki/Ackermann_steering_geometry, accessed 28.10.2022]
43+
* The calculation only works for the following assumptions, as it assumes that the centre of rotation is on the same level with the rear wheels:
44+
* - low speed
45+
* - no rear steering
46+
* Detailed explanations can be found in basic vehicle dynamics literature, e.g. chapter 4.2 of the Steering Handbook
47+
* by Harrer and Pfeffer [https://link.springer.com/book/10.1007/978-3-319-05449-0]
48+
*
49+
* The function needs a wheel_base, a track_base (both stored in Geometry), the wheel_id and the steering_angle in the center of the axle.
50+
* The wheel_id is the ID you want to calculate the angle for, i.e. either FrontLeft or FrontRight.
51+
* The function returns the value of the steering_angle of the requested wheel.
52+
*/
53+
double calculate_wheel_angle(const Geometry& geometry, WheelId wheel_id, double steering_angle);
54+
55+
} // namespace utility
56+
} // namespace cloe
57+
58+
#endif // CLOE_COMPONENT_UTILITY_STEERING_UTILS_HPP_

0 commit comments

Comments
 (0)