def test_givenRobotNotCorrectlyOrientedAndRobotWithOrientationLargerThan180Degree_whenRotate_thenSendNegativeAdjustedOrientation(
        self, ):
        self._setup_communication_service(1)
        self._setup_vision_service(self.ANOTHER_ORIENTATION)
        expected_orientation = Orientation(-126)

        self._rotation_service.rotate(self.AN_ORIENTATION)

        self._communication_service.send_object.assert_called_with(
            Message(Topic.ROTATION, expected_orientation))
 def align_with_command_panel(self, letter_position: int):
     if ALIGN_WITH_COMMAND_PANEL_FOR_REAL:
         first_starting_zone_corner = (self._read_command_panel_handler.
                                       _read_command_panel(letter_position))
         print(first_starting_zone_corner)
         # self._communication_service.send_object(
         #     Message(Topic.ANALYZE_COMMAND_PANEL, first_starting_zone_corner)
         # )
     else:
         print("On aligne pas pour de vrai")
         input("Appuyez sur Entrer pour envoyer D")
         self._communication_service.send_object(
             Message(Topic.ANALYZE_COMMAND_PANEL, "D"))
Example #3
0
    def rotate(self, desired_orientation: Orientation):
        while True:
            time.sleep(0.5)
            robot_pose = None
            try:
                _, robot_pose = self._vision_service.get_vision_state()
            except RobotNotFoundException:
                continue
            orientation_to_send = (robot_pose.get_orientation_in_degree() -
                                   desired_orientation)
            if abs(orientation_to_send.get_orientation_in_degree()) <= 1:
                break
            orientation_to_send = self._find_smallest_orientation_to_send(
                orientation_to_send)
            if abs(orientation_to_send.get_orientation_in_degree()) <= 5:
                orientation_to_send = self._shrink_rotation(
                    orientation_to_send)

            self._communication_service.send_object(
                Message(Topic.ROTATION, orientation_to_send))
            message: Message = self._communication_service.receive_object()
            if (message.get_topic() == Topic.ROTATION_COMPLETED
                    and self._is_correctly_oriented(desired_orientation)):
                break
 def _send_confirmation_to_station(self, command: Topic, payload: Any):
     message = Message(command, payload)
     self._communication_service.send_object(message)
Example #5
0
 def send_command_to_robot(self, command: Topic, payload: object):
     message = Message(command, payload)
     self._communication_service.send_object(message)
Example #6
0
 def send_transport_puck_command(self):
     message = Message(Topic.START_CYCLE, Stage.TRANSPORT_PUCK)
     self._communication_service.send_object(message)
from domain.communication.Message import Message
from domain.game.Stage import Stage
from domain.game.Topic import Topic
from infra.communication.station.ZmqReqRepConnector import ZmqReqRepConnector

if __name__ == "__main__":
    zmq_connector = ZmqReqRepConnector("tcp://10.248.74.150:5556")

    message = zmq_connector.receive_object()

    if message.get_topic() == Topic.START_CYCLE:
        print(message.get_payload())

    zmq_connector.send_object(Message(Topic.STAGE_COMPLETED, Stage.STAGE_COMPLETED))
class TestCommunicationService(TestCase):
    A_MESSAGE = Message(Topic.READ_RESISTANCE, False)

    def setUp(self):
        self.pub_sub_connector = MagicMock()
        self.game_cycle_connector = MagicMock()
        self.robot_information = MagicMock()
        self.communication_service = CommunicationService(
            self.game_cycle_connector, self.pub_sub_connector, self.robot_information
        )

    def test_whenReceiveMessage_thenConnectorReceivesMessage(self):
        self.communication_service.receive_game_cycle_message()

        self.assertTrue(self.game_cycle_connector.receive_message.called)

    def test_whenSendMessage_thenConnectorSendsMessage(self):
        self.communication_service.send_game_cycle_message(self.A_MESSAGE)

        self.assertTrue(
            self.game_cycle_connector.send_message.called_with(self.A_MESSAGE)
        )

    def test_whenReceiveObject_thenConnectorIsUsedToReceiveObject(self):
        an_object = MagicMock()
        self.game_cycle_connector.receive_object.return_value = an_object

        actual_object = self.communication_service.receive_object()

        self.assertEqual(an_object, actual_object)

    def test_givenStatusReturnByRobotInformation_whenSendGripperStatus_thenPublishStatus(
        self,
    ):
        self.robot_information.get_gripper_status.return_value = STATUS_HAS_PUCK

        self.communication_service.send_gripper_status()

        self.pub_sub_connector.publish_gripper_status.assert_called_with(
            STATUS_HAS_PUCK
        )

    def test_givenCurrentConsumptionReturnedByRobotInformation_whenSendPowerConsumption_thenPublishCurrentConsumption(
        self,
    ):
        self.robot_information.get_current_consumption.return_value = A_CURRENT_VALUE
        self.communication_service.send_current_consumption()
        self.pub_sub_connector.publish_battery_consumption.assert_called_with(
            A_CURRENT_VALUE
        )

    def test_givenPowerConsumptionReturnedByRobotInformation_whenSendPowerConsumption_thenPublishPowerConsumption(
        self,
    ):
        self.robot_information.get_power_consumption.return_value = A_POWER_CONSUMPTION

        self.communication_service.send_power_consumption()

        self.pub_sub_connector.publish_power_consumption.assert_called_with(
            A_POWER_CONSUMPTION
        )

    def test_givenPowerConsumptionFirstWheelReturnedByRobotInformation_whenSendPowerConsumptionFirstWheel_thenPublishPowerConsumptionFirstWheel(
        self,
    ):
        self.robot_information.get_power_consumption_first_wheel.return_value = (
            A_POWER_CONSUMPTION_FIRST_WHEEL
        )

        self.communication_service.send_power_consumption_first_wheel()

        self.pub_sub_connector.publish_power_consumption_first_wheel.assert_called_with(
            A_POWER_CONSUMPTION_FIRST_WHEEL
        )

    def test_givenPowerConsumptionSecondWheelReturnedByRobotInformation_whenSendPowerConsumptionSecondWheel_thenPublishPowerConsumptionSecondWheel(
        self,
    ):
        self.robot_information.get_power_consumption_second_wheel.return_value = (
            A_POWER_CONSUMPTION_SECOND_WHEEL
        )

        self.communication_service.send_power_consumption_second_wheel()

        self.pub_sub_connector.publish_power_consumption_second_wheel.assert_called_with(
            A_POWER_CONSUMPTION_SECOND_WHEEL
        )

    def test_givenPowerConsumptionThirdWheelReturnedByRobotInformation_whenSendPowerConsumptionThirdWheel_thenPublishPowerConsumptionThirdWheel(
        self,
    ):
        self.robot_information.get_power_consumption_third_wheel.return_value = (
            A_POWER_CONSUMPTION_THIRD_WHEEL
        )

        self.communication_service.send_power_consumption_third_wheel()

        self.pub_sub_connector.publish_power_consumption_third_wheel.assert_called_with(
            A_POWER_CONSUMPTION_THIRD_WHEEL
        )

    def test_givenPowerConsumptionFourthWheelReturnedByRobotInformation_whenSendPowerConsumptionFourthWheel_thenPublishPowerConsumptionFourthWheel(
        self,
    ):
        self.robot_information.get_power_consumption_fourth_wheel.return_value = (
            A_POWER_CONSUMPTION_FOURTH_WHEEL
        )

        self.communication_service.send_power_consumption_fourth_wheel()

        self.pub_sub_connector.publish_power_consumption_fourth_wheel.assert_called_with(
            A_POWER_CONSUMPTION_FOURTH_WHEEL
        )

    def test_givenBatteryTimeLeftReturnedByRobotInformation_whenSendBatteryTimeLeft_thenPublishBatteryTimeLeft(
        self,
    ):
        self.robot_information.get_battery_time_left.return_value = A_BATTERY_TIME_LEFT
        self.communication_service.send_battery_time_left()
        self.pub_sub_connector.publish_battery_time_left.assert_called_with(
            A_BATTERY_TIME_LEFT
        )

    def test_givenBatteryPercentageReturnedByRobotInformation_whenSendBatteryPercentage_thenPublishBatteryBatteryPercentage(
        self,
    ):
        self.robot_information.get_battery_percentage.return_value = (
            A_BATTERY_PERCENTAGE
        )
        self.communication_service.send_battery_percentage()
        self.pub_sub_connector.publish_battery_percentage.assert_called_with(
            A_BATTERY_PERCENTAGE
        )
 def _send_start_signal(self):
     print("Sending start signal...")
     self._communication_service.send_object(
         Message(Topic.START_STAGE, Stage.START_CYCLE))
from domain.communication.Message import Message
from domain.game.Stage import Stage
from domain.game.Topic import Topic
from infra.communication.robot.ZmqReqRepConnector import ZmqReqRepConnector

if __name__ == "__main__":
    req_connector = ZmqReqRepConnector("tcp://*:5556")

    message = Message(Topic.START_CYCLE, Stage.START_CYCLE)

    input("Press enter to send message")
    req_connector.send_object(message)

    message = req_connector.receive_object()

    if message.get_payload() == Stage.STAGE_COMPLETED:
        print(message.get_payload())
 def _move_robot(self, movements: List[Movement]):
     command = Message(Topic.MOVEMENTS, movements)
     self._communication_service.send_object(command)
     self._wait_for_robot_confirmation(Topic.MOVEMENTS)
 def _send_confirmation_to_station(self, topic: Topic, payload: Any):
     message = Message(topic, payload)
     self._communication_service.send_object(message)
     raise StageComplete
 def _setup_communication_service(self,
                                  number_of_rotation_message_send: int):
     side_effect = []
     for i in range(number_of_rotation_message_send):
         side_effect.append(Message(Topic.ROTATION_COMPLETED, None))
     self._communication_service.receive_object.side_effect = side_effect