Ejemplo n.º 1
0
def update_state_evade():
    global next_state,sonar_difference_handlers
    initialize_sonar_handlers()
    rospy.loginfo("Evading obstacle")
    sonar_difference_handlers[1][0]=update_state_align
    motor.act(command='FORWARD',dutycycle=50)
    next_state="evade"
Ejemplo n.º 2
0
def force_stop():
    global is_map,STOP_FLAG
    initialize_sonar_handlers()
    is_map=False
    STOP_FLAG=True
    rospy.loginfo("Stoping motor")
    motor.act("STOP",dutycycle)
Ejemplo n.º 3
0
def update_state_forward():
    global next_state,sonar_difference_handlers
    initialize_sonar_handlers()
    rospy.loginfo("Going forward")
    sonar_difference_handlers[0][2]=update_state_obstacle
    motor.act(command="FORWARD",dutycycle=60)
    next_state="forward"
Ejemplo n.º 4
0
def normal_backward(command):
    global STOP_FLAG
    STOP_FLAG=False
    global sonar_difference_handlers
    #stop when back sensor return 1
    sonar_difference_handlers[2][2]=force_stop
    rospy.loginfo("Normal backward")
    motor.act("BACKWARD",dutycycle)
Ejemplo n.º 5
0
def normal_forward(command):
    global sonar_difference_handlers
    global STOP_FLAG
    STOP_FLAG=False
    #stop when front sensor return 1
    sonar_difference_handlers[0][2]=force_stop
    rospy.loginfo("Normal forward")
    motor.act("FORWARD",dutycycle)
Ejemplo n.º 6
0
def update_state_obstacle():
    global next_state
    initialize_sonar_handlers()
    rospy.loginfo("Encountered obstacle")
    sonar_difference_handlers[0][0]=update_state_evade
    sonar_difference_handlers[0][2]=update_state_obstacle
    motor.act(command='LEFT',dutycycle=50)
    next_state="evade"
Ejemplo n.º 7
0
def direct_backward(command):
    global STOP_FLAG
    STOP_FLAG=False
    global sonar_difference_handlers
    #stop when front sensor return 1
    sonar_difference_handlers[0][2]=stop
    rospy.loginfo("Direct backward")
    turnto(180)
    if not STOP_FLAG:
        motor.act("FORWARD",dutycycle)
Ejemplo n.º 8
0
def rotate():
    global target
    global current
    if ((target+360-current)%360)<=180:
        print ('right')
        while True:
            motor.act(command='RIGHT', dutycycle=50)
        
    elif ((target+360-current)%360)>180:
        print ('left')
        while True:
            motor.act(command='RIGHT', dutycycle=50)
Ejemplo n.º 9
0
def turnto(target_angle):
    direction = None
    while difference(target_angle,angle)>15 and not STOP_FLAG:
        error = difference(target_angle,angle)
        if is_right(target_angle,angle):
            motor.act(command='RIGHT',dutycycle=50)
            rospy.loginfo("Aligning, turning right, error: "+str(error))
            time.sleep(error*0.005)
        elif not is_right(target_angle,angle):
            motor.act(command='LEFT',dutycycle=50)
            rospy.loginfo("Aligning, turning left, error: "+str(error))
            time.sleep(error*0.005)
        motor.act(command="STOP",dutycycle=90)
        time.sleep(0.4)
Ejemplo n.º 10
0
def normal_right(command):
    global STOP_FLAG
    STOP_FLAG=False
    rospy.loginfo("Normal turn right")
    motor.act("RIGHT",dutycycle)
Ejemplo n.º 11
0
def normal_left(command):
    global STOP_FLAG
    STOP_FLAG=False
    rospy.loginfo("Normal turn left")
    motor.act("LEFT",dutycycle)
Ejemplo n.º 12
0
def update_state_align():
    global next_state
    initialize_sonar_handlers()
    motor.act(command='STOP',dutycycle=50)
    next_state="align"