mirror of https://github.com/ArduPilot/ardupilot
SITL: make it easier to start ArduPlane SITL at any location
this generates a jsbsim startup XML file from a template
This commit is contained in:
parent
93f45f232f
commit
b018d7ba77
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<initialize name="Start up at Canberra Model Aircraft Club">
|
||||||
|
<latitude unit="DEG"> %(LATITUDE)s </latitude>
|
||||||
|
<longitude unit="DEG"> %(LONGITUDE)s </longitude>
|
||||||
|
<altitude unit="M"> 0 </altitude>
|
||||||
|
<vt unit="FT/SEC"> 0.0 </vt>
|
||||||
|
<gamma unit="DEG"> 0.0 </gamma>
|
||||||
|
<phi unit="DEG"> 0.0 </phi>
|
||||||
|
<theta unit="DEG"> 0.0 </theta>
|
||||||
|
<psi unit="DEG"> %(HEADING)s </psi>
|
||||||
|
</initialize>
|
|
@ -8,7 +8,7 @@
|
||||||
test ArduPlane using Rascal110 and JSBSim
|
test ArduPlane using Rascal110 and JSBSim
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<use aircraft="Rascal" initialize="reset_CMAC"/>
|
<use aircraft="Rascal" initialize="reset"/>
|
||||||
|
|
||||||
<!-- we control the servos via the jsbsim console
|
<!-- we control the servos via the jsbsim console
|
||||||
interface on TCP 5124 -->
|
interface on TCP 5124 -->
|
||||||
|
|
|
@ -31,23 +31,25 @@ def jsb_set(variable, value):
|
||||||
global jsb_console
|
global jsb_console
|
||||||
jsb_console.send('set %s %s\r\n' % (variable, value))
|
jsb_console.send('set %s %s\r\n' % (variable, value))
|
||||||
|
|
||||||
def setup_home(home):
|
def setup_template(home):
|
||||||
'''setup home location'''
|
'''setup aircraft/Rascal/reset.xml'''
|
||||||
v = home.split(',')
|
v = home.split(',')
|
||||||
if len(v) != 4:
|
if len(v) != 4:
|
||||||
print("home should be lat,lng,alt,hdg")
|
print("home should be lat,lng,alt,hdg - '%s'" % home)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
latitude = float(v[0])
|
latitude = float(v[0])
|
||||||
longitude = float(v[1])
|
longitude = float(v[1])
|
||||||
altitude = float(v[2])
|
altitude = float(v[2])
|
||||||
heading = float(v[3])
|
heading = float(v[3])
|
||||||
sitl_state.ground_height = altitude
|
sitl_state.ground_height = altitude
|
||||||
|
template = os.path.join('aircraft', 'Rascal', 'reset_template.xml')
|
||||||
jsb_set('position/lat-gc-deg', latitude)
|
reset = os.path.join('aircraft', 'Rascal', 'reset.xml')
|
||||||
jsb_set('position/long-gc-deg', longitude)
|
xml = open(template).read() % { 'LATITUDE' : str(latitude),
|
||||||
jsb_set('attitude/psi-rad', math.radians(heading))
|
'LONGITUDE' : str(longitude),
|
||||||
jsb_set('attitude/phi-rad', 0)
|
'HEADING' : str(heading) }
|
||||||
jsb_set('attitude/theta-rad', 0)
|
open(reset, mode='w').write(xml)
|
||||||
|
print("Wrote %s" % reset)
|
||||||
|
|
||||||
|
|
||||||
def process_sitl_input(buf):
|
def process_sitl_input(buf):
|
||||||
'''process control changes from SITL sim'''
|
'''process control changes from SITL sim'''
|
||||||
|
@ -142,6 +144,8 @@ os.chdir(util.reltopdir('Tools/autotest'))
|
||||||
# kill off child when we exit
|
# kill off child when we exit
|
||||||
atexit.register(util.pexpect_close_all)
|
atexit.register(util.pexpect_close_all)
|
||||||
|
|
||||||
|
setup_template(opts.home)
|
||||||
|
|
||||||
# start child
|
# start child
|
||||||
cmd = "JSBSim --realtime --suspend --nice --simulation-rate=1000 --logdirectivefile=jsbsim/fgout.xml --script=%s" % opts.script
|
cmd = "JSBSim --realtime --suspend --nice --simulation-rate=1000 --logdirectivefile=jsbsim/fgout.xml --script=%s" % opts.script
|
||||||
if opts.options:
|
if opts.options:
|
||||||
|
@ -198,9 +202,6 @@ if opts.fgout:
|
||||||
# setup wind generator
|
# setup wind generator
|
||||||
wind = util.Wind(opts.wind)
|
wind = util.Wind(opts.wind)
|
||||||
|
|
||||||
|
|
||||||
setup_home(opts.home)
|
|
||||||
|
|
||||||
fdm = fgFDM.fgFDM()
|
fdm = fgFDM.fgFDM()
|
||||||
|
|
||||||
jsb_console.send('info\n')
|
jsb_console.send('info\n')
|
||||||
|
|
Loading…
Reference in New Issue