Skip to content

Commit

Permalink
models: Add brake, steering, wheel, and powertrain sensors
Browse files Browse the repository at this point in the history
This just extends the package with extra components and is therefore backwards compatible
  • Loading branch information
mats4 authored and cassava committed Oct 20, 2022
1 parent a745edc commit 09e14fd
Show file tree
Hide file tree
Showing 6 changed files with 396 additions and 0 deletions.
70 changes: 70 additions & 0 deletions models/include/cloe/component/brake_sensor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2022 Robert Bosch GmbH
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* \file cloe/component/brake_sensor.hpp
*/

#pragma once
#ifndef CLOE_COMPONENT_BRAKE_SENSOR_HPP_
#define CLOE_COMPONENT_BRAKE_SENSOR_HPP_

#include <cloe/component.hpp> // for Component, Json

namespace cloe {

class BrakeSensor : public Component {
public:
using Component::Component;
BrakeSensor() : Component("brake_sensor") {}
virtual ~BrakeSensor() noexcept = default;

/**
* Return the position of the brake pedal with no unit.
*
* The range goes from 0 (unpressed) to 1 (fully pressed).
*/
virtual double pedal_position_brake() const = 0;

/**
* Return sensor state as JSON.
*/
Json active_state() const override {
return Json{{"pedal_position_brake", pedal_position_brake()}};
}
};

/**
* NopBrakeSensor is an example no-op implementation of BrakeSensor.
*/
class NopBrakeSensor : public BrakeSensor {
public:
using BrakeSensor::BrakeSensor;
NopBrakeSensor() : BrakeSensor("nop_brake_sensor") {}
virtual ~NopBrakeSensor() noexcept {};

double pedal_position_brake() const override { return pedal_position_brake_; }

void reset() override { pedal_position_brake_ = 0.0; }

protected:
double pedal_position_brake_{0.0};
};

} // namespace cloe

#endif // CLOE_COMPONENT_BRAKE_SENSOR_HPP_
90 changes: 90 additions & 0 deletions models/include/cloe/component/powertrain_sensor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright 2022 Robert Bosch GmbH
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* \file cloe/component/powertrain_sensor.hpp
*/

#pragma once
#ifndef CLOE_COMPONENT_POWERTRAIN_SENSOR_HPP_
#define CLOE_COMPONENT_POWERTRAIN_SENSOR_HPP_

#include <cloe/component.hpp> // for Component, Json

namespace cloe {

class PowertrainSensor : public Component {
public:
using Component::Component;
PowertrainSensor() : Component("powertrain_sensor") {}
virtual ~PowertrainSensor() noexcept = default;

/**
* Return the position of the acceleration pedal with no unit.
*
* The range goes from 0 (unpressed) to 1 (fully pressed).
*/
virtual double pedal_position_acceleration() const = 0;

/**
* Return the gear transmission.
*
* The sign of this field is linked to the mode of the gear
* - positive: driving forward (e.g. a value of 3 means the third gear in driving forward mode)
* - 0: means that the gear lever is in neutral position
* - negative: reverse mode (e.g. a value of -1 means the first gear in reverse mode)
* - int max: means that the transmission is in parking position (can be accessed via std::numeric_limits<int>::max())
*/
virtual int gear_transmission() const = 0;

/**
* Return sensor state as JSON.
*/
Json active_state() const override {
return Json{
{"pedal_position_acceleration", pedal_position_acceleration()},
{"gear_transmission", gear_transmission()},
};
}
};

/**
* NopPowertrainSensor is an example no-op implementation of PowertrainSensor.
*/
class NopPowertrainSensor : public PowertrainSensor {
public:
using PowertrainSensor::PowertrainSensor;
NopPowertrainSensor() : PowertrainSensor("nop_powertrain_sensor") {}
virtual ~NopPowertrainSensor() noexcept {};

double pedal_position_acceleration() const override { return pedal_position_acceleration_; }

int gear_transmission() const override { return gear_transmission_; }

void reset() override {
pedal_position_acceleration_ = 0.0;
gear_transmission_ = 0;
}

protected:
double pedal_position_acceleration_{0.0};
int gear_transmission_{0};
};

} // namespace cloe

#endif // CLOE_COMPONENT_POWERTRAIN_SENSOR_HPP_
69 changes: 69 additions & 0 deletions models/include/cloe/component/steering_sensor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2022 Robert Bosch GmbH
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* \file cloe/component/steering_sensor.hpp
*/

#pragma once
#ifndef CLOE_COMPONENT_STEERING_SENSOR_HPP_
#define CLOE_COMPONENT_STEERING_SENSOR_HPP_

#include <cloe/component.hpp> // for Component, Json

namespace cloe {

class SteeringSensor : public Component {
public:
using Component::Component;
SteeringSensor() : Component("steering_sensor") {}
virtual ~SteeringSensor() noexcept = default;

/**
* Return curvature of ego vehicle track in [1/m].
*/
virtual double curvature() const = 0;

/**
* Return sensor state as JSON.
*/
Json active_state() const override {
return Json{
{"curvature", curvature()},
};
}
};

/**
* NopSteeringSensor is an example no-op implementation of SteeringSensor.
*/
class NopSteeringSensor : public SteeringSensor {
public:
using SteeringSensor::SteeringSensor;
NopSteeringSensor() : SteeringSensor("nop_steering_sensor") {}
virtual ~NopSteeringSensor() noexcept {};

double curvature() const override { return curvature_; }
void reset() override { curvature_ = 0.0; }

protected:
double curvature_{0.0};
};

} // namespace cloe

#endif // CLOE_COMPONENT_STEERING_SENSOR_HPP_
51 changes: 51 additions & 0 deletions models/include/cloe/component/wheel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2022 Robert Bosch GmbH
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* \file cloe/component/wheel.hpp
*/

#pragma once
#ifndef CLOE_COMPONENT_WHEEL_HPP_
#define CLOE_COMPONENT_WHEEL_HPP_

#include <fable/json.hpp> // for to_json

namespace cloe {

struct Wheel {
/// Rotational angle of wheel around y-axis in [rad].
double rotation{0.0};

/// Translative velocity of the wheel in [m/s].
double velocity{0.0};

/// Compression of the spring in [m].
double spring_compression{0.0};

friend void to_json(Json& j, const Wheel& w) {
j = Json{
{"rotation", w.rotation},
{"velocity", w.velocity},
{"spring_compression", w.spring_compression},
};
}
};

} // namespace cloe

#endif // CLOE_COMPONENT_WHEEL_HPP_
100 changes: 100 additions & 0 deletions models/include/cloe/component/wheel_sensor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright 2022 Robert Bosch GmbH
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* \file cloe/component/wheel_sensor.hpp
*/

#pragma once
#ifndef CLOE_COMPONENT_WHEEL_SENSOR_HPP_
#define CLOE_COMPONENT_WHEEL_SENSOR_HPP_

#include <cloe/component.hpp> // for Component, Json
#include <cloe/component/wheel.hpp> // for Wheel

namespace cloe {

class WheelSensor : public Component {
public:
using Component::Component;
WheelSensor() : Component("wheel_sensor") {}
virtual ~WheelSensor() noexcept = default;

/**
* Return front left wheel.
*/
virtual Wheel wheel_fl() const = 0;

/**
* Return front right wheel.
*/
virtual Wheel wheel_fr() const = 0;

/**
* Return rear left wheel.
*/
virtual Wheel wheel_rl() const = 0;

/**
* Return rear right wheel.
*/
virtual Wheel wheel_rr() const = 0;

/**
* Return sensor state as JSON.
*/
Json active_state() const override {
return Json{
{"wheel_fl", wheel_fl()},
{"wheel_fr", wheel_fr()},
{"wheel_rl", wheel_rl()},
{"wheel_rr", wheel_rr()},
};
}
};

/**
* NopWheelSensor is an example no-op implementation of WheelSensor.
*/
class NopWheelSensor : public WheelSensor {
public:
using WheelSensor::WheelSensor;
NopWheelSensor() : WheelSensor("nop_wheel_sensor") {}
virtual ~NopWheelSensor() noexcept {};

Wheel wheel_fl() const override { return wheel_fl_; };
Wheel wheel_fr() const override { return wheel_fr_; };
Wheel wheel_rl() const override { return wheel_rl_; };
Wheel wheel_rr() const override { return wheel_rr_; };

void reset() override {
wheel_fl_ = Wheel();
wheel_fr_ = Wheel();
wheel_rl_ = Wheel();
wheel_rr_ = Wheel();
}

protected:
Wheel wheel_fl_{};
Wheel wheel_fr_{};
Wheel wheel_rl_{};
Wheel wheel_rr_{};
};

} // namespace cloe

#endif // CLOE_COMPONENT_WHEEL_SENSOR_HPP_
Loading

0 comments on commit 09e14fd

Please sign in to comment.