def __init__(self, _id, name, waypoint, arrow, route, spot):
        super().__init__(_id, name, waypoint, arrow, route)

        self.waypoint = waypoint
        self.arrow = arrow
        self.route = route
        self.spot = spot
        self.relation = Relation()
        self.__bus_routes = {}
        self.__bus_schedules = {}

        self.bus_parkable_spots = self.spot.get_spots_of_target_group(
            Target.new_node_target(SimBus))

        self.vehicle_statuses = self.manager.dict()
        self.vehicle_statuses_lock = self.manager.Lock()

        self.vehicle_schedules = {}
        self.vehicle_last_indices = {}
        self.bus_schedules = {}
        self.bus_stop_spots = {}
        self.state_machines = {}

        self.__topicPubVehicleSchedules = Topic()
        self.__topicPubVehicleSchedules.set_categories(
            FleetManager.CONST.TOPIC.CATEGORIES.SCHEDULES)

        self.__topicSubVehicleStatus = Topic()
        self.__topicSubVehicleStatus.set_targets(
            Target.new_target(None, SIM_BUS.NODE_NAME), None)
        self.__topicSubVehicleStatus.set_categories(
            Vehicle.CONST.TOPIC.CATEGORIES.STATUS)
        self.__topicSubVehicleStatus.set_message(VehicleStatus)
        self.set_subscriber(self.__topicSubVehicleStatus,
                            self.update_vehicle_status)
Beispiel #2
0
    def __init__(self, name, waypoint, dt=1.0):
        super().__init__()

        self.topicUserPublish = Topic()
        self.topicUserPublish.set_id(self.event_loop_id)
        self.topicUserPublish.set_root(User.TOPIC.PUBLISH)
        self.topicUserPublish.set_message(user_message)

        self.topicUserSubscribe = Topic()
        self.topicUserSubscribe.set_id(self.event_loop_id)
        self.topicUserSubscribe.set_root(User.TOPIC.SUBSCRIBE)
        self.topicUserSubscribe.set_message(user_message)

        self.name = name
        self.id = self.event_loop_id
        self.state = User.STATE.LOGIN
        self.event = None
        self.action = None
        self.dt = dt
        self.__start_waypoint_id = None
        self.__goal_waypoint_id = None
        self.__vehicleID = None

        self.__waypoint = waypoint

        self.add_on_message_function(self.update_action)
        self.add_on_message_function(self.update_event)

        self.set_subscriber(self.topicUserSubscribe.private + "/schedules")
        self.set_subscriber(self.topicUserSubscribe.private + "/event")
        self.set_main_loop(self.__main_loop)
Beispiel #3
0
    def __init__(self,
                 name,
                 waypoint,
                 arrow,
                 route,
                 waypoint_id,
                 velocity,
                 schedules=None,
                 dt=1.0):
        super().__init__(name, waypoint, arrow, route, waypoint_id, velocity,
                         schedules, dt)

        self.name = name

        self.autowarePublishTopic = Topic()
        self.autowarePublishTopic.set_id(self.name)
        self.autowarePublishTopic.set_root(Autoware.TOPIC.PUBLISH)
        self.autowarePublishTopic.set_message(autoware_message)

        self.autowareSubscribeTopic = Topic()
        self.autowareSubscribeTopic.set_id(self.name)
        self.autowareSubscribeTopic.set_root(Autoware.TOPIC.SUBSCRIBE)
        self.autowareSubscribeTopic.set_message(autoware_message)

        self.pose_index = 0
        self.current_poses = []

        self.add_on_message_function(self.set_autoware_pose)
        self.set_subscriber(self.autowareSubscribeTopic.private +
                            "/closest_waypoint")
    def __init__(self, _id, name, waypoint, arrow, route, dt=3.0):
        super().__init__(_id)

        self.status = FleetStatus.new_data(name=name,
                                           time=time(),
                                           state=FLEET_MANAGER.STATE.LOG_IN,
                                           relations={})

        self.waypoint = waypoint
        self.arrow = arrow
        self.route = route
        self.relation = Relation()
        self.traffic_signals = self.manager.dict()
        self.state_machine = None
        self.dt = dt

        self.__pubTopicStatus = Topic()
        self.__pubTopicStatus.set_targets(self.target)
        self.__pubTopicStatus.set_categories(
            FLEET_MANAGER.TOPIC.CATEGORIES.STATUS)

        self.__topicSubTrafficSignalStatus = Topic()
        self.__topicSubTrafficSignalStatus.set_targets(
            Target.new_target(None, TRAFFIC_SIGNAL.NODE_NAME), None)
        self.__topicSubTrafficSignalStatus.set_categories(
            TRAFFIC_SIGNAL.TOPIC.CATEGORIES.STATUS)
        self.__topicSubTrafficSignalStatus.set_message(TrafficSignalStatus)
        self.set_subscriber(self.__topicSubTrafficSignalStatus,
                            self.update_traffic_signal_status)

        self.set_main_loop(self.__main_loop)
Beispiel #5
0
    def __init__(self, _id, name, dt=1.0):
        super().__init__(_id)

        self.status = UserStatus.new_data(
            name=name,
            time=time(),
            trip_schedules=None,
            state=USER.STATE.LOG_IN,
            schedule=None
        )

        self.state_machine = None
        self.dt = dt

        self.schedules = self.manager.list()
        self.schedules_lock = self.manager.Lock()

        self.__topicPubStatus = Topic()
        self.__topicPubStatus.set_targets(self.target)
        self.__topicPubStatus.set_categories(USER.TOPIC.CATEGORIES.STATUS)

        self.__topicSubSchedules = Topic()
        self.__topicSubSchedules.set_targets(None, self.target)
        self.__topicSubSchedules.set_categories(FLEET_MANAGER.TOPIC.CATEGORIES.SCHEDULES)
        self.__topicSubSchedules.set_message(Schedules)
        self.set_subscriber(self.__topicSubSchedules, self.update_schedules)

        self.set_main_loop(self.__main_loop)
Beispiel #6
0
    def __init__(self, _id, name, waypoint, arrow, route, dt=1.0):
        super().__init__(_id)

        self.status = VehicleStatus.new_data(name=name,
                                             time=time(),
                                             state=VEHICLE.STATE.LOG_IN,
                                             schedule=None,
                                             location=None,
                                             pose=None)

        self.waypoint = waypoint
        self.arrow = arrow
        self.route = route
        self.state_machine = None
        self.np_position = None
        self.dt = dt

        self.schedules = self.manager.list()
        self.schedules_lock = self.manager.Lock()

        self.__topicPubStatus = Topic()
        self.__topicPubStatus.set_targets(self.target)
        self.__topicPubStatus.set_categories(VEHICLE.TOPIC.CATEGORIES.STATUS)

        self.__topicSubSchedules = Topic()
        self.__topicSubSchedules.set_targets(None, self.target)
        self.__topicSubSchedules.set_categories(
            FLEET_MANAGER.TOPIC.CATEGORIES.SCHEDULES)
        self.__topicSubSchedules.set_message(Schedules)
        self.set_subscriber(self.__topicSubSchedules, self.update_schedules)

        self.__topicPubGeotopic = Topic()
        self.__topicPubGeotopic.set_targets(self.target, None)

        self.set_main_loop(self.__main_loop)
Beispiel #7
0
    def __init__(self, _id):
        self.manager = Manager()

        self.event_loop_id = _id
        self.target = Target.new_target(self.event_loop_id,
                                        self.__class__.__name__)
        self.__subscribers = {}
        self.__subscribers_lock = self.manager.Lock()
        self.__publishers = {}
        self.__client = None
        self.__main_loop = None
        self.__pid = os.getpid()

        self.__topicPub = Topic()
        self.__topicPub.set_targets(
            Target.new_target(self.event_loop_id, EventLoop.__name__))
        self.__topicPub.set_categories(EVENT_LOOP.TOPIC.CATEGORIES.RESPONSE)

        self.__topicSub = Topic()
        self.__topicSub.set_targets(
            None, Target.new_target(self.event_loop_id, EventLoop.__name__))
        self.__topicSub.set_categories(EVENT_LOOP.TOPIC.CATEGORIES.REQUEST)
        self.__topicSub.set_message(EventLoopMessage)
        self.set_subscriber(self.__topicSub, self.on_event_loop_message)

        self.__user_data = None
        self.__user_will = None
Beispiel #8
0
    def __init__(self, name, processing_cycle=1.0):
        super().__init__()

        self.trafficSignalPublishTopic = Topic()
        self.trafficSignalPublishTopic.set_id(self.event_loop_id)
        self.trafficSignalPublishTopic.set_root(TrafficSignal.TOPIC.PUBLISH)
        self.trafficSignalPublishTopic.set_message(traffic_signal_message)

        self.trafficSignalSubscribeTopic = Topic()
        self.trafficSignalSubscribeTopic.set_id(self.event_loop_id)
        self.trafficSignalSubscribeTopic.set_root(
            TrafficSignal.TOPIC.SUBSCRIBE)
        self.trafficSignalSubscribeTopic.set_message(traffic_signal_message)

        self.name = name
        self.routes = {}
        self.schedules = {}
        self.cycles = {}
        self.__processing_cycle = processing_cycle
        self.__check_time = time()
        self.__publish_flag = False

        self.add_on_message_function(self.update_routes)
        self.add_on_message_function(self.update_schedules)
        self.add_on_message_function(self.update_cycles)
        self.set_subscriber(self.trafficSignalSubscribeTopic.private +
                            "/routes")
        self.set_subscriber(self.trafficSignalSubscribeTopic.private +
                            "/schedules")
        self.set_subscriber(self.trafficSignalSubscribeTopic.private +
                            "/cycles")
        self.set_main_loop(self.__main_loop)
Beispiel #9
0
    def __init__(self,
                 _id,
                 name,
                 waypoint,
                 arrow,
                 route,
                 intersection,
                 dt=1.0):
        super().__init__(_id,
                         name,
                         waypoint,
                         arrow,
                         route,
                         intersection,
                         dt=dt)

        self.state_machine = self.get_state_machine()

        self.user_statuses = self.manager.dict()
        self.user_statuses_lock = self.manager.Lock()

        self.__topicSubUserStatus = Topic()
        self.__topicSubUserStatus.set_targets(
            Target.new_target(None, SIM_BUS_USER.NODE_NAME), None)
        self.__topicSubUserStatus.set_categories(USER.TOPIC.CATEGORIES.STATUS)
        self.__topicSubUserStatus.set_message(UserStatus)
        self.set_subscriber(self.__topicSubUserStatus, self.update_user_status)
Beispiel #10
0
    def __init__(self,
                 name,
                 waypoint,
                 arrow,
                 route,
                 intersection,
                 waypoint_id,
                 velocity,
                 schedules=None,
                 dt=1.0):
        super().__init__(name, waypoint, arrow, route, waypoint_id, velocity,
                         schedules, dt)

        self.topicTrafficSignalPublish = Topic()
        self.topicTrafficSignalPublish.set_root(TrafficSignal.TOPIC.PUBLISH)
        self.topicTrafficSignalPublish.set_message(traffic_signal_message)

        self.__prev_waypoint_id = waypoint_id

        self.traffic_signals = {}
        self.other_vehicles = {}

        self.intersection = intersection

        self.add_on_message_function(self.set_other_vehicle_poses)
        self.add_on_message_function(self.set_traffic_signals)

        self.set_subscriber(self.topicVehiclePublish.all)
        self.set_subscriber(self.topicTrafficSignalPublish.all)
Beispiel #11
0
def request_fleet_relations():
    topic = Topic()
    topic.set_root(FleetManager.TOPIC.SUBSCRIBE)
    topic.set_message(fleet_manager_message)
    message = topic.get_template()
    message["action"] = FleetManager.ACTION.PUBLISH_RELATIONS
    mqtt.publish(topic.root, topic.serialize(message))
    return api_response(code=200, message={"result": "requested"})
Beispiel #12
0
    def __init__(self,
                 _id,
                 name,
                 waypoint,
                 arrow,
                 route,
                 intersection,
                 dt=1.0):
        super().__init__(_id, name, waypoint, arrow, route, dt=dt)

        self.state_machine = self.get_state_machine()
        self.velocity = None

        self.traffic_signals = self.manager.dict()
        self.traffic_signals_lock = self.manager.Lock()
        self.other_vehicle_locations = self.manager.dict()
        self.other_vehicle_locations_lock = self.manager.Lock()
        self.intersection = intersection

        self.__topicPubLocation = Topic()
        self.__topicPubLocation.set_targets(
            Target.new_target(self.target.id, SIM_CAR.NODE_NAME))
        self.__topicPubLocation.set_categories(
            SIM_CAR.TOPIC.CATEGORIES.LOCATION)

        self.__topicSubStatus = Topic()
        self.__topicSubStatus.set_targets(
            Target.new_target(None, SIM_CAR.NODE_NAME), None)
        self.__topicSubStatus.set_categories(SIM_CAR.TOPIC.CATEGORIES.LOCATION)
        self.__topicSubStatus.set_message(Location)
        self.set_subscriber(self.__topicSubStatus,
                            self.update_other_vehicle_locations)

        self.__topicSubTrafficSignalStatus = Topic()
        self.__topicSubTrafficSignalStatus.set_targets(
            Target.new_target(None, TRAFFIC_SIGNAL.NODE_NAME), None)
        self.__topicSubTrafficSignalStatus.set_categories(
            TRAFFIC_SIGNAL.TOPIC.CATEGORIES.STATUS)
        self.__topicSubTrafficSignalStatus.set_message(TrafficSignalStatus)
        self.set_subscriber(self.__topicSubTrafficSignalStatus,
                            self.update_traffic_signals)
Beispiel #13
0
    def __init__(self, name, waypoint, arrow, route, waypoint_id, velocity, schedules=None, dt=1.0):
        super().__init__()

        self.topicVehiclePublish = Topic()
        self.topicVehiclePublish.set_id(self.event_loop_id)
        self.topicVehiclePublish.set_root(Vehicle.TOPIC.PUBLISH)
        self.topicVehiclePublish.set_message(vehicle_message)

        self.topicVehicleSubscribe = Topic()
        self.topicVehicleSubscribe.set_id(self.event_loop_id)
        self.topicVehicleSubscribe.set_root(Vehicle.TOPIC.SUBSCRIBE)
        self.topicVehicleSubscribe.set_message(vehicle_message)

        self.topicGeoVehiclePublish = Topic()
        self.topicGeoVehiclePublish.set_id(self.event_loop_id)
        self.topicGeoVehiclePublish.set_root(Vehicle.TOPIC.GEO.PUBLISH)
        self.topicGeoVehiclePublish.set_message(geo_vehicle_message)

        self.name = name
        self.state = Vehicle.STATE.STOP
        self.event = None
        self.action = None
        self.waypoint = waypoint
        self.arrow = arrow
        self.route = route
        self.waypoint_id = waypoint_id
        self.position = self.waypoint.get_position(self.waypoint_id)
        self.velocity = velocity
        self.schedules = schedules
        self.dt = dt

        self.arrow_code = self.arrow.get_arrow_codes_from_waypoint_id(waypoint_id)[0]
        self.position = self.waypoint.get_position(self.waypoint_id)
        self.yaw = self.arrow.get_heading(self.arrow_code, self.waypoint_id)

        self.add_on_message_function(self.update_schedules)
        self.add_on_message_function(self.update_event)
        self.set_subscriber(self.topicVehicleSubscribe.private+"/schedules")
        self.set_subscriber(self.topicVehicleSubscribe.private+"/event")
        self.set_main_loop(self.__main_loop)
    def __init__(self, _id, name, waypoint, arrow, route):
        super().__init__(_id, name, waypoint, arrow, route)

        self.waypoint = waypoint
        self.arrow = arrow
        self.route = route

        self.user_statuses = self.manager.dict()
        self.user_statuses_lock = self.manager.Lock()

        self.vehicle_statuses = self.manager.dict()
        self.vehicle_statuses_lock = self.manager.Lock()

        self.user_schedules = {}
        self.vehicle_schedules = {}
        self.state_machines = {}

        self.__topicPubUserSchedules = Topic()
        self.__topicPubUserSchedules.set_categories(
            FLEET_MANAGER.TOPIC.CATEGORIES.SCHEDULES)

        self.__topicPubVehicleSchedules = Topic()
        self.__topicPubVehicleSchedules.set_categories(
            FLEET_MANAGER.TOPIC.CATEGORIES.SCHEDULES)

        self.__topicSubUserStatus = Topic()
        self.__topicSubUserStatus.set_targets(
            Target.new_target(None, SIM_TAXI_USER.NODE_NAME), None)
        self.__topicSubUserStatus.set_categories(USER.TOPIC.CATEGORIES.STATUS)
        self.__topicSubUserStatus.set_message(UserStatus)
        self.set_subscriber(self.__topicSubUserStatus, self.update_user_status)

        self.__topicSubVehicleStatus = Topic()
        self.__topicSubVehicleStatus.set_targets(
            Target.new_target(None, SIM_TAXI.NODE_NAME), None)
        self.__topicSubVehicleStatus.set_categories(
            VEHICLE.TOPIC.CATEGORIES.STATUS)
        self.__topicSubVehicleStatus.set_message(VehicleStatus)
        self.set_subscriber(self.__topicSubVehicleStatus,
                            self.update_vehicle_status)
    def __init__(self, name):
        super(LaneArrayPublisher, self).__init__()

        self.autowarePublishTopic = Topic()
        self.autowarePublishTopic.set_id(name)
        self.autowarePublishTopic.set_root(Autoware.TOPIC.PUBLISH)
        self.autowarePublishTopic.set_message(autoware_message)

        self.add_on_message_function(self.publish_to_ros)
        self.set_subscriber(self.autowarePublishTopic.private+"/waypoints")

        rospy.init_node("ams_lane_array_publisher", anonymous=True)
        self.__ROSPublisher = rospy.Publisher(Autoware.ROSTOPIC.PUBLISH, LaneArray)
Beispiel #16
0
    def __init__(self,
                 _id,
                 route_code,
                 state=TRAFFIC_SIGNAL.STATE.UNKNOWN,
                 processing_cycle=1.0):
        super().__init__(_id)

        self.route_code = route_code
        self.state = state

        self.schedules = []
        self.cycle = None
        self.__processing_cycle = processing_cycle
        self.__check_time = time()
        self.__publish_flag = False

        self.__topicPubStatus = Topic()
        self.__topicPubStatus.set_targets(self.target)
        self.__topicPubStatus.set_categories(
            TRAFFIC_SIGNAL.TOPIC.CATEGORIES.STATUS)

        self.__topicSubSchedules = Topic()
        self.__topicSubSchedules.set_targets(None, self.target)
        self.__topicSubSchedules.set_categories(
            TRAFFIC_SIGNAL.TOPIC.CATEGORIES.SCHEDULES)
        self.__topicSubSchedules.set_message(Schedules)
        self.set_subscriber(self.__topicSubSchedules, self.update_schedules)

        self.__topicSubCycle = Topic()
        self.__topicSubCycle.set_targets(None, self.target)
        self.__topicSubCycle.set_categories(
            TRAFFIC_SIGNAL.TOPIC.CATEGORIES.CYCLE)
        self.__topicSubCycle.set_message(Cycle)
        self.set_subscriber(self.__topicSubCycle, self.update_cycle)

        self.set_main_loop(self.__main_loop)
Beispiel #17
0
    def __init__(self, waypoint, arrow, route):
        super().__init__()

        self.topicUserPublish = Topic()
        self.topicUserPublish.set_root(User.TOPIC.PUBLISH)
        self.topicUserPublish.set_message(user_message)

        self.topicUserSubscribe = Topic()
        self.topicUserSubscribe.set_root(User.TOPIC.SUBSCRIBE)
        self.topicUserSubscribe.set_message(user_message)

        self.topicVehiclePublish = Topic()
        self.topicVehiclePublish.set_root(Vehicle.TOPIC.PUBLISH)
        self.topicVehiclePublish.set_message(vehicle_message)

        self.topicVehicleSubscribe = Topic()
        self.topicVehicleSubscribe.set_root(Vehicle.TOPIC.SUBSCRIBE)
        self.topicVehicleSubscribe.set_message(vehicle_message)

        self.topicTrafficSignalPublish = Topic()
        self.topicTrafficSignalPublish.set_root(TrafficSignal.TOPIC.PUBLISH)
        self.topicTrafficSignalPublish.set_message(traffic_signal_message)

        self.topicFleetManagerPublish = Topic()
        self.topicFleetManagerPublish.set_id(self.event_loop_id)
        self.topicFleetManagerPublish.set_root(FleetManager.TOPIC.PUBLISH)
        self.topicFleetManagerPublish.set_message(fleet_manager_message)

        self.topicFleetManagerSubscribe = Topic()
        self.topicFleetManagerSubscribe.set_id(self.event_loop_id)
        self.topicFleetManagerSubscribe.set_root(FleetManager.TOPIC.SUBSCRIBE)
        self.topicFleetManagerSubscribe.set_message(fleet_manager_message)

        self.waypoint = waypoint
        self.arrow = arrow
        self.route = route

        self.users = {}
        self.vehicles = {}
        self.traffic_signals = {}
        self.relations = {}  # vehicle_id -> user_id, user_id -> vehicle_id

        self.add_on_message_function(self.update_user_status)
        self.add_on_message_function(self.update_vehicle_status)
        self.add_on_message_function(self.update_traffic_signal_status)
        self.add_on_message_function(self.response_request)

        self.set_subscriber(self.topicUserPublish.all)
        self.set_subscriber(self.topicVehiclePublish.all)
        self.set_subscriber(self.topicTrafficSignalPublish.all)
        self.set_subscriber(self.topicFleetManagerSubscribe.all)
Beispiel #18
0
    def __init__(self, _id=None):
        self.event_loop_id = _id
        if _id is None:
            self.event_loop_id = str(uuid())

        self.__subscribeTopic = Topic()
        self.__subscribeTopic.set_id(self.event_loop_id)
        self.__subscribeTopic.set_root(EventLoop.TOPIC.SUBSCRIBE)
        self.__subscribeTopic.set_message(event_loop_message)

        self.__publishTopic = Topic()
        self.__publishTopic.set_id(self.event_loop_id)
        self.__publishTopic.set_root(EventLoop.TOPIC.PUBLISH)
        self.__publishTopic.set_message(event_loop_message)

        self.__subscribers = {}
        self.__publishers = {}
        self.__client = None
        self.__main_loop = None
        self.__pid = os.getpid()
        self.set_subscriber(self.__subscribeTopic.private)
        self.__on_message_functions = []
        self.__user_data = None
        self.__user_will = None
    def __init__(self, name, host, port):
        super(ClosestWaypointSubscriber, self).__init__()

        self.autowareSubscribeTopic = Topic()
        self.autowareSubscribeTopic.set_id(name)
        self.autowareSubscribeTopic.set_root(Autoware.TOPIC.SUBSCRIBE)
        self.autowareSubscribeTopic.set_message(autoware_message)

        self.__previous_time = time()
        self.__period = 1.0  # [sec]

        self.connect(host, port)
        self.set_main_loop(rospy.spin)

        rospy.init_node("ams_closest_waypoint_subscriber", anonymous=True)
        self.__ROSSubscriber = message_filters.Subscriber(
            Autoware.ROSTOPIC.SUBSCRIBE, Int32)
        self.__ROSSubscriber.registerCallback(self.on_message_from_ros,
                                              self.publish)
    def __init__(self, _id, name, dt=1.0):
        super().__init__(_id, name, dt)

        self.state_machine = self.get_state_machine()

        self.target_start_bus_stop = None
        self.target_goal_bus_stop = None
        self.vehicle_id = None

        self.vehicle_statuses = self.manager.dict()
        self.vehicle_statuses_lock = self.manager.Lock()

        self.__topicSubVehicleStatus = Topic()
        self.__topicSubVehicleStatus.set_targets(
            Target.new_target(None, SIM_BUS.NODE_NAME), None)
        self.__topicSubVehicleStatus.set_categories(
            VEHICLE.TOPIC.CATEGORIES.STATUS)
        self.__topicSubVehicleStatus.set_message(VehicleStatus)
        self.set_subscriber(self.__topicSubVehicleStatus,
                            self.update_vehicle_status)
Beispiel #21
0
    arrow = Arrow(waypoint)
    arrow.load(ARROW_FILE)

    route = Route()
    route.set_waypoint(waypoint)
    route.set_arrow(arrow)

    intersection = Intersection()
    intersection.load(INTERSECTION_FILE)

    start_waypoint_id = "9566"  # 9232

    currentTime = time()

    topic = Topic()
    topic.set_message(vehicle_message)
    schedules = deepcopy(topic.get_template()["schedules"])
    schedules[0]["start_time"] = currentTime - 5
    schedules[0]["duration"] = 10
    schedules[0]["action"] = Vehicle.ACTION.STOP
    # schedules[0]["route"] = None

    # """
    next_start_waypoint_id = start_waypoint_id
    for i in range(10):
        startPoint = {
            "arrow_code":
            arrow.get_arrow_codes_from_waypoint_id(next_start_waypoint_id)[0],
            "waypoint_id":
            next_start_waypoint_id,
Beispiel #22
0
    def publish(self, topic, message):
        self.__client.publish(topic, message)


TRAFFIC_SIGNAL_FILE = "../../res/trafficSignal.json"

if __name__ == '__main__':
    host = "localhost"
    port = 1883
    if 1 < len(sys.argv):
        host = sys.argv[1]
    if 2 < len(sys.argv):
        port = int(sys.argv[2])
    mqtt_client = MQTTClient(host, port)

    topicTrafficSignalSubscribe = Topic()
    topicTrafficSignalSubscribe.set_root(TrafficSignal.TOPIC.SUBSCRIBE)
    topicTrafficSignalSubscribe.set_message(traffic_signal_message)

    with open(TRAFFIC_SIGNAL_FILE, "r") as f:
        traffic_signal_configs = json.load(f)

    cycle_set = traffic_signal_configs["cycles"]
    cycle_groups = traffic_signal_configs["cycleGroups"]

    traffic_signals = {}
    routes = {}
    cycles = {}
    schedules = {}
    for intersection_id, intersection_cycle_groups in cycle_groups.items():
        instance = TrafficSignal(name=intersection_id)
Beispiel #23
0
    def __init__(self, _id, name, waypoint, arrow, route, dt=0.5):
        super().__init__(_id, name, waypoint, arrow, route, dt=dt)

        self.upper_distance_from_stopline = AUTOWARE.DEFAULT_UPPER_DISTANCE_FROM_STOPLINE
        self.state_machine = self.get_state_machine()

        self.__map_match = MapMatch()
        self.__map_match.set_waypoint(self.waypoint)
        self.__map_match.set_arrow(self.arrow)

        self.ros_closest_waypoint = None
        self.ros_closest_waypoint_lock = self.manager.Lock()

        self.ros_current_pose = None
        self.ros_current_pose_lock = self.manager.Lock()

        self.ros_decisionmaker_states = None
        self.ros_decisionmaker_states_lock = self.manager.Lock()

        self.current_locations = []

        self.traffic_signals = self.manager.dict()
        self.traffic_signals_lock = self.manager.Lock()

        self.__previous_state_command = None

        self.__topicPubBasedLaneWaypointsArray = Topic()
        self.__topicPubBasedLaneWaypointsArray.set_targets(
            self.target, Target.new_target(self.target.id, AUTOWARE.TOPIC.ROS_NODE_NAME))
        self.__topicPubBasedLaneWaypointsArray.set_categories(AUTOWARE.TOPIC.CATEGORIES.BASED_LANE_WAYPOINTS_ARRAY)

        self.__topicPubStateCmd = Topic()
        self.__topicPubStateCmd.set_targets(
            self.target, Target.new_target(self.target.id, AUTOWARE.TOPIC.ROS_NODE_NAME))
        self.__topicPubStateCmd.set_categories(AUTOWARE.TOPIC.CATEGORIES.STATE_CMD)

        self.__topicPubLightColor = Topic()
        self.__topicPubLightColor.set_targets(
            self.target, Target.new_target(self.target.id, AUTOWARE.TOPIC.ROS_NODE_NAME))
        self.__topicPubLightColor.set_categories(AUTOWARE.TOPIC.CATEGORIES.LIGHT_COLOR)

        self.__topicSubCurrentPose = Topic()
        self.__topicSubCurrentPose.set_targets(
            Target.new_target(self.target.id, AUTOWARE.TOPIC.ROS_NODE_NAME), self.target)
        self.__topicSubCurrentPose.set_categories(AUTOWARE.TOPIC.CATEGORIES.CURRENT_POSE)
        self.__topicSubCurrentPose.set_message(ROSMessage.CurrentPose)
        self.set_subscriber(self.__topicSubCurrentPose, self.update_current_pose)

        self.__topicSubClosestWaypoint = Topic()
        self.__topicSubClosestWaypoint.set_targets(
            Target.new_target(self.target.id, AUTOWARE.TOPIC.ROS_NODE_NAME), self.target)
        self.__topicSubClosestWaypoint.set_categories(AUTOWARE.TOPIC.CATEGORIES.CLOSEST_WAYPOINT)
        self.__topicSubClosestWaypoint.set_message(ROSMessage.ClosestWaypoint)
        self.set_subscriber(self.__topicSubClosestWaypoint, self.update_closest_waypoint)

        self.__topicSubDecisionMakerStates = Topic()
        self.__topicSubDecisionMakerStates.set_targets(
            Target.new_target(self.target.id, AUTOWARE.TOPIC.ROS_NODE_NAME), self.target)
        self.__topicSubDecisionMakerStates.set_categories(AUTOWARE.TOPIC.CATEGORIES.DECISION_MAKER_STATES)
        self.__topicSubDecisionMakerStates.set_message(ROSMessage.DecisionMakerStates)
        self.set_subscriber(self.__topicSubDecisionMakerStates, self.update_decisionmaker_states)

        self.__topicSubTrafficSignalStatus = Topic()
        self.__topicSubTrafficSignalStatus.set_targets(Target.new_target(None, TRAFFIC_SIGNAL.NODE_NAME))
        self.__topicSubTrafficSignalStatus.set_categories(TRAFFIC_SIGNAL.TOPIC.CATEGORIES.STATUS)
        self.__topicSubTrafficSignalStatus.set_message(TrafficSignalStatus)
        self.set_subscriber(self.__topicSubTrafficSignalStatus, self.update_traffic_signals)
args = parser.parse_args()

if __name__ == '__main__':

    mqtt_client = MQTTClient(args.host, args.port)

    traffic_signal = TrafficSignal(
        _id=args.id if args.id is not None else str(uuid()),
        route_code=args.route_code)
    process = Process(target=traffic_signal.start, args=[args.host, args.port])
    process.start()

    if args.cycle is not None:
        sleep(5)
        # print("publish cycles")
        topicCycle = Topic()
        topicCycle.set_targets(
            Target.new_target(None, "TrafficSignalCycleSetter"),
            traffic_signal.target)
        topicCycle.set_categories(TrafficSignal.CONST.TOPIC.CATEGORIES.CYCLE)
        mqtt_client.publish(topicCycle.get_path(),
                            topicCycle.serialize(json.loads(args.cycle)))

    if args.schedules is not None:
        sleep(5)
        # print("publish schedules")
        topicSchedules = Topic()
        topicSchedules.set_targets(
            Target.new_target(None, "TrafficSignalSchedulesSetter"),
            traffic_signal.target)
        topicSchedules.set_categories(
Beispiel #25
0
 def response(self, request_path, payload, qos=0, retain=False):
     response_topic = Topic()
     response_topic.set_fix_path(
         self.__topicPub.get_response_path(request_path))
     self.publish(response_topic, payload, qos, retain)