def my_callback(request):
    
    my_response = BB8CustomServiceMessageResponse()
    my_response.success = True
    length = request.side
    print("help")

    for i in range (0, request.repetitions):
        for j in range (0, 4):
            cmd_vel.linear.x = 0.5
            #pub.publish(cmd_vel)
            time.sleep(length)

            cmd_vel.linear.x = 0.0
            #pub.publish(cmd_vel)
            time.sleep(length)

            cmd_vel.angular.z = 0.5
            #pub.publish(cmd_vel)
            time.sleep(1.45)

            cmd_vel.angular.z = 0.0
            #pub.publish(cmd_vel)
            time.sleep(1.45)


    return  my_response # the service Response class, in this case MyCustomServiceMessageResponse
Exemplo n.º 2
0
def my_callback(request):
    print "Repitions" + str(request.repetitions)  #checkers
    print "Side" + str(request.side)
    response = BB8CustomServiceMessageResponse()
    square = Twist()

    for x in range(0, request.repetitions):
        for i in range(0, 4):
            square.linear.x = 1.0
            pub.publish(square)
            time.sleep(request.side)

            square.linear.x = 0.0
            pub.publish(square)
            time.sleep(request.side)

            square.angular.z = 1.0
            pub.publish(square)
            time.sleep(request.side)

            square.angular.z = 0.0
            pub.publish(square)
            time.sleep(request.side)

    square.linear.x = 0
    square.angular.z = 0
    pub.publish(square)
    response.success = True

    return response  # the service Response class, in this case EmptyResponse
Exemplo n.º 3
0
def callback(request):
    response = BB8CustomServiceMessageResponse()
    global count
    
    linear_time = request.side / 0.5
    
    n = request.repetitions * 4

    while count < n: # repeat this many times
        # move in square here. 
        pub.publish(halt(move))
        time.sleep(0.1)
        
        pub.publish(linear_movement(move))
        time.sleep(linear_time)
        pub.publish(halt(move))
        time.sleep(0.1)
        pub.publish(angular_movement(move))
        time.sleep(1.7)
        pub.publish(halt(move))
        time.sleep(0.1)
        
        count += 1

    pub.publish(halt(move))
    response.success = True
    return response
def my_callback(request):
    
    rospy.loginfo("The Service move_bb8_in_square_custom has been called")
    
    radius = request.side
    for i in range(request.repetitions):
        rospy.loginfo("Moving forward...")
        move_circle.linear.x = 0.2
        move_circle.angular.z = 0
        my_pub.publish(move_circle)
        time.sleep(radius)
        rospy.loginfo("Rotating...")
        move_circle.linear.x = 0
        move_circle.angular.z = 0.2
        my_pub.publish(move_circle)
        time.sleep(4)
        rospy.loginfo("Moving forward...")
        move_circle.linear.x = 0.2
        move_circle.angular.z = 0
        my_pub.publish(move_circle)
        time.sleep(radius)
        rospy.loginfo("Rotating...")
        move_circle.linear.x = 0
        move_circle.angular.z = 0.2
        my_pub.publish(move_circle)
        time.sleep(4)
        rospy.loginfo("Moving forward...")
        move_circle.linear.x = 0.2
        move_circle.angular.z = 0
        my_pub.publish(move_circle)
        time.sleep(radius)
        rospy.loginfo("Rotating...")
        move_circle.linear.x = 0
        move_circle.angular.z = 0.2
        my_pub.publish(move_circle)
        time.sleep(4)
        rospy.loginfo("Moving forward...")
        move_circle.linear.x = 0.2
        move_circle.angular.z = 0
        my_pub.publish(move_circle)
        time.sleep(radius)
        rospy.loginfo("Rotating...")
        move_circle.linear.x = 0
        move_circle.angular.z = 0.2
        my_pub.publish(move_circle)
        time.sleep(4)
        rospy.loginfo("Stopping...")
        move_circle.linear.x = 0
        move_circle.angular.z = 0
        my_pub.publish(move_circle)
        time.sleep(2)
        
    rospy.loginfo("Finished service move_bb8_in_square_custom")
    response = BB8CustomServiceMessageResponse()
    response.success = True
    return response # the service Response class, in this case EmptyResponse
Exemplo n.º 5
0
def service_callback(request):
    resp = BB8CustomServiceMessageResponse()
    try:
        for i in range(request.repetitions):
            move_square(request.side)
            rospy.sleep(1.5)
        resp.success = True
    except:
        resp.success = False
    return resp
def my_callback(request):

    sides = request.side
    rep = request.repetitions

    loop_func(4, sides)

    response = BB8CustomServiceMessageResponse()
    response.success = True
    return response
Exemplo n.º 7
0
def my_callback(request):
    i = 0
    while i <= request.repetitions:
        cube(request.side)
        i += 1

    response = BB8CustomServiceMessageResponse()
    response.success = True
    move.linear.x = 0.0
    move.angular.z = 0.0
    pub.publish(move)
    rate.sleep()
    return response  # the service Response class, in this case EmptyResponse
def my_callback(request):
    rospy.loginfo("The Service move_bb8_in_circle_custom has been called")

    while (request.repetitions > 0):

        j = 0
        while (j < 4):

            # Moving the robot
            print('Moving the robot for ' + str(request.side) + 'mtr')
            i = 0
            move_circle.linear.x = 0.2
            move_circle.angular.z = 0.0
            while i <= request.side:
                my_pub.publish(move_circle)
                print('Length Travelled =' + str(i))
                rate.sleep()
                i = i + 1

            # Linear speed in x is zero
            move_circle.linear.x = 0.0
            my_pub.publish(move_circle)

            # Rotating the robot
            i = 0
            move_circle.angular.z = 0.2
            move_circle.linear.x = 0.0
            while i <= 3:
                my_pub.publish(move_circle)
                print('Length Travelled =' + str(i))
                rate.sleep()
                i = i + 1

            # Angular speed in z is zero
            move_circle.angular.z = 0.0
            my_pub.publish(move_circle)

            # Increment the counter
            j = j + 1

        request.repetitions = request.repetitions - 1

    move_circle.linear.x = 0
    move_circle.angular.z = 0.0
    my_pub.publish(move_circle)

    rospy.loginfo("Finished service move_bb8_in_circle_custom")

    response = BB8CustomServiceMessageResponse()
    response.success = True
    return response  # the service Response class, in this case EmptyResponse
Exemplo n.º 9
0
def my_callback(request):
    print "Request Data==> side=" + str(request.side) + ", repetitions=" + str(
        request.repetitions)
    my_response = BB8CustomServiceMessageResponse()
    move_square = MoveBB8()
    try:
        for i in range(request.repetitions):
            move_square.move_square(request.side)
        my_response.success = True
    except Exception as e:
        print e.message
        my_response.success = False
    rospy.loginfo('Finished service move bb8 in square')
    return my_response
    def service(self, *_data):
        request = _data[0]
        time_size_scale = 0.2
        repetitions = request.repetitions
        side = request.side * time_size_scale

        for _ in range(repetitions):
            for _ in range(4):
                self.move_linear(side)
                self.move_angular()

        my_response = BB8CustomServiceMessageResponse()
        my_response.success = True
        return my_response
def my_callback(request):
    rospy.loginfo("The Service move_bb8_in_square has been called")
    movebb8_object = MoveBB8()
    repetions_of_square = request.repetitions + 1
    new_side = request.side

    for i in range(repetions_of_square):
        rospy.loginfo("Start Movement with side =" + str(new_side) +
                      " Repetition = " + str(i))
        movebb8_object.move_square(side=new_side)

    rospy.loginfo("Finished service move_bb8_in_square that was called called")
    response = BB8CustomServiceMessageResponse()
    response.success = True
    return response
Exemplo n.º 12
0
def my_callback(request):
    endResponse = BB8CustomServiceMessageResponse()

    for i in range(0, request.repetitions):
        for k in range(0, 4):
            pub.publish(straightMov)
            rospy.sleep(request.side)
            pub.publish(stopMov)
            rospy.sleep(request.side)
            pub.publish(turnMov)
            rospy.sleep(turnTime)

    pub.publish(stopMov)

    endResponse.success = True
    return endResponse
Exemplo n.º 13
0
def my_callback(request):
    rospy.loginfo("The Service move_bb8_in_square_custom has been called")

    movebb8_object = MoveBB8()

    # We need to add because if we ask 0 repetitions means to execute once, not zero times.
    repetitions_of_square = request.repetitions + 1
    new_side = request.side
    for i in range(repetitions_of_square):
        rospy.loginfo("Start Movement with side = "+str(new_side)+"Repetition = "+str(i))
        movebb8_object.move_square(side=new_side)

    rospy.loginfo("Finished service move_bb8_in_square that was called called")
    response = BB8CustomServiceMessageResponse()
    response.success = True
    return response
Exemplo n.º 14
0
def my_callback(request):
    
    print "Request Data==> repetitions="+str(request.repetitions)
    my_response     = BB8CustomServiceMessageResponse()
    i               = 0

    while i < request.repetitions:
        move_like_square(request.side)
        rate.sleep()
        i = i + 1

    my_response.success = True
    move.angular.z  = 0
    move.linear.x   = 0
    pub.publish(move)
    
    return my_response
Exemplo n.º 15
0
def my_callback(request):
    rospy.loginfo("The Service move_bb8_in_square_custom has been called")
    move_square.linear.x = 0.2
    move_square.angular.z = 0.2
    my_pub.publish(move_square)
    rate.sleep()
    i = 0
    print(request.repetitions)
    print(request.side)

    for i in range(request.repetitions):
        while i < 4:
            move_square.linear.x = 0.2
            move_square.angular.z = 0.0
            my_pub.publish(move_square)
            for x in range(int(request.side)):
                rate.sleep()
                rate.sleep()
                rate.sleep()
            move_square.linear.x = 0.0
            move_square.angular.z = 0.0
            my_pub.publish(move_square)
            rate.sleep()
            rate.sleep()
            move_square.linear.x = 0.0
            move_square.angular.z = 0.25
            my_pub.publish(move_square)
            rate.sleep()
            rate.sleep()
            rate.sleep()
            move_square.linear.x = 0.0
            move_square.angular.z = 0.0
            my_pub.publish(move_square)
            rate.sleep()
            rate.sleep()
            i = i + 1

    move_square.linear.x = 0
    move_square.angular.z = 0
    my_pub.publish(move_square)
    rospy.loginfo("Finished service move_bb8_in_square_custom")

    response = BB8CustomServiceMessageResponse()
    response.success = True
    return response  # the service Response class, in this case EmptyResponse
Exemplo n.º 16
0
def my_callback(request):

    executed_repetitions = 0

    rospy.loginfo("Your request to move bb8 in a square has been received.")

    def go_straight_bb8(side):
        move.linear.x = 0.2
        pub.publish(move)
        rospy.sleep(side)

    def turn_bb8():
        move.angular.z = 0.2
        pub.publish(move)
        rospy.sleep(3.9)

    def stop_bb8():
        move.angular.z = 0.0
        move.linear.x = 0.0
        pub.publish(move)
        rospy.sleep(1.5)

    def move_square_bb8():
        i = 0
        while i < 4:
            go_straight_bb8(request.side)
            stop_bb8()
            turn_bb8()
            stop_bb8()
            i += 1

    while executed_repetitions < request.repetitions:
        move_square_bb8()
        executed_repetitions += 1

    rospy.loginfo("Your bb8 has executed squares for the requested duration.")

    # set response of message to True
    response = BB8CustomServiceMessageResponse()
    response.success = True

    return response  # the service Response class, in this case MyCustomServiceMessage
Exemplo n.º 17
0
def my_callback(request):
    # rospy.loginfo("Call back function accesed")
    rep = 0
    r = request.repetitions
    while rep < r:
        # repp(request.side,move)
        # repp(request.side,move)
        # repp(request.side,move)
        # repp(request.side,move)
        # move.linear.x = 0.0                                    #stopping
        # move.angular.z = 0.0
        # pub.publish(move)
        # rate_s.sleep()
        # rate.sleep()
        move_straight(request.side, move)
        stop(move)
        rate_s.sleep()
        rotate(move)
        stop(move)
        rate_s.sleep()
        move_straight(request.side, move)
        stop(move)
        rate_s.sleep()
        rotate(move)
        stop(move)
        rate_s.sleep()
        move_straight(request.side, move)
        stop(move)
        rate_s.sleep()
        rotate(move)
        stop(move)
        rate_s.sleep()
        move_straight(request.side, move)
        stop(move)
        rate_s.sleep()
        rotate(move)
        stop(move)
        rate_s.sleep()
        rep = rep + 1
    response = BB8CustomServiceMessageResponse()
    response.success = True
    return response
def callback(request):
    # User feedback to confirm service launch
    rospy.loginfo("\"move_bb8_in_square_custom\" service launched")
    # Creating a movement object of Move_BB8 class
    movebb8_object = Move_BB8()
    # Storing custom msg data for use
    num_squares = request.repetitions
    new_side = request.side

    ########## Loop to pub square movements ##########
    for i in range(num_squares):
        # User feedback at start of movement
        rospy.loginfo("Squares starting... Side =" + str(new_side) +
                      " Repetition = " + str(i))
        # Calling move_square with desired params
        movebb8_object.move_square(side=new_side)

########## Service completion message response ##########
    rospy.loginfo("The service \"move_bb8_in_square_custom\" has ended")
    response = BB8CustomServiceMessageResponse()
    # Set custom message bool to show successful completion
    response.success = True
    return response
def my_callback(request):
    rospy.loginfo("The Service move_bb8_in_square_custom has been called")
    print "Request Data==> side=" + str(request.side)
    print "Request Data==> repetitions =" + str(request.repetitions)
    my_response = BB8CustomServiceMessageResponse()
    i = 0
    while i < request.repetitions:
        ii = 0
        while ii < 4:
            stime = 2.0
            move.linear.x = 0.2
            move.angular.z = 0
            my_pub.publish(move)
            time.sleep(request.side)

            move.linear.x = 0.0
            move.angular.z = 0.0
            my_pub.publish(move)
            time.sleep(3)

            move.linear.x = 0.0
            move.angular.z = 0.2
            my_pub.publish(move)
            time.sleep(3.7)

            move.linear.x = 0.0
            move.angular.z = 0.0
            my_pub.publish(move)
            time.sleep(0.1)
            ii += 1
        i += 1
    my_response.success = True
    move.linear.x = 0.0
    move.angular.z = 0.0
    rospy.loginfo("Finished service move_bb8_in_square_custom")
    return my_response  # the service Response class, in this case EmptyResponse