Ejemplo n.º 1
0
    def main_loop(self):
        """The main thread for communicating with the server

        Args:
            None

        Returns:
            None

        Raises:
            grpc exceptions. please refer to grpc
        """

        with grpc.insecure_channel(self.server_address,
                                   options=[("grpc.max_send_message_length",
                                             self.max_message_length),
                                            ("grpc.max_receive_message_length",
                                             self.max_message_length)
                                            ]) as channel:
            stub = ros_pb2_grpc.RosServiceStub(channel)
            for communication in stub.Communicate(self.stub_callback()):
                print(communication)
                if communication.HasField("mapping_request"):
                    mapping_request = communication.mapping_request
                    self.mapping_hanlder.handle_request(mapping_request)
                elif communication.HasField("navigation_request"):
                    navigation_request = communication.navigation_request
                    self.navigation_handler.handle_request(navigation_request)
Ejemplo n.º 2
0
 def fetch_remote_map(self):
     with grpc.insecure_channel(self.server_address) as channel:
         stub = ros_pb2_grpc.RosServiceStub(channel)
         map_request = ros_pb2.GetMapRequest(robot_name=self.robot_name)
         remote_map = stub.GetRawMap(map_request)
         self.ros_map = self.grpc_map_to_rosmap(remote_map)
         self.delta_theta = remote_map.origin_angle_shift
         self.gps_origin = remote_map.origin
def main(argv):
    with grpc.insecure_channel(f'localhost:{FLAGS.port}') as channel:
        with grpc.insecure_channel(f'localhost:50051') as auth_channel:
            auth_stub = login_pb2_grpc.AuthenticationServiceStub(auth_channel)
            response = auth_stub.Login(
                login_pb2.LoginRequest(username="******", password="******"))
            token = response.token
        print(token)
        stub = ros_pb2_grpc.RosServiceStub(channel)
        stub.CreateTrip(
            ros_pb2.CreateTripRequest(token=token,
                                      start_waypoint="test_waypoint",
                                      end_waypoint="test_destination"))
        time.sleep(1)
        stub.ConfirmTrip(ros_pb2.ConfirmTripRequest(token=token))
Ejemplo n.º 4
0
    def fetch_pose(self):
        with grpc.insecure_channel(self.server_address) as channel:
            stub = ros_pb2_grpc.RosServiceStub(channel)
            pose_request = ros_pb2.GetPoseRequest(robot_name=self.robot_name)

            remote_pose = stub.GetPose(pose_request)

            initial_pose_row = remote_pose.row
            initial_pose_col = remote_pose.column
            initial_pose_angle = remote_pose.angle

            point = Point(initial_pose_row, initial_pose_col, 0)
            quaternion = tf.transformations.quaternion_from_euler(
                0, 0, initial_pose_angle)
            orientation = Quaternion(quaternion[0], quaternion[1],
                                     quaternion[2], quaternion[3])

            self.initial_pose.pose.pose.position = point
            self.initial_pose.pose.pose.orientation = orientation
Ejemplo n.º 5
0
def main(argv):
    with grpc.insecure_channel(f'localhost:{FLAGS.port}') as channel:
        stub = ros_pb2_grpc.RosServiceStub(channel)
        communication_generator = stub.Communicate(GenerateRequest())
        try:
            for communication in communication_generator:
                print(communication)
                if communication.HasField("navigation_request"):
                    state_update_requests.put(
                        ros_pb2.RosToServerCommunication(
                            status_update=ros_pb2.RobotStatusUpdate(
                                status_update=ros_pb2.RobotStatusUpdate.
                                NAVIGATING)))
                    state_update_requests.put(
                        ros_pb2.RosToServerCommunication(
                            status_update=ros_pb2.RobotStatusUpdate(
                                status_update=ros_pb2.RobotStatusUpdate.
                                NAVIGATING_AND_IDLE)))
        except KeyError:
            communication_generator.cancel()
Ejemplo n.º 6
0
def main(argv):
    with grpc.insecure_channel(f'localhost:{FLAGS.port}') as channel:
        with grpc.insecure_channel(f'localhost:50051') as auth_channel:
            auth_stub = login_pb2_grpc.AuthenticationServiceStub(auth_channel)
            response = auth_stub.Login(
                login_pb2.LoginRequest(username="******", password="******"))
            token = response.token
        stub = ros_pb2_grpc.RosServiceStub(channel)
        stub.SendMovement(
            ros_pb2.MappingRequest(
                token=token,
                mapping_request=ros_pb2.ServerToRosMappingRequest(
                    request_type=ros_pb2.ServerToRosMappingRequest.
                    START_MAPPING)))
        time.sleep(3)
        stub.SendMovement(
            ros_pb2.MappingRequest(
                token=token,
                mapping_request=ros_pb2.ServerToRosMappingRequest(
                    request_type=ros_pb2.ServerToRosMappingRequest.DIRECTION,
                    direction=ros_pb2.ServerToRosMappingRequest.FORWARD)))
        time.sleep(3)
        stub.SendMovement(
            ros_pb2.MappingRequest(
                token=token,
                mapping_request=ros_pb2.ServerToRosMappingRequest(
                    request_type=ros_pb2.ServerToRosMappingRequest.DIRECTION,
                    direction=ros_pb2.ServerToRosMappingRequest.STOP)))
        time.sleep(3)
        stub.SendMovement(
            ros_pb2.MappingRequest(
                token=token,
                mapping_request=ros_pb2.ServerToRosMappingRequest(
                    request_type=ros_pb2.ServerToRosMappingRequest.STOP_MAPPING
                )))
        time.sleep(3)
        stub.AddWaypoint(
            ros_pb2.AddWaypointRequest(waypoint_name='test_waypoint',
                                       description='some description',
                                       token=token))