def perform_action(self, action_index): if action_index < 0 or action_index >= len(self.actions): raise Exception("Invalid action: " + str(action_index)) angle, velocity = self.actions[action_index] message = drive_param() message.angle = angle message.velocity = velocity self.drive_parameters_publisher.publish(message)
def drive(self, laser_message): if self.scan_indices is None: self.scan_indices = [int(i * (len(laser_message.ranges) - 1) / (STATE_SIZE - 1)) for i in range(STATE_SIZE)] # nopep8 values = [laser_message.ranges[i] for i in self.scan_indices] values = [v if not math.isinf(v) else 100 for v in values] state = torch.tensor(values, dtype=torch.float) with torch.no_grad(): action = self.layers.forward(state) message = drive_param() message.angle = action[0].item() message.velocity = (MIN_SPEED + MAX_SPEED) / 2 + \ action[1].item() * (MAX_SPEED - MIN_SPEED) / 2 drive_parameters_publisher.publish(message)
def drive(angle, velocity): message = drive_param() message.angle = angle message.velocity = velocity drive_parameters_publisher.publish(message)