3 from __future__
import absolute_import, print_function, division
4 from mesonh_atmosphere
import MesoNHAtmosphere
16 PPRZ_HOME = getenv(
"PAPARAZZI_HOME", os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'../../../')))
17 sys.path.append(PPRZ_HOME +
"/var/lib/python")
19 from pprzlink.ivy
import IvyMessagesInterface
20 from pprzlink.message
import PprzMessage
25 origin = np.array([0, 0, 0, 0])
26 scale = np.array([1., 1/M_IN_KM, 1/M_IN_KM, 1/M_IN_KM])
28 start_time = time.time()
32 t = time.time() - start_time
34 print(
"north :",north)
36 loc = np.array([t, up, east, north])
37 loc = loc*scale + origin
39 weast, wnorth, wup = atm.get_wind(loc)
40 return weast, wnorth, wup
45 Ivy Callback for Paparazzi Requests
48 if msg.msg_class ==
"ground" and msg.name ==
"WORLD_ENV_REQ":
57 Callback for paparazzi WORLD_ENV requests
60 east, north, up = float(msg.get_field(3)),\
61 float(msg.get_field(4)),\
62 float(msg.get_field(5))
65 weast, wnorth, wup =
get_wind(east, north, up)
70 msg_back=PprzMessage(
"ground",
"WORLD_ENV")
71 msg_back.set_value_by_name(
"wind_east",weast)
72 msg_back.set_value_by_name(
"wind_north",wnorth)
73 msg_back.set_value_by_name(
"wind_up",wup)
74 msg_back.set_value_by_name(
"ir_contrast",400)
75 msg_back.set_value_by_name(
"time_scale",1)
76 msg_back.set_value_by_name(
"gps_availability",1)
77 ivy.send(msg_back,
None)
81 print(
'\nShutting down IVY...')
90 argp = ap.ArgumentParser(description=
"Environment variables provider "
91 "for Paparazzi simulation from MesoNH data")
93 argp.add_argument(
"-t",
"--time-step", required=
True, type=int,
94 help=
"Duration of a time step between MesoNH Files.")
95 argp.add_argument(
"-f",
"--files", required=
True, nargs=
'+',
96 help=
"MesoNH netCDF files, in temporal ordering")
97 argp.add_argument(
"-x",
"--origin-x", required=
False, type=float,
99 help=
"Origin translation x.")
100 argp.add_argument(
"-y",
"--origin-y", required=
False, type=float,
102 help=
"Origin translation y.")
103 argp.add_argument(
"-z",
"--origin-z", required=
False, type=float,
105 help=
"Origin translation z.")
106 arguments = argp.parse_args()
111 signal.signal(signal.SIGINT, signal_handler)
115 origin = np.array([0, arguments.origin_z, arguments.origin_x, arguments.origin_y])
123 ivy = IvyMessagesInterface(
"MesoNH");
124 ivy.subscribe(worldenv_cb,
'(.* WORLD_ENV_REQ .*)')
127 from ivy.std_api
import IvyMainLoop
132 if __name__ ==
'__main__':
def get_wind(east, north, up)
def worldenv_cb(ac_id, msg)
def ivy_request_callback(sender, msg, resp, *args, **kwargs)
def signal_handler(signal, frame)