Skip to content

Commit

Permalink
Switch Ign-math to Eigen3 (#5)
Browse files Browse the repository at this point in the history
* Add simple build test with github actions

This Adds a simple build test for github actions.

* Renaming the Rascal submodule directory.

* Fix some model path.
Draft of multi-vehicle simulation init scripts.

* Disable joystick and mouse control input.

* Switch to LKSO airport.

* Update README.md

* Add note about availability of multi make target.

* Fix level of details handling for multi-vehicle simulation.

* Add TF-G2 model

* add submodule TF-G2

* Add TF-G2 autogyro model

* Update README.md

* Update submodule

* Fix typos.

* Workaround of issue ThunderFly-aerospace#15

* Update README.md

* Switch from IgnMath to Eigen3 math library.

* Remove libignition-math4-dev from readme.

Co-authored-by: JaeyoungLim <gokoreas@gmail.com>
Co-authored-by: Jakub Kákona <kaklik@mlab.cz>
Co-authored-by: Roman Dvorak <romandvorak@mlab.cz>
  • Loading branch information
4 people authored Jan 6, 2021
1 parent 44b51d5 commit 7c2c623
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "models/FlightGear-TF-R1"]
path = models/TF-R1
url = https://github.com/ThunderFly-aerospace/FlightGear-TF-R1.git
[submodule "models/FlightGear-TF-G2"]
path = models/TF-G2
url = https://github.com/ThunderFly-aerospace/FlightGear-TF-G2.git
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 2.8.11)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

find_package(ignition-math4 REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(MAVLink)

message(STATUS "${MAVLINK_INCLUDE_DIRS}")
Expand All @@ -20,6 +20,5 @@ target_include_directories(flightgear_bridge
PUBLIC ${MAVLINK_INCLUDE_DIRS})

target_compile_options(flightgear_bridge PUBLIC -g -fexceptions -Wno-cast-align -Wno-address-of-packed-member)

target_link_libraries(flightgear_bridge ignition-math4::ignition-math4)
target_link_libraries(flightgear_bridge Eigen3::Eigen)

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ It connects to FG (over UDP generic protocol) and transforms the data to TCP MAV
### How to run the development version:

#### Install:
1) Install FlightGear. In Ubuntu You can use install last stable FG from PAA repository by folowing commands: ```sudo add-apt-repository -y -u ppa:saiarcot895/flightgear``` and ```sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet install flightgear```
3) Set write permissions to the `Protocols` folder in the FlightGear instalation directory. On Ubuntu run ```sudo chmod a+w /usr/share/games/flightgear/Protocols ```
1) Install FlightGear. In Ubuntu You can use install last stable FG from the [PPA repository](https://launchpad.net/~saiarcot895/+archive/ubuntu/flightgear) by following commands: ```sudo add-apt-repository -y -u ppa:saiarcot895/flightgear``` and ```sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet install flightgear```
3) Set write permissions to the `Protocols` folder in the FlightGear instalation directory. On Ubuntu run ```sudo chmod a+w /usr/share/games/flightgear/Protocol ```

#### Run:
1) Open [QgroundControl](http://qgroundcontrol.com/)
Expand All @@ -23,7 +23,7 @@ It connects to FG (over UDP generic protocol) and transforms the data to TCP MAV

#### Known issues:
1) If you have FPS lower than 20 the bridge will not work correctly. Check your FPS. In FlightGear display frame rate by enabling it in View->View Options->Show frame rate.
2) You can probably use a wild set of FG versions - we tested installation with FG 2019.1.1 and the "next" (source-code branch) of FG (nightly builds). But in the past, we achieved basic functionality on Debian 9, FG 2016.1.1 from distribution repository, with some Racal (JSBSim) model download as a zip from the FGaddon repository.
2) You can probably use a wild set of FG versions - we tested installation with FG 2019.1.1 and the "next" (source-code branch) of FG (nightly builds). But in the past, we achieved basic functionality on Debian 9, FG 2016.1.1 from the distribution repository, with some Racal (JSBSim) model download as a zip from the FGaddon repository.
3) Multiple models packaged with the bridge have an electric engine that needs up-to-date patched FlightGear from [nightly builds PPA repository](https://launchpad.net/~saiarcot895/+archive/ubuntu/flightgear-edge).
5) Internal starting scripts run ```fgfs``` has a set of parameters to reduce graphic load. But before that setup, the starting script searches for the FG-Data folder by running ```fgfs --version```. If your output of this command does not contain the FG_ROOT line, the script will not work. Check how is your FG binaries in the system, by ```which fgfs```. Then the Advanced Options section of this readme can help you.
6) If you want another plane model, you can switch the Rascal model to another editing file ```models/rascal.json```. For example substitute ```Rascal110-YASim``` by ```Rascal110-JSBSim```, or another aircraft name.
Expand Down
1 change: 1 addition & 0 deletions models/TF-G2
Submodule TF-G2 added at 562ee7
10 changes: 10 additions & 0 deletions models/tf-g2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"FgModel":"TF-G2",
"Url":"https://github.com/ThunderFly-aerospace/FlightGear-TF-G2/archive/master.zip",
"Controls": [
["2","/controls/flight/aileron","-1"],
["3","/controls/flight/elevator","-1"],
["0","/controls/flight/rudder","1"],
["1","/controls/engines/engine/throttle","1"]
]
}
3 changes: 2 additions & 1 deletion scripts/vehicle1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ export FG_ARGS_EX="--allow-nasal-read=${MODEL_PATH} \
--ignore-autosave \
--disable-hold-short \
--prop:input/joysticks/js=0 \
--prop:/sim/rendering/static-lod/aimp-range-mode-distance=true \
--disable-mouse-pointer \
--multiplay=out,10,127.0.0.1,5000 \
--multiplay=in,10,127.0.0.1,5001"
export PX4_ID=0


cd ${FIRMWARE_DIR}
make px4_sitl_nolockstep flightgear_rascal___multi
make px4_sitl_nolockstep flightgear_rascal___multi # The make target flightgear_rascal___multi is currently available only in flightgear-multi branch of https://github.com/ThunderFly-aerospace/PX4Firmware fork
3 changes: 2 additions & 1 deletion scripts/vehicle2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ export FG_ARGS_EX="--allow-nasal-read=${MODEL_PATH} \
--ignore-autosave \
--disable-hold-short \
--prop:input/joysticks/js=0 \
--prop:/sim/rendering/static-lod/aimp-range-mode-distance=true \
--disable-mouse-pointer \
--multiplay=out,10,127.0.0.1,5001 \
--multiplay=in,10,127.0.0.1,5000"
export PX4_ID=1


cd ${FIRMWARE_DIR}
make px4_sitl_nolockstep flightgear_rascal___multi
make px4_sitl_nolockstep flightgear_rascal___multi # The make target flightgear_rascal___multi is currently available only in flightgear-multi branch of https://github.com/ThunderFly-aerospace/PX4Firmware fork
18 changes: 9 additions & 9 deletions src/vehicle_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,18 @@ void VehicleState::setSensor(const fgOutputData &fgData)
Vector3d VehicleState::getGyro(const fgOutputData &fgData)
{

Quaterniond roll(Vector3d(1, 0, 0), degToRad(fgData.roll_deg));
Quaterniond pitch(Vector3d(0, 1, 0), degToRad(fgData.pitch_deg));
Quaterniond heading(Vector3d(0, 0, 1), degToRad(fgData.heading_deg));
Quaterniond roll(AngleAxisd(degToRad(fgData.roll_deg),Vector3d(1, 0, 0)));
Quaterniond pitch(AngleAxisd(degToRad(fgData.pitch_deg),Vector3d(0, 1, 0)));
Quaterniond heading(AngleAxisd(degToRad(fgData.heading_deg),Vector3d(0, 0, 1)));
Quaterniond bodyRot = heading * pitch * roll;

Vector3d rollRateP(degToRad(fgData.rateRoll_degps), 0, 0);

Vector3d pitchRate(0, degToRad(fgData.ratePitch_degps), 0);
Vector3d pitchRateP = bodyRot.RotateVectorReverse(heading.RotateVector(pitchRate));
Vector3d pitchRateP = bodyRot.inverse()._transformVector(heading._transformVector(pitchRate));

Vector3d headingRate(0, 0, degToRad(fgData.rateYaw_degps));
Vector3d headingRateP = bodyRot.RotateVectorReverse(headingRate);
Vector3d headingRateP = bodyRot.inverse()._transformVector(headingRate);

Vector3d ret = rollRateP + pitchRateP + headingRateP;
return ret;
Expand All @@ -209,12 +209,12 @@ Vector3d VehicleState::getMagneticField(const fgOutputData &fgData)

Vector3d mag_g(X, Y, Z);

Quaterniond roll(Vector3d(1, 0, 0), degToRad(fgData.roll_deg));
Quaterniond pitch(Vector3d(0, 1, 0), degToRad(fgData.pitch_deg));
Quaterniond heading(Vector3d(0, 0, 1), degToRad(fgData.heading_deg));
Quaterniond roll(AngleAxisd(degToRad(fgData.roll_deg),Vector3d(1, 0, 0)));
Quaterniond pitch(AngleAxisd(degToRad(fgData.pitch_deg),Vector3d(0, 1, 0)));
Quaterniond heading(AngleAxisd(degToRad(fgData.heading_deg),Vector3d(0, 0, 1)));
Quaterniond bodyRot = heading * pitch * roll;

Vector3d mag1 = bodyRot.RotateVectorReverse(mag_g);
Vector3d mag1 = bodyRot.inverse()._transformVector(mag_g);

return mag1;
}
Expand Down
7 changes: 4 additions & 3 deletions src/vehicle_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@
#include <random>

#include <mavlink/v2.0/common/mavlink.h>
#include <ignition/math/Vector3.hh>
#include <ignition/math/Quaternion.hh>
#include <Eigen/Geometry>

using namespace ignition::math;
using namespace Eigen;

struct fgOutputData {

Expand Down Expand Up @@ -91,6 +90,8 @@ struct fgOutputData {
class VehicleState
{

//typedef Vector3d Vector3<double>

public:

mavlink_hil_gps_t hil_gps_msg;
Expand Down

0 comments on commit 7c2c623

Please sign in to comment.