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

Create tuning package #15

Merged
merged 4 commits into from
Mar 4, 2024
Merged
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
8 changes: 0 additions & 8 deletions data_viz/CHANGELOG.rst

This file was deleted.

Empty file removed data_viz/data_viz/__init__.py
Empty file.
20 changes: 0 additions & 20 deletions data_viz/package.xml

This file was deleted.

Empty file removed data_viz/resource/data_viz
Empty file.
4 changes: 0 additions & 4 deletions data_viz/setup.cfg

This file was deleted.

26 changes: 0 additions & 26 deletions data_viz/setup.py

This file was deleted.

25 changes: 0 additions & 25 deletions data_viz/test/test_copyright.py

This file was deleted.

25 changes: 0 additions & 25 deletions data_viz/test/test_flake8.py

This file was deleted.

23 changes: 0 additions & 23 deletions data_viz/test/test_pep257.py

This file was deleted.

9 changes: 0 additions & 9 deletions rosplane/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,6 @@ install(TARGETS
rosplane_estimator_node
DESTINATION lib/${PROJECT_NAME})

# Signal Generator
add_executable(tuning_signal_generator
src/tuning_signal_generator.cpp)
ament_target_dependencies(tuning_signal_generator rosplane_msgs std_srvs rclcpp)
target_compile_options(tuning_signal_generator PRIVATE -Wno-unused-parameter)
install(TARGETS
tuning_signal_generator
DESTINATION lib/${PROJECT_NAME})

#### END OF EXECUTABLES ###


Expand Down
6 changes: 6 additions & 0 deletions rosplane_tuning/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package rosplane
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2.0.0 (Pre-release)
------------------
68 changes: 68 additions & 0 deletions rosplane_tuning/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
cmake_minimum_required(VERSION 3.8)
project(rosplane_tuning)

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif(NOT CMAKE_BUILD_TYPE)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclpy REQUIRED)
find_package(std_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(rosplane_msgs REQUIRED)
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
find_package(rosflight_msgs REQUIRED)

ament_export_dependencies(rclcpp rclpy)
ament_export_include_directories(include)

#install(DIRECTORY originalFiles DESTINATION share/${PROJECT_NAME}/)
include_directories( #use this if you need .h files for include statements. The include will need to have the directories where each .h is respectively.
include
${EIGEN3_INCLUDE_DIRS}
)

install(DIRECTORY launch DESTINATION share/${PROJECT_NAME}/)

### START OF REAL EXECUTABLES ###

# Signal Generator
add_executable(signal_generator
src/signal_generator.cpp)
ament_target_dependencies(signal_generator rosplane_msgs std_srvs rclcpp)
target_compile_options(signal_generator PRIVATE -Wno-unused-parameter)
install(TARGETS
signal_generator
DESTINATION lib/${PROJECT_NAME})

# Data viz
install(PROGRAMS
src/data_viz/data_storage.py
src/data_viz/data_viz.py
src/data_viz/plot_window.py
DESTINATION lib/${PROJECT_NAME}
)

#### END OF EXECUTABLES ###

ament_package()
65 changes: 65 additions & 0 deletions rosplane_tuning/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# ROSplane Tuning

This ROS2 package contains tools useful for tuning the autopilot performance of ROSplane.

We recommend using [PlotJuggler](https://github.com/facontidavide/PlotJuggler) to visualize command input and response.

## Signal Generator

Signal generator is a ROS2 node that will generate step inputs, square waves, sine waves, sawtooth waves, and triangle waves to be used as command input for ROSplane. It has support for roll, pitch, altitude, heading, and airspeed command input.

This is useful for tuning autopilots as we can give a clear and repeatable command to any portion of the autopilot and observe its response to that input. We can then tune gains, re-issue the same commands, and observe whether performance improved or worsened.

Signal generator works by publishing autopilot commands on the ROS network on the `controller_commands` and `tuning_debug` topics. Each control output (roll, pitch, altitude, heading, airspeed) has a default values that is set by a ROS parameter. The signal generator will then add the generated signal to one of the control outputs with a set magnitude and frequency.

### Signal Types
- Step: This is a non-continuous signal, where the generated signal will jump between the default value and the default+magnitude every time the `toggle_step_signal` service is called.
- Sine: This is a continuous signal that create a standard sine wave.
- Square: This is a continuous signal that creates a square type pattern.
- Triangle: This is a continuous signal that ramps up and down between the minimum and maximum value of the signal, creating a triangle like pattern.
- Sawtooth: This is a continuous signal (sometimes call a ramp signal) that creates a constantly increasing signal that resets to its minimum value once the maximum value is reached.

![Waveforms](Waveforms.svg)

*By Omegatron - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=343520*

### Parameters
- `controller_output`: Specifies what controller to apply the generated signal to. All other controllers will be constant at their default values. Valid values are `roll`, `pitch`, `altitude`, `heading`, and `airspeed`.
- `signal_type`: Specified what kind of signal to generate. Valid values are `step`, `square`, `sawtooth`, `triangle`, and `sine`.
- `publish_rate_hz`: Specifies the rate to publish control commands. Must be greater than 0.
- `signal_magnitude`: Specifies the magnitude of the signal to generate. The signal will only be added to the default value, rather than subtracted. For example, if the signal has a magnitude of 2 and a default value of 5, the generated signal will range from 5 to 7.
- `frequency_hz`: Specifies the frequency of the generated signal. Must be greater than 0, and does not apply to step signals. For step signals, manually toggle the signal up and down with the `toggle_step_signal` service.
- `default_va_c`: The default value for the commanded airspeed, in meters per second.
- `default_h_c`: The default value for the commanded altitude, in meters above takeoff altitude.
- `default_chi_c`: The default value for the commanded heading, in radians clockwise from north.
- `default_theta_c`: The default value for the commanded pitch, in radians pitched up from horizontal.
- `default_phi_c`: The default value for the commanded roll, in radians 'rolled right' from horizontal.

To get a parameter from the command line, use this command, replacing <parameter> with the desired parameter to get.
```
ros2 param get signal_generator <parameter>
```

To set a parameter from the command line, use this command, replacing <parameter> with the name of the parameter to set. Enter number parameters as float values, not integers (i.e. 1.0, not 1).
```
ros2 param set signal_generator <parameter>
```

### ROS Services
- `toggle_step_signal`: Toggles the step signal up and down. Does not apply to any other type of signal.
- `reset_signal`: Stops the generated signal and sets it to its default value.
- `pause_signal`: Pauses the generated signal at its current value. Does not apply to step signal.
- `start_continuous_signal`: Starts the signal generator at its current value, running continously until manually stopped. Does not apply to step signal.
- `start_single_period_signal`: Starts the signal generator at its current value, stopping after one full cycle. Does not apply to step signal.

To call a service from the command line use this command, replacing <service> with the name of the service you wish to call.
```
ros2 service call <service> std_srvs/srv/Trigger
```

## Data Viz

Data viz is a python utility that can be used to plot the controller commands and response, as an alternative to PlotJuggler. To run data viz,
```
ros2 run rosplane_tuning data_viz.py
```
82 changes: 82 additions & 0 deletions rosplane_tuning/Waveforms.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading