Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Airflow/Wind sensor #2256

Open
wants to merge 7 commits into
base: gz-sim7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ gz_find_package(gz-sensors7 REQUIRED VERSION 7.1
# component order is important
COMPONENTS
# non-rendering
air_flow
air_pressure
air_speed
altimeter
Expand Down
21 changes: 21 additions & 0 deletions examples/worlds/sensors.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,27 @@
</vertical_velocity>
</altimeter>
</sensor>
<sensor name="air_flow" type="air_flow">
<always_on>1</always_on>
<update_rate>10</update_rate>
<visualize>true</visualize>
<topic>air_flow</topic>
<enable_metrics>true</enable_metrics>
<air_flow>
<speed>
<noise type="gaussian">
<mean>0.2</mean>
<stddev>0.1</stddev>
</noise>
</speed>
<direction>
<noise type="gaussian">
<mean>0.2</mean>
<stddev>0.1</stddev>
</noise>
</direction>
</air_flow>
</sensor>
<sensor name="air_pressure" type="air_pressure">
<always_on>1</always_on>
<update_rate>30</update_rate>
Expand Down
46 changes: 46 additions & 0 deletions include/gz/sim/components/AirFlowSensor.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2023 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 GZ_SIM_COMPONENTS_AIRFLOW_HH_
#define GZ_SIM_COMPONENTS_AIRFLOW_HH_

#include <sdf/Sensor.hh>

#include <gz/sim/components/Factory.hh>
#include <gz/sim/components/Component.hh>
#include <gz/sim/components/Serialization.hh>
#include <gz/sim/config.hh>

namespace gz
{
namespace sim
{
// Inline bracket to help doxygen filtering.
inline namespace GZ_SIM_VERSION_NAMESPACE {
namespace components
{
/// \brief A component type that contains an air flow sensor,
/// sdf::AirFlow, information.
using AirFlowSensor = Component<sdf::Sensor, class AirFlowSensorTag,
serializers::SensorSerializer>;
GZ_SIM_REGISTER_COMPONENT("gz_sim_components.AirFlowSensor",
AirFlowSensor)
}
}
}
}

#endif
1 change: 1 addition & 0 deletions src/Conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#include <sdf/Actor.hh>
#include <sdf/Atmosphere.hh>
#include <sdf/AirFlow.hh>
#include <sdf/AirPressure.hh>
#include <sdf/AirSpeed.hh>
#include <sdf/Altimeter.hh>
Expand Down
14 changes: 14 additions & 0 deletions src/SdfEntityCreator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "gz/sim/components/components.hh"
#else
#include "gz/sim/components/Actor.hh"
#include "gz/sim/components/AirFlowSensor.hh"
#include "gz/sim/components/AirPressureSensor.hh"
#include "gz/sim/components/AirSpeedSensor.hh"
#include "gz/sim/components/Altimeter.hh"
Expand Down Expand Up @@ -994,6 +995,19 @@ Entity SdfEntityCreator::CreateEntities(const sdf::Sensor *_sensor)
this->dataPtr->ecm->CreateComponent(sensorEntity,
components::WideAngleCamera(*_sensor));
}
else if (_sensor->Type() == sdf::SensorType::AIR_FLOW)
{
this->dataPtr->ecm->CreateComponent(sensorEntity,
components::AirFlowSensor(*_sensor));

// create components to be filled by physics
this->dataPtr->ecm->CreateComponent(sensorEntity,
components::WorldPose(math::Pose3d::Zero));
this->dataPtr->ecm->CreateComponent(sensorEntity,
components::WorldLinearVelocity(math::Vector3d::Zero));
this->dataPtr->ecm->CreateComponent(sensorEntity,
components::WorldAngularVelocity(math::Vector3d::Zero));
}
else if (_sensor->Type() == sdf::SensorType::AIR_PRESSURE)
{
this->dataPtr->ecm->CreateComponent(sensorEntity,
Expand Down
10 changes: 10 additions & 0 deletions src/SdfGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <gz/common/URI.hh>

#include "gz/sim/Util.hh"
#include "gz/sim/components/AirFlowSensor.hh"
#include "gz/sim/components/AirPressureSensor.hh"
#include "gz/sim/components/AirSpeedSensor.hh"
#include "gz/sim/components/Altimeter.hh"
Expand Down Expand Up @@ -716,6 +717,15 @@ namespace sdf_generator
_elem = contactComp->Data();
return updateSensorNameAndPose();
}
// air flow
auto airFlowComp =
_ecm.Component<components::AirFlowSensor>(_entity);
if (airFlowComp)
{
const sdf::Sensor &sensor = airFlowComp->Data();
_elem->Copy(sensor.ToElement());
return updateSensorNameAndPose();
}
// air pressure
auto airPressureComp =
_ecm.Component<components::AirPressureSensor>(_entity);
Expand Down
1 change: 1 addition & 0 deletions src/systems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ endfunction()
add_subdirectory(ackermann_steering)
add_subdirectory(acoustic_comms)
add_subdirectory(advanced_lift_drag)
add_subdirectory(air_flow)
add_subdirectory(air_pressure)
add_subdirectory(air_speed)
add_subdirectory(altimeter)
Expand Down
Loading