23 from weather_reporter_factory
import WeatherReporterFactory
25 from rapp_utilities
import RappUtilities
26 from rapp_exceptions
import RappError
28 from rapp_platform_ros_communications.msg
import WeatherForecastMsg
30 from rapp_platform_ros_communications.srv
import (
31 WeatherReporterCurrentSrv,
32 WeatherReporterCurrentSrvResponse,
33 WeatherReporterForecastSrv,
34 WeatherReporterForecastSrvResponse
47 if rospy.has_param(
'rapp_weather_current_topic'):
49 rospy.get_param(
"rapp_weather_current_topic")
52 RappUtilities.rapp_print(
'Weather Reporter Current Weather topic not found!',
'ERROR')
54 current_weather_service = rospy.Service(
58 if rospy.has_param(
'rapp_weather_forecast_topic'):
60 rospy.get_param(
"rapp_weather_forecast_topic")
63 RappUtilities.rapp_print(
'Weather Reporter Forecast topic not found!',
'ERROR')
65 forecast_weather_service = rospy.Service(
79 response = WeatherReporterCurrentSrvResponse()
83 select_weather_reporter(req.weather_reporter)
84 except RappError
as err:
85 response.error = str(err)
88 results = w_reporter.fetch_current_weather(req)
89 except RappError
as err:
90 response.error = str(err)
105 response = WeatherReporterForecastSrvResponse()
109 select_weather_reporter(req.weather_reporter)
110 except RappError
as err:
111 response.error = str(err)
114 results = w_reporter.fetch_weather_forecast(req)
115 except RappError
as err:
116 response.error = str(err)
130 response = WeatherReporterCurrentSrvResponse()
132 response.date = result[
'date']
133 response.temperature = result[
'temperature']
134 response.weather_description = result[
'weather_description']
135 response.humidity = result[
'humidity']
136 response.visibility = result[
'visibility']
137 response.pressure = result[
'pressure']
138 response.wind_speed = result[
'wind_speed']
139 response.wind_temperature = result[
'wind_temperature']
140 response.wind_direction = result[
'wind_direction']
145 response = WeatherReporterForecastSrvResponse()
148 msg = WeatherForecastMsg()
149 msg.high_temperature = res[
'high_temperature']
150 msg.low_temperature = res[
'low_temperature']
151 msg.description = res[
'description']
152 msg.date = res[
'date']
153 response.forecast.append(msg)
156 if __name__ ==
"__main__":
157 rospy.init_node(
'WeatherReporter')
159 RappUtilities.rapp_print(
"Weather Reporter node initialized")
def _create_current_service_response
Creates proper response.
def _create_forecast_service_response
def fetch_current_weather_srv_callback
The callback to fetch current weather.
_weather_reporter_factory
Factory that returns proper weather_reporter.
Evaluates weather conditions.
def fetch_forecast_srv_callback
The callback to fetch weather forecast.