Exemple #1
0
class Kernel(object):
    state_receiver = None
    command_sender = None
    debug_sender = None

    def loop(self):
        self.state_receiver = StateReceiver()
        self.state_receiver.create_socket()

        self.command_sender = CommandSender()
        self.command_sender.create_socket()

        self.debug_sender = DebugSender()
        self.debug_sender.create_socket()

        while(True):
            state = self.state_receiver.receive_state()
            self.command_sender.send_command(self.__build_command())
            self.debug_sender.send_debug(self.__build_debug(state))

    def __build_command(self):
        command = Command()
        command.wheels_commands.append(WheelsCommand(10, -10))
        command.wheels_commands.append(WheelsCommand(10, -10))
        command.wheels_commands.append(WheelsCommand(10, -10))
        return command

    def __build_debug(self, state):
        debug = Debug()
        debug.clean()

        for robot in state.team_yellow:
            debug.step_points.append(Point(robot.x + 10, robot.y + 10))
            debug.final_poses.append(Pose(state.ball.x + 10, state.ball.y + 10, 10))
Exemple #2
0
class Kernel(object):
    state_receiver = None
    command_sender = None
    debug_sender = None

    def __init__(self):
        self.state_receiver = StateReceiver()
        self.state_receiver.create_socket()

        self.command_sender = CommandSender()
        self.command_sender.create_socket()

        self.debug_sender = DebugSender()
        self.debug_sender.create_socket()


    def __build_command(self, rvel):
        command = Command()
        command.wheels_commands.append(WheelsCommand(rvel[0][0], rvel[0][1]))
        command.wheels_commands.append(WheelsCommand(rvel[1][0], rvel[1][1]))
        command.wheels_commands.append(WheelsCommand(rvel[2][0], rvel[2][1]))
        return command

    def __build_debug(self, robots_points):
        debug = Debug()
        debug.clean()

        for robot_points in robots_points:
            points = robot_points["step_points"]
            end_pose = robot_points["end_pose"]

            for point in points:
                debug.step_points.append(Point(point[0], point[1]))
            debug.final_poses.append(
                    Pose(end_pose[0], end_pose[1] + end_pose[2]))
    
    """ Nome da função :     receive_state 
        Intenção da função : receber um state do simulador vss-sdk
        Pré-requisitos :     simulador rodando
        Efeitos colaterais : recebe o state atual
        Parâmetros :         nenhum
        Retorno :            state : State
    """
    def receive_state(self):
        return self.state_receiver.receive_state()
    
    """ Nome da função :     send_command 
        Intenção da função : enviar um comando ao simulador vss-sdk
        Pré-requisitos :     simulador rodando
        Efeitos colaterais : envia comandos a um dos times do simulador
                             os times movem-se com a velocidade especificada
        Parâmetros :         rvel : List([vel1, vel2]*3)
        Retorno :            nenhum
    """    
    def send_command(self, rvel):
        self.command_sender.send_command(self.__build_command(rvel))

    def send_debug(self, robots_points):
        self.debug_sender.send_debug(self.__build_debug(robots_points))