Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
43 changes: 42 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ if("$ENV{GZ_VERSION}" STREQUAL "harmonic" OR NOT DEFINED "ENV{GZ_VERSION}")
gz_find_package(gz-sim8 REQUIRED)
set(GZ_SIM_VER ${gz-sim8_VERSION_MAJOR})

gz_find_package(gz-msgs10 REQUIRED)
set(GZ_MSGS_VER ${gz-msgs10_VERSION_MAJOR})

message(STATUS "Compiling against Gazebo Harmonic")
elseif("$ENV{GZ_VERSION}" STREQUAL "ionic")
# Ionic
Expand Down Expand Up @@ -69,10 +72,29 @@ endif()
# --------------------------------------------------------------------------- #
find_package(RapidJSON REQUIRED)
find_package(OpenCV REQUIRED)
find_package(Protobuf REQUIRED)

pkg_check_modules(GST REQUIRED gstreamer-1.0 gstreamer-app-1.0)


# --------------------------------------------------------------------------- #
# Build proto custom messages
set(ARDUPILOT_MSGS_PROTOS
${CMAKE_CURRENT_SOURCE_DIR}/proto/ardupilot_gazebo/msgs/motor_stats.proto
)

gz_msgs_generate_messages(
# The cmake target to be generated for libraries/executables to link
TARGET msgs
# The protobuf package to generate (Typically based on the path)
PROTO_PACKAGE "ardupilot_gazebo.msgs"
# The path to the base directory of the proto files
# All import paths should be relative to this (eg gz/custom_msgs/vector3d.proto)
MSGS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/proto
# List of proto files to generate
MSGS_PROTOS ${ARDUPILOT_MSGS_PROTOS}
# List of message targets this library imports from
DEPENDENCIES gz-msgs${GZ_MSGS_VER}::gz-msgs${GZ_MSGS_VER}
)
# --------------------------------------------------------------------------- #
# Build plugin.

Expand All @@ -89,6 +111,24 @@ target_link_libraries(ArduPilotPlugin PRIVATE
gz-sim${GZ_SIM_VER}::gz-sim${GZ_SIM_VER}
)

add_library(MotorPlugin
SHARED
src/MotorPlugin.cc
src/Util.cc

)
target_include_directories(MotorPlugin PRIVATE
include
# ${CMAKE_CURRENT_BINARY_DIR}/ardupilot_gazebo-msgs_genmsg
)
target_link_libraries(MotorPlugin PRIVATE
gz-sim${GZ_SIM_VER}::gz-sim${GZ_SIM_VER}
${PROJECT_NAME}-msgs
# gz-msgs${GZ_MSGS_VER}::gz-msgs${GZ_MSGS_VER}
# ardupilot_gazebo-msgs
)
# add_dependencies(MotorPlugin ardupilot_gazebo-msgs)

add_library(ParachutePlugin
SHARED
src/ParachutePlugin.cc
Expand Down Expand Up @@ -134,6 +174,7 @@ target_link_libraries(GstCameraPlugin PRIVATE
install(
TARGETS
ArduPilotPlugin
MotorPlugin
ParachutePlugin
CameraZoomPlugin
GstCameraPlugin
Expand Down
67 changes: 67 additions & 0 deletions include/MotorPlugin.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
*
* 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.
*
*/
Comment on lines +1 to +16

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be LGPLv3. The original ArduPilotPlugin code was Apache, but new works should match the repo license (https://github.com/ArduPilot/ardupilot_gazebo/blob/main/LICENSE.md). See https://github.com/ArduPilot/ardupilot_gazebo/blob/main/include/SocketUDP.hh for example text to include in source files.


#ifndef MOTORPLUGIN_HH_
#define MOTORPLUGIN_HH_

#include <memory>

#include <gz/sim/System.hh>

namespace gz {
namespace sim {
inline namespace GZ_SIM_VERSION_NAMESPACE {
namespace systems {


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include a doc string describing the plugins purpose and SDF parameters. See for example: https://github.com/ArduPilot/ardupilot_gazebo/blob/main/include/GstCameraPlugin.hh

class MotorPlugin :
public System,
public ISystemPreUpdate,
public ISystemConfigure
{
/// \brief Destructor
public: virtual ~MotorPlugin();

/// \brief Constructor
public: MotorPlugin();

// Documentation inherited
public: void PreUpdate(const gz::sim::UpdateInfo &_info,
EntityComponentManager &_ecm) final;

// Documentation inherited
public: void Configure(const Entity &_entity,
const std::shared_ptr<const sdf::Element> &_sdf,
EntityComponentManager &_ecm,
EventManager &) final;

/// \brief Load control channels
private: void LoadControlChannels(
sdf::ElementPtr _sdf,
gz::sim::EntityComponentManager &_ecm);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be in the private Impl class as this function is not called by the Gazebo system.


/// \internal
/// \brief Private implementation
private: class Impl;
private: std::unique_ptr<Impl> impl;
};

} // namespace systems
}
} // namespace sim
} // namespace gz

#endif // MOTORPLUGIN_HH_
73 changes: 68 additions & 5 deletions models/iris_with_gimbal/model.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,15 @@
<offset>0</offset>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to see the changes to the models split into a separate PR. That way we can proceed with including the motor plugin without altering the existing models and their behaviour. When we're more comfortable with the plugin we can consider migrating the examples over to it.

In the meanwhile a small test model (one of the iris motors and prop fixed to a thrust stand would be good). That would allow testing and demonstrations. It could even have a force torque sensor plugin included in the joint for additional feedback.

<servo_min>1100</servo_min>
<servo_max>1900</servo_max>
<type>VELOCITY</type>
<type>COMMAND</type>
<p_gain>0.20</p_gain>
<i_gain>0</i_gain>
<d_gain>0</d_gain>
<i_max>0</i_max>
<i_min>0</i_min>
<cmd_max>2.5</cmd_max>
<cmd_min>-2.5</cmd_min>
<cmd_topic>joint_0</cmd_topic>
<controlVelocitySlowdownSim>1</controlVelocitySlowdownSim>
</control>

Expand All @@ -233,14 +234,15 @@
<offset>0</offset>
<servo_min>1100</servo_min>
<servo_max>1900</servo_max>
<type>VELOCITY</type>
<type>COMMAND</type>
<p_gain>0.20</p_gain>
<i_gain>0</i_gain>
<d_gain>0</d_gain>
<i_max>0</i_max>
<i_min>0</i_min>
<cmd_max>2.5</cmd_max>
<cmd_min>-2.5</cmd_min>
<cmd_topic>joint_1</cmd_topic>
<controlVelocitySlowdownSim>1</controlVelocitySlowdownSim>
</control>

Expand All @@ -251,14 +253,15 @@
<offset>0</offset>
<servo_min>1100</servo_min>
<servo_max>1900</servo_max>
<type>VELOCITY</type>
<type>COMMAND</type>
<p_gain>0.20</p_gain>
<i_gain>0</i_gain>
<d_gain>0</d_gain>
<i_max>0</i_max>
<i_min>0</i_min>
<cmd_max>2.5</cmd_max>
<cmd_min>-2.5</cmd_min>
<cmd_topic>joint_2</cmd_topic>
<controlVelocitySlowdownSim>1</controlVelocitySlowdownSim>
</control>

Expand All @@ -269,14 +272,15 @@
<offset>0</offset>
<servo_min>1100</servo_min>
<servo_max>1900</servo_max>
<type>VELOCITY</type>
<type>COMMAND</type>
<p_gain>0.20</p_gain>
<i_gain>0</i_gain>
<d_gain>0</d_gain>
<i_max>0</i_max>
<i_min>0</i_min>
<cmd_max>2.5</cmd_max>
<cmd_min>-2.5</cmd_min>
<cmd_topic>joint_3</cmd_topic>
<controlVelocitySlowdownSim>1</controlVelocitySlowdownSim>
</control>

Expand Down Expand Up @@ -318,6 +322,65 @@

</plugin>

<plugin filename="MotorPlugin" name="MotorPlugin">

<control channel="0">
<joint_name>iris_with_standoffs::rotor_0_joint</joint_name>
<voltage_bat>16</voltage_bat>
<speed_constant>920</speed_constant>
<resistance>0.115</resistance>
<no_load_current>0.8</no_load_current>
<cmd_topic>joint_0</cmd_topic>
<multiplier>838</multiplier>
<offset>0</offset>
<thermal_resistance>1.4</thermal_resistance>
<thermal_capacitance>214.28</thermal_capacitance>
<ambient_temperature>25.0</ambient_temperature>
</control>

<control channel="1">
<joint_name>iris_with_standoffs::rotor_1_joint</joint_name>
<voltage_bat>16</voltage_bat>
<speed_constant>920</speed_constant>
<resistance>0.115</resistance>
<no_load_current>0.8</no_load_current>
<cmd_topic>joint_1</cmd_topic>
<multiplier>838</multiplier>
<offset>0</offset>
<thermal_resistance>1.4</thermal_resistance>
<thermal_capacitance>214.28</thermal_capacitance>
<ambient_temperature>25.0</ambient_temperature>
</control>

<control channel="2">
<joint_name>iris_with_standoffs::rotor_2_joint</joint_name>
<voltage_bat>16</voltage_bat>
<speed_constant>920</speed_constant>
<resistance>0.115</resistance>
<no_load_current>0.8</no_load_current>
<cmd_topic>joint_2</cmd_topic>
<multiplier>-838</multiplier>
<offset>0</offset>
<thermal_resistance>1.4</thermal_resistance>
<thermal_capacitance>214.28</thermal_capacitance>
<ambient_temperature>25.0</ambient_temperature>
</control>

<control channel="3">
<joint_name>iris_with_standoffs::rotor_3_joint</joint_name>
<voltage_bat>16</voltage_bat>
<speed_constant>920</speed_constant>
<resistance>0.115</resistance>
<no_load_current>0.8</no_load_current>
<cmd_topic>joint_3</cmd_topic>
<multiplier>-838</multiplier>
<offset>0</offset>
<thermal_resistance>1.4</thermal_resistance>
<thermal_capacitance>214.28</thermal_capacitance>
<ambient_temperature>25.0</ambient_temperature>
</control>
</plugin>

<plugin
filename="gz-sim-joint-position-controller-system"
name="gz::sim::systems::JointPositionController">
Expand All @@ -341,4 +404,4 @@
</plugin>

</model>
</sdf>
</sdf>
8 changes: 4 additions & 4 deletions models/iris_with_standoffs/model.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
<upper>1e+16</upper>
</limit>
<dynamics>
<damping>0.004</damping>
<damping>1.0e-4</damping>
</dynamics>
</axis>
<physics>
Expand Down Expand Up @@ -315,7 +315,7 @@
<upper>1e+16</upper>
</limit>
<dynamics>
<damping>0.004</damping>
<damping>1.0e-4</damping>
</dynamics>
</axis>
<physics>
Expand Down Expand Up @@ -389,7 +389,7 @@
<upper>1e+16</upper>
</limit>
<dynamics>
<damping>0.004</damping>
<damping>1.0e-4</damping>
</dynamics>
</axis>
<physics>
Expand Down Expand Up @@ -463,7 +463,7 @@
<upper>1e+16</upper>
</limit>
<dynamics>
<damping>0.004</damping>
<damping>1.0e-4</damping>
</dynamics>
</axis>
<physics>
Expand Down
20 changes: 20 additions & 0 deletions proto/ardupilot_gazebo/msgs/motor_stats.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto3";
package ardupilot_gazebo.msgs;

// Message to hold the status of a single motor.
message MotorStats {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
message MotorStats {
message MotorStatus {

MotorStatus better aligns with the DroneCAN message names (uavcan.equipment.esc.Status and uavcan.equipment.esc.StatusExtended). See for example: https://github.com/dronecan/DSDL/blob/master/uavcan/equipment/esc/1034.Status.uavcan

// Motor Id
int32 motor_id = 1;

// Rotational speed of the motor in revolutions per minute (RPM).
double rpm = 2;

// Voltage supplied to the motor in Volts.
double voltage = 3;

// Current drawn by the motor in Amperes.
double current = 4;

// Motor Temperature in Celsius.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temperature in Kelvin.

double temperature = 5;
}
Loading
Loading