Skip to content

Commit

Permalink
Merge branch 'master' into motor_speed_republisher
Browse files Browse the repository at this point in the history
  • Loading branch information
petrlmat committed Nov 7, 2023
2 parents e4e07d9 + f9ae5d2 commit 19590e3
Show file tree
Hide file tree
Showing 15 changed files with 994 additions and 74 deletions.
12 changes: 0 additions & 12 deletions .ci/build.sh

This file was deleted.

46 changes: 0 additions & 46 deletions .ci/install.sh

This file was deleted.

25 changes: 25 additions & 0 deletions .github/workflows/ros_build_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: ros_build_test

on:

push:
branches: [ devel ]

paths-ignore:
- '**/README.md'

pull_request:
branches: [ master ]

workflow_dispatch:

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:

build:
uses: ctu-mrs/ci_scripts/.github/workflows/ros_build_test.yml@master
secrets:
PUSH_TOKEN: ${{ secrets.PUSH_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/ros_package_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: ros_package_build
on:

push:
branches: [ hw_api ]
branches: [ master ]

pull_request:
branches: [ hw_api ]
paths-ignore:
- '**/README.md'

workflow_dispatch:

Expand Down
56 changes: 46 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set(CATKIN_DEPENDENCIES
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
${CATKIN_DEPENDENCIES}
)
)

# include Gazebo
find_package(gazebo REQUIRED)
Expand Down Expand Up @@ -65,6 +65,9 @@ set(sensor_msgs
msgs/Groundtruth.proto
msgs/MagneticField.proto
msgs/Float.proto
msgs/CommandMotorSpeed.proto
msgs/MotorSpeed.proto
msgs/Wind.proto
)

PROTOBUF_GENERATE_CPP(SEN_PROTO_SRCS SEN_PROTO_HDRS ${sensor_msgs})
Expand Down Expand Up @@ -95,14 +98,17 @@ set(LIBRARIES
MrsGazeboCommonResources_ServoCameraPlugin
MrsGazeboCommonResources_DynamicModelPlugin
MrsGazeboCommonResources_SafetyLedPlugin
MrsGazeboCommonResources_FluidResistancePlugin
MrsGazeboCommonResources_MotorSpeedRepublisherPlugin
MrsGazeboCommonResources_MotorPropModelPlugin
)

catkin_package(
INCLUDE_DIRS include
CATKIN_DEPENDS ${CATKIN_DEPENDENCIES}
DEPENDS GAZEBO Qt5Widgets Boost Eigen OpenCV
LIBRARIES ${LIBRARIES}
)
INCLUDE_DIRS include
CATKIN_DEPENDS ${CATKIN_DEPENDENCIES}
DEPENDS GAZEBO Qt5Widgets Boost Eigen OpenCV
LIBRARIES ${LIBRARIES}
)

###########
## Build ##
Expand Down Expand Up @@ -327,13 +333,43 @@ target_link_libraries(MrsGazeboCommonResources_SafetyLedPlugin
${Boost_LIBRARIES}
)

add_library(MRSGazeboMotorSpeedRepublisherPlugin SHARED src/sensor_and_model_plugins/motor_speed_republisher.cpp)
target_link_libraries(MRSGazeboMotorSpeedRepublisherPlugin
# FluidResistancePlugin

add_library(MrsGazeboCommonResources_FluidResistancePlugin SHARED
src/physics_plugins/fluid_resistance_plugin.cpp
)

target_link_libraries(MrsGazeboCommonResources_FluidResistancePlugin
${GAZEBO_LIBRARIES}
${catkin_LIBRARIES}
${Boost_LIBRARIES}
)

# MotorSpeedRepublisherPlugin

add_library(MrsGazeboCommonResources_MotorSpeedRepublisherPlugin SHARED
src/sensor_and_model_plugins/motor_speed_republisher.cpp
${SEN_PROTO_SRCS}
)

target_link_libraries(MrsGazeboCommonResources_MotorSpeedRepublisherPlugin
${GAZEBO_LIBRARIES}
${catkin_LIBRARIES}
${Boost_LIBRARIES}
)

# MotorPropModelPlugin

add_library(MrsGazeboCommonResources_MotorPropModelPlugin SHARED
src/physics_plugins/motor_prop_model_plugin.cpp
${SEN_PROTO_SRCS}
)

target_link_libraries(MrsGazeboCommonResources_MotorPropModelPlugin
${GAZEBO_LIBRARIES}
${catkin_LIBRARIES}
${Boost_LIBRARIES}
)

## --------------------------------------------------------------
## | Install |
Expand All @@ -347,8 +383,8 @@ install(TARGETS ${LIBRARIES}

install(DIRECTORY models/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/models
)
)

install(DIRECTORY worlds/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/worlds
)
)
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# MRS resources for Gazebo

| Build status | [![Build Status](https://github.com/ctu-mrs/mrs_gazebo_common_resources/workflows/Noetic/badge.svg)](https://github.com/ctu-mrs/mrs_gazebo_common_resources/actions) |
|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
> :warning: **Attention please: This README is outdated.**
>
> The MRS UAV System 1.5 is being released and this page needs updating. Please, keep in mind that the information on this page might not be valid.
This package contains common gazebo files (worlds, models and plugins) for the MRS system.
This package contains common gazebo files (worlds, models and plugins) for the [MRS UAV system](https://github.com/ctu-mrs/mrs_uav_system).

## Worlds

- [forest.world](worlds/forest.world)
- [grass_plane.world](worlds/grass_plane.world)
- [uneven_plane.world](worlds/uneven_plane.world)

## Models

- [grass_plane](models/grass_plane)
- [grey_wall](models/grey_wall)
- [static_camera](models/static_camera)
Expand All @@ -24,6 +27,7 @@ This package contains common gazebo files (worlds, models and plugins) for the M
- [safety_led](models/safety_led)

## Plugins

- [world_plugins](src/world_plugins) - Detail descriptions in [README](src/world_plugins/README.md)
- [gui_plugins](src/gui_plugins) - Detail descriptions in [README](src/gui_plugins/README.md)
- [sensor_and_model_plugins](src/sensor_and_model_plugins) - Detail descriptions in [README](src/sensor_and_model_plugins/README.md)
157 changes: 157 additions & 0 deletions include/motor_prop_model.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
* Copyright 2015 Fadri Furrer, ASL, ETH Zurich, Switzerland
* Copyright 2015 Michael Burri, ASL, ETH Zurich, Switzerland
* Copyright 2015 Mina Kamel, ASL, ETH Zurich, Switzerland
* Copyright 2015 Janosch Nikolic, ASL, ETH Zurich, Switzerland
* Copyright 2015 Markus Achtelik, ASL, ETH Zurich, Switzerland
*
* 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.
*/



#include <stdio.h>

#include <boost/bind.hpp>
#include <Eigen/Eigen>
#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>
#include <gazebo/common/common.hh>
#include <gazebo/common/Plugin.hh>
#include <rotors_model/motor_model.hpp>
#include "CommandMotorSpeed.pb.h"
#include "gazebo/transport/transport.hh"
#include "gazebo/msgs/msgs.hh"
#include "MotorSpeed.pb.h"
#include "Float.pb.h"
#include "Wind.pb.h"

#include "common.h"


namespace turning_direction {
const static int CCW = 1;
const static int CW = -1;
}

namespace gazebo {
// Default values
static const std::string kDefaultNamespace = "";
static const std::string kDefaultCommandSubTopic = "/gazebo/command/motor_speed";
static const std::string kDefaultMotorFailureNumSubTopic = "/gazebo/motor_failure_num";
static const std::string kDefaultMotorVelocityPubTopic = "/motor_speed";
std::string wind_sub_topic_ = "/world_wind";

typedef const boost::shared_ptr<const mav_msgs::msgs::CommandMotorSpeed> CommandMotorSpeedPtr;
typedef const boost::shared_ptr<const physics_msgs::msgs::Wind> WindPtr;
/*
// Protobuf test
typedef const boost::shared_ptr<const mav_msgs::msgs::MotorSpeed> MotorSpeedPtr;
static const std::string kDefaultMotorTestSubTopic = "motors";
*/

// Set the max_force_ to the max double value. The limitations get handled by the FirstOrderFilter.
static constexpr double kDefaultMaxForce = std::numeric_limits<double>::max();
static constexpr double kDefaultMotorConstant = 8.54858e-06;
static constexpr double kDefaultMomentConstant = 0.016;
static constexpr double kDefaultTimeConstantUp = 1.0 / 80.0;
static constexpr double kDefaultTimeConstantDown = 1.0 / 40.0;
static constexpr double kDefaulMaxRotVelocity = 838.0;
static constexpr double kDefaultRotorDragCoefficient = 1.0e-4;
static constexpr double kDefaultRollingMomentCoefficient = 1.0e-6;
static constexpr double kDefaultRotorVelocitySlowdownSim = 10.0;

class GazeboMotorPropModel : public MotorPropModel, public ModelPlugin {
public:
GazeboMotorPropModel()
: MotorPropModel(),
ModelPlugin(){
}

virtual ~GazeboMotorPropModel();

virtual void InitializeParams();
virtual void Publish();
//void testProto(MotorSpeedPtr &msg);
protected:
virtual void UpdateForcesAndMoments();
/// \brief A function to check the motor_Failure_Number_ and stimulate motor fail
/// \details Doing joint_->SetVelocity(0,0) for the flagged motor to fail
virtual void UpdateMotorFail();
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf);
virtual void OnUpdate(const common::UpdateInfo & /*_info*/);

private:
std::string command_sub_topic_{kDefaultCommandSubTopic};
std::string motor_failure_sub_topic_{kDefaultMotorFailureNumSubTopic};
std::string joint_name_;
std::string link_name_;
std::string motor_speed_pub_topic_{kDefaultMotorVelocityPubTopic};
std::string namespace_;

int motor_number_{0};
int turning_direction_{turning_direction::CW};

int motor_Failure_Number_{0}; /*!< motor_Failure_Number is (motor_number_ + 1) as (0) is considered no_fail. Publish accordingly */
int tmp_motor_num; // A temporary variable used to print msg

int screen_msg_flag = 1;

bool motor_ok_flag_ = true;
bool enable_motor_crash_ = true;
double last_motor_speed_ = 0.0;

double max_force_{kDefaultMaxForce};
double max_rot_velocity_{kDefaulMaxRotVelocity};
double moment_constant_{kDefaultMomentConstant};
double motor_constant_{kDefaultMotorConstant};
double ref_motor_rot_vel_{0.0};
double rolling_moment_coefficient_{kDefaultRollingMomentCoefficient};
double rotor_drag_coefficient_{kDefaultRotorDragCoefficient};
double rotor_velocity_slowdown_sim_{kDefaultRotorVelocitySlowdownSim};
double time_constant_down_{kDefaultTimeConstantDown};
double time_constant_up_{kDefaultTimeConstantUp};

bool reversible_{false};

transport::NodePtr node_handle_;
transport::PublisherPtr motor_velocity_pub_;
transport::SubscriberPtr command_sub_;
transport::SubscriberPtr motor_failure_sub_; /*!< Subscribing to motor_failure_sub_topic_; receiving motor number to fail, as an integer */
transport::SubscriberPtr wind_sub_;

ignition::math::Vector3d wind_vel_;

physics::ModelPtr model_;
physics::JointPtr joint_;
common::PID pid_;
bool use_pid_;
physics::LinkPtr link_;
/// \brief Pointer to the update event connection.
event::ConnectionPtr updateConnection_;

boost::thread callback_queue_thread_;
void QueueThread();
std_msgs::msgs::Float turning_velocity_msg_;
void VelocityCallback(CommandMotorSpeedPtr &rot_velocities);
void MotorFailureCallback(const boost::shared_ptr<const msgs::Int> &fail_msg); /*!< Callback for the motor_failure_sub_ subscriber */
void WindVelocityCallback(const boost::shared_ptr<const physics_msgs::msgs::Wind> &msg);

std::unique_ptr<FirstOrderFilter<double>> rotor_velocity_filter_;
/*
// Protobuf test
std::string motor_test_sub_topic_;
transport::SubscriberPtr motor_sub_;
*/
};
}
Loading

0 comments on commit 19590e3

Please sign in to comment.