Exemple #1
0
def generate_perception(perception_description, prev_perception):
    """
    Generate perception data
    """
    perceptions = PerceptionObstacles()
    perceptions.header.sequence_num = get_seq_num()
    perceptions.header.module_name = "perception"
    perceptions.header.timestamp_sec = time.time()
    if not perception_description:
        return perceptions
    if prev_perception is None:
        for description in perception_description:
            p = perceptions.perception_obstacle.add()
            p.CopyFrom(init_perception(description))
        return perceptions
    else:  # Linear projection
        description_dict = {}
        for desc in perception_description:
            description_dict[desc["id"]] = desc
        for obstacle in prev_perception.perception_obstacle:
            description = description_dict[obstacle.id]
            p = perceptions.perception_obstacle.add()
            next_obstacle = linear_project_perception(description, obstacle)
            p.CopyFrom(next_obstacle)
        return perceptions
Exemple #2
0
    def on_tick(self, world_snapshot):
        """
        Get a cyber PerceptionObstacles message including all actors within range, except the ego

        """
        self.seconds_since_write += world_snapshot.delta_seconds
        if self.seconds_since_write >= self.tick_rate:
            self.seconds_since_write -= self.tick_rate
            obstacles = PerceptionObstacles()
            obstacles.header.CopyFrom(self.bridge.get_cyber_header())
            for actor in self.bridge.child_actors.values():
                if actor.carla_actor is not self.parent_actor:
                    if actor.carla_actor.get_location().distance(
                            self.parent_actor.get_location()) <= self.range:
                        if isinstance(actor.carla_actor, carla.Vehicle):
                            obstacles.perception_obstacle.append(
                                actor.get_cyber_obstacle_msg())
                        elif isinstance(actor.carla_actor, carla.Walker):
                            msg = actor.get_cyber_obstacle_msg()
                            msg.type = PerceptionObstacle.Type.PEDESTRIAN
                            obstacles.perception_obstacle.append(msg)
            self.bridge.write_cyber_message(self.channel_name, obstacles)
def receiver(data):
    """receiver"""
    perception = PerceptionObstacles()
    perception.ParseFromString(data.data)
    print str(perception)
"""
this module creates a node and fake prediction data based
on json configurations
"""
import argparse
import math
import time

import numpy
import simplejson
from cyber_py import cyber
from cyber_py import cyber_time

from modules.prediction.proto.prediction_obstacle_pb2 import PredictionObstacles
from modules.perception.proto.perception_obstacle_pb2 import PerceptionObstacles
obstacles_=PerceptionObstacles()
def receive_perception_obstacles(perception_obstacles):
    obstacles_=perception_obstacles
def prediction_publisher(prediction_channel, rate):
    """publisher"""
    cyber.init()
    node = cyber.Node("prediction")
    writer = node.create_writer(prediction_channel, PredictionObstacles)
    prediction = PredictionObstacles()
    prediction.header.sequence_num = seq_num
    prediction.header.timestamp_sec = cyber_time.Time.now().to_sec()
    prediction.header.module_name = "prediction"
    i=0
    writer.write(prediction)
    seq_num += 1
    time.sleep(sleep_time)