1 from __future__
import absolute_import, print_function, division
2 from mesonh_atmosphere
import MesoNHAtmosphere
14 PPRZ_SRC = getenv(
"PAPARAZZI_SRC", os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'../../../')))
15 sys.path.append(PPRZ_SRC +
"/sw/ext/pprzlink/lib/v1.0/python")
17 from pprzlink.ivy
import IvyMessagesInterface
18 from pprzlink.message
import PprzMessage
23 origin = np.array([0, 0, 0, 0])
24 scale = np.array([1., 1/M_IN_KM, 1/M_IN_KM, 1/M_IN_KM])
26 start_time = time.time()
30 t = time.time() - start_time
32 print(
"north :",north)
34 loc = np.array([t, up, east, north])
35 loc = loc*scale + origin
37 weast, wnorth, wup = atm.get_wind(loc)
38 return weast, wnorth, wup
43 Ivy Callback for Paparazzi Requests
46 if msg.msg_class ==
"ground" and msg.name ==
"WORLD_ENV_REQ":
55 Callback for paparazzi WORLD_ENV requests
58 east, north, up = float(msg.get_field(3)),\
59 float(msg.get_field(4)),\
60 float(msg.get_field(5))
63 weast, wnorth, wup =
get_wind(east, north, up)
68 msg_back=PprzMessage(
"ground",
"WORLD_ENV")
69 msg_back.set_value_by_name(
"wind_east",weast)
70 msg_back.set_value_by_name(
"wind_north",wnorth)
71 msg_back.set_value_by_name(
"wind_up",wup)
72 msg_back.set_value_by_name(
"ir_contrast",400)
73 msg_back.set_value_by_name(
"time_scale",1)
74 msg_back.set_value_by_name(
"gps_availability",1)
75 ivy.send(msg_back,
None)
79 print(
'\nShutting down IVY...')
88 argp = ap.ArgumentParser(description=
"Environment variables provider "
89 "for Paparazzi simulation from MesoNH data")
91 argp.add_argument(
"-t",
"--time-step", required=
True, type=int,
92 help=
"Duration of a time step between MesoNH Files.")
93 argp.add_argument(
"-f",
"--files", required=
True, nargs=
'+',
94 help=
"MesoNH netCDF files, in temporal ordering")
95 argp.add_argument(
"-x",
"--origin-x", required=
False, type=float,
97 help=
"Origin translation x.")
98 argp.add_argument(
"-y",
"--origin-y", required=
False, type=float,
100 help=
"Origin translation y.")
101 argp.add_argument(
"-z",
"--origin-z", required=
False, type=float,
103 help=
"Origin translation z.")
104 arguments = argp.parse_args()
109 signal.signal(signal.SIGINT, signal_handler)
113 origin = np.array([0, arguments.origin_z, arguments.origin_x, arguments.origin_y])
117 atm = MesoNHAtmosphere(arguments.files, arguments.time_step, tinit=0)
121 ivy = IvyMessagesInterface(
"MesoNH");
122 ivy.subscribe(worldenv_cb,
'(.* WORLD_ENV_REQ .*)')
125 from ivy.std_api
import IvyMainLoop
130 if __name__ ==
'__main__':