Skip to content

Commit 276d4bc

Browse files
committed
Add support of TF-G1 and TF-G2 to FG bridge, update readme, update mavlink communication
Add support of TF-G1 and TF-G2 to FG bridge, update readme, update mavlink communication
1 parent ea9b6cb commit 276d4bc

File tree

12 files changed

+140
-37
lines changed

12 files changed

+140
-37
lines changed

FG_run.py

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,40 @@
99

1010
import subprocess
1111

12+
exparameters = [
13+
"--enable-terrasync",
14+
"--timeofday=noon",
15+
"--disable-sound",
16+
"--disable-random-objects",
17+
"--prop:/sim/rendering/texture-compression=off",
18+
"--prop:/sim/rendering/quality-level=0",
19+
"--prop:/sim/rendering/shaders/quality-level=0",
20+
"--disable-ai-traffic",
21+
"--prop:/sim/ai/enabled=0",
22+
"--prop:/sim/rendering/random-vegetation=0",
23+
"--prop:/sim/rendering/random-buildings=0",
24+
"--disable-specular-highlight",
25+
"--disable-ai-models",
26+
"--disable-clouds",
27+
"--disable-clouds3d",
28+
"--fog-fastest",
29+
"--visibility=2000",
30+
"--disable-distance-attenuation",
31+
"--disable-real-weather-fetch",
32+
"--prop:/sim/rendering/particles=0",
33+
"--prop:/sim/rendering/multi-sample-buffers=1",
34+
"--prop:/sim/rendering/multi-samples=2",
35+
"--prop:/sim/rendering/draw-mask/clouds=false",
36+
"--prop:/sim/rendering/draw-mask/aircraft=true",
37+
"--prop:/sim/rendering/draw-mask/models=true",
38+
"--prop:/sim/rendering/draw-mask/terrain=true",
39+
"--disable-random-vegetation",
40+
"--disable-random-buildings",
41+
"--disable-rembrandt",
42+
"--disable-horizon-effect"
43+
]
44+
45+
1246
if len(sys.argv)!=3:
1347
print('FG_run.py -- bad argument count')
1448
exit(-1)
@@ -41,11 +75,17 @@
4175
if fgmodelsdir is None:
4276
fgmodelsdir='./models'
4377

44-
#get FGFS EXTRA PARAMS dir
78+
#get FGFS EXTRA PARAMS
4579
fgargsex=os.getenv("FG_ARGS_EX")
4680
print(fgargsex)
4781
if fgargsex is None:
48-
fgargsex=''
82+
fgargsex=" ".join(exparameters);
83+
84+
#get FGFS ADD PARAMS
85+
fgargsadd=os.getenv("FG_ARGS_ADD")
86+
print(fgargsadd)
87+
if fgargsadd is None:
88+
fgargsadd="";
4989

5090
protocols=fgroot+'/Protocol'
5191
if not os.access(protocols, os.W_OK):
@@ -94,13 +134,11 @@
94134

95135
############################ Run FG #############################################
96136

97-
parameters = [
137+
baseparameters = [
98138
"--aircraft=" + model,
99139
"--fg-aircraft=" + fgmodelsdir,
100-
"--enable-terrasync",
101-
"--timeofday=noon",
102-
"--disable-sound",
103140
"--telnet="+str(15400+px4id),
141+
"--timeofday=noon",
104142
"--generic=socket,out,100,127.0.0.1,"+str(15200+px4id)+",udp,FGtoPX4",
105143
"--generic=socket,in,100,,"+str(15300+px4id)+",udp,PX4toFG",
106144
"--model-hz=120",
@@ -118,6 +156,7 @@
118156
"--disable-clouds3d",
119157
"--fog-fastest",
120158
"--visibility=2000",
159+
"--model-hz=500",
121160
"--disable-distance-attenuation",
122161
"--disable-real-weather-fetch",
123162
"--prop:/sim/rendering/particles=0",
@@ -129,12 +168,11 @@
129168
"--prop:/sim/rendering/draw-mask/terrain=true",
130169
"--disable-random-vegetation",
131170
"--disable-random-buildings",
132-
"--disable-rembrandt",
133171
"--disable-horizon-effect"
134172
]
135173

136174
#with FG output
137-
commnad=fgbin+" "+fgargsex+" "+" ".join(parameters)+" & echo $! > /tmp/px4fgfspid_"+str(px4id)
175+
commnad=fgbin+" "+" ".join(baseparameters)+" "+fgargsex+" "+fgargsadd+" & echo $! > /tmp/px4fgfspid_"+str(px4id)
138176

139177
print(commnad)
140178
os.system(commnad)

README.md

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,63 @@
22

33
![Build Tests](https://github.com/PX4/PX4-FlightGear-Bridge/workflows/Build%20Tests/badge.svg)
44

5-
The FlightGear alternative to the current PX4's mainstream simulator Gazebo.
5+
The FlightGear alternative to the current PX4's mainstream simulator Gazebo. The FlightGear expands the simulation possibilities by advanced weather simulations.
66

77
![FlightGear SITL connected with PX4 and QGroundControl](art/screenshot.png)
88

99
This stand-alone application adding the possibility of the use of the FlightGear simulator. The system was tested on the [Rascal airplane](https://github.com/ThunderFly-aerospace/FlightGear-Rascal) and [TF-G1](https://github.com/ThunderFly-aerospace/FlightGear-TF-G1) autogyro simulation models.
1010

1111
It connects to FG (over UDP generic protocol) and transforms the data to TCP MAVlink packets for the PX4 stack.
1212

13-
### How to run the development version:
13+
### How to use the FlightGear with PX4
14+
15+
#### Install
1416

15-
#### Install:
1617
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```
1718
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 ```
1819

19-
#### Run:
20+
#### Startup
21+
22+
General usage consists following steps
23+
24+
1) Open [QgroundControl](http://qgroundcontrol.com/)
25+
2) In [PX4Firmware](https://github.com/PX4/PX4-Autopilot) folder run: ```make px4_sitl_nolockstep flightgear_model-name```
26+
3) Wait until FlightGear fully loads.
27+
28+
29+
##### Rascal airplane
30+
31+
1) Open [QgroundControl](http://qgroundcontrol.com/)
32+
2) In PX4Firmware folder run: ```make px4_sitl_nolockstep flightgear_rascal``` for plane with combustion engine. Alternatively you could use ```make px4_sitl_nolockstep flightgear_rascal-electric``` for plane with electric engine model.
33+
3) Wait until FlightGear fully loads.
34+
35+
##### TF-G1 autogyro
36+
2037
1) Open [QgroundControl](http://qgroundcontrol.com/)
21-
2) In PX4Firmware folder run: ```make px4_sitl_nolockstep flightgear_rascal``` for plane.
38+
2) In PX4Firmware folder run: ```make px4_sitl_nolockstep flightgear_tf-g1``` for [TF-G1 autogyro](https://github.com/ThunderFly-aerospace/TF-G1).
2239
3) Wait until FlightGear fully loads.
2340

24-
#### Known issues:
41+
##### TF-G2 autogyro
42+
43+
1) Open [QgroundControl](http://qgroundcontrol.com/)
44+
2) In PX4Firmware folder run: ```make px4_sitl_nolockstep flightgear_tf-g2``` for [TF-G2 autogyro](https://github.com/ThunderFly-aerospace/TF-G2).
45+
3) Wait until FlightGear fully loads.
46+
47+
##### TF-R1 rover
48+
49+
1) Open [QgroundControl](http://qgroundcontrol.com/)
50+
2) In PX4Firmware folder run: ```make px4_sitl_nolockstep flightgear_tf-r1``` for [TF-R1 ground rover](https://github.com/ThunderFly-aerospace/TF-R1).
51+
3) Wait until FlightGear fully loads.
52+
53+
54+
55+
#### Known issues
56+
2557
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.
26-
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.
27-
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).
28-
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.
29-
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.
58+
2) You can probably use a wild set of FG versions - we tested installation with FG 2019.1.1 and 2020.3.8. But in the past, we achieved basic functionality on Debian 9 runnig FG 2016.1.1 from the distribution repository.
59+
3) Multiple models packaged with the bridge have an electric engine that needs up-to-date FlightGear.
60+
5) PX4 internal starting script runs ```fgfs``` with a set of parameters to reduce graphic load.
61+
6) The starting script searches for the FG-Data folder. Run ```fgfs --version``` to check the paths. If your output of this command does not contain the FG_ROOT line, the script will not work. Check where are FG binaries in your system, by executing command ```which fgfs```. Then the Advanced Options section of this readme could help you.
3062

3163
### Advanced Options
3264

@@ -38,15 +70,17 @@ You can tune your FG installation/settings by the following environment variable
3870

3971
FlightGear Bridge and starting script now support multiple instances of PX4. FG\_run script takes the second argument, which is PX4 ID (and automatically adjust the port numbers according to given number) and bridge binary takes this ID as the first argument before the output of get\_FGbridge\_params.py
4072

41-
If you want to test another aircraft with PX4, you need:
73+
If you want to use a currently unsupported FlightGear aircraft with PX4, you need:
4274
1) Add the FlightGear aircraft to ```models``` subdirectory, or to other MODEL PATH searched by FG
4375
2) In ```models``` subdirectory create ```.json``` file.
4476
3) Add model into PX4 make system in file ```platforms/posix/cmake/sitl_target.cmake``` with same name as json file in previous step.
45-
4) You probably will need a PX4 startup script for your vehicle. (vehicle name is the same name as the name of .json file)
77+
4) You probably will need a new PX4 startup script for your vehicle. (vehicle name is the same name as the name of .json file)
78+
79+
If you want test another plane model, you can switch the Rascal model to another type by editing the file ```models/rascal.json```. For example substitute ```Rascal110-YASim``` by ```Rascal110-JSBSim```, or chosen aircraft name.
4680

4781
### Limitations
4882

49-
The PX4 is connected to FlightGear thought "[generic protocol](http://wiki.flightgear.org/Generic_protocol)", which is served synchronously to the simulator graphics engine frame rate. So the PX4 gets the sensor data in frequency, depending on graphics resources and the current scene. The source-code implements artificial upsampling of sensor data to ~100Hz in the order to avoid stale sensor detection. Random noise is added to the sensor data.
83+
The PX4 is connected to FlightGear thought "[generic protocol](http://wiki.flightgear.org/Generic_protocol)", which is served synchronously to the simulator graphics engine frame rate. So the PX4 gets the sensor data in frequency, depending on graphics resources and the current scene. The source-code implements artificial upsampling of sensor data to ~100Hz to avoid stale sensor detection trigger in PX4. Random noise is added to the sensor data.
5084

5185
The possible better approach is to obtain the FlightGear using an [HLA](http://wiki.flightgear.org/High-Level_Architecture) interface.
5286

cmake/FindMAVLink.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ find_path(_MAVLINK_INCLUDE_DIR
4949

5050
# look specifically for the ROS version if no other was found
5151
find_path(_MAVLINK_INCLUDE_DIR
52-
NAMES mavlink/v1.0/mavlink_types.h mavlink/v2.0/mavlink_types.h
53-
PATH_SUFFIXES include
52+
NAMES mavlink_types.h
53+
PATH_SUFFIXES include/mavlink
5454
PATHS /opt/ros/${ROS_DISTRO}/
5555
)
5656

px4bridge.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@
154154
<node>/systems/pitot/measured-total-pressure-inhg</node>
155155
</chunk>
156156

157+
<chunk>
158+
<name>rpm</name>
159+
<type>double</type>
160+
<format>%.3f</format>
161+
<node>/rotors/main/rpm</node>
162+
</chunk>
163+
157164
</output>
158165

159166
<input>

src/fg_communicator.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/****************************************************************************
22
*
3-
* Copyright (c) 2020 ThunderFly s.r.o.. All rights reserved.
3+
* Copyright (c) 2020-2022 ThunderFly s.r.o.. All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
66
* modification, are permitted provided that the following conditions
@@ -173,8 +173,10 @@ int FGCommunicator::Recieve(bool blocking)
173173
swap64(&outputPacket.pressure_inhg);
174174
swap64(&outputPacket.measured_total_pressure_inhg);
175175

176+
swap64(&outputPacket.rpm);
177+
176178
//fprintf(stderr,"FG data recieved\n");
177-
if(outputPacket.elapsed_sec>0)
179+
if(outputPacket.elapsed_sec>5)
178180
vehicle->setFGData(outputPacket);
179181
else
180182
return 0;

src/fg_communicator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/****************************************************************************
22
*
3-
* Copyright (c) 2020 ThunderFly s.r.o.. All rights reserved.
3+
* Copyright (c) 2020-2022 ThunderFly s.r.o.. All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
66
* modification, are permitted provided that the following conditions

src/flightgear_bridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ int main(int argc, char **argv)
9595
{
9696
cerr << "I'm Mavlink to FlightGear Bridge" << endl;;
9797

98-
int delay_us = 5000;
98+
int delay_us = 2000;
9999
bool havePxData = false;
100100
bool haveFGData = false;
101101
bool sendEveryStep = true;

src/px4_communicator.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ int PX4Communicator::Send(int offset_us)
173173

174174
mavlink_msg_hil_sensor_encode_chan(1, 200, MAVLINK_COMM_0, &msg, &sensor_msg);
175175
packetlen = mavlink_msg_to_send_buffer(buffer, &msg);
176-
send(px4MavlinkSock, buffer, packetlen, 0);
177176
if(send(px4MavlinkSock, buffer, packetlen, 0)!=packetlen)
178177
{
179178
std::cerr << "PX4 Communicator: Sent to PX4 failed: "<< strerror(errno) <<std::endl;
@@ -191,6 +190,18 @@ int PX4Communicator::Send(int offset_us)
191190
return -1;
192191
}
193192

193+
194+
mavlink_raw_rpm_t rpmmessage;
195+
rpmmessage.index=0;
196+
rpmmessage.frequency=vehicle->rpm;
197+
mavlink_msg_raw_rpm_encode_chan(1, 200, MAVLINK_COMM_0, &msg, &rpmmessage);
198+
packetlen = mavlink_msg_to_send_buffer(buffer, &msg);
199+
if(send(px4MavlinkSock, buffer, packetlen, 0)!=packetlen)
200+
{
201+
std::cerr << "PX4 Communicator: Sent to PX4 failed: " << strerror(errno) <<std::endl;
202+
return -1;
203+
}
204+
194205
return 0;
195206
}
196207

0 commit comments

Comments
 (0)