예제 #1
0
 def __init__(self, motion, clockwise, speed, time):
     self.robotcontrol = RobotControl(robot_name="summit")
     self.motion = motion
     self.clockwise = clockwise
     self.speed = speed
     self.time = time
     self.time_turn = 7.0 # This is an estimate time in which the robot will rotate 90 degrees
예제 #2
0
 def __init__(self, motion, clockwise, speed, time):
     self.RC = RobotControl()
     self.motion = motion
     self.clockwise = clockwise
     self.speed = speed
     self.time = time
     self.time_turn = 7.0
 def get_laser_readings(self):
     output = []
     rc = RobotControl()
     laser = rc.get_laser_full()
     output.append(laser[719])
     output.append(laser[0])
     return output
예제 #4
0
 def __init__(self, moveDirection, turnDirection, speed):
     self.RobotControl = RobotControl()
     self.moveDirection = moveDirection
     self.turnDirection = turnDirection
     self.speed = speed
     self.timeTurn = 4.80  #Set to get as close to 90 degrees as possible
     self.left = 0  #Sets leftmost laser value
     self.middle = 360  #sets middle laser value
     self.right = 719  #sets rightmost laser value
예제 #5
0
 def __init__(self, motion, clockwise, speed, time):
     self.robot = RobotControl()
     self.motion = motion
     self.clockwise = clockwise
     self.speed = speed
     self.time = time
     self.time_turn = 2.5
     self.turn_speed = speed
     self.full_laser = self.robot.get_laser_full()
     self.full_laser2 = self.robot.get_laser_full()
예제 #6
0
def get_highest_lowest():
    from robot_control_class import RobotControl
    rc = RobotControl()

    laser_readings = []
    laser_readings = rc.get_laser_full()
    max = 0
    low = 1000000000000000000000
    for costas in range(0, 720):
        if laser_readings[costas] > max and laser_readings[costas] != float(
                "inf"):
            max = laser_readings[costas]
            max_pos = costas
        if laser_readings[costas] < low:
            min = laser_readings[costas]
            min_pos = costas

    return max_pos, min_pos
예제 #7
0
파일: task1.py 프로젝트: sreejen/ROS
def get_higest_lowest():
    rc = RobotControl()
    lc1 = rc.get_laser_full()
    #lc1 = [1,2,3,4,5,float('inf')]
    lc = []
    for x in lc1:
        if not math.isinf(x):
            #print (x)
            lc.append(x)
    #print (lc)
    #print (lc1)
    lw = min(lc)
    #print(lw)
    hw = max(lc)
    return lc1.index(hw), lc1.index(lw)


#j = get_higest_lowest()
#print (j)
예제 #8
0
class Project:

    def __init__(self,speed,time):
        self.rc=RobotControl()
        self.motion=None
        self.speed=speed
        self.time=time
        self.d=None
    def dist(self):
        return(self.rc.get_laser(360))
    def mov(self):
        distance=self.dist()
        while True:
            while (distance>1):
                self.rc.move_straight()
                distance=self.dist()
                print("Current distance from wall : ", distance)

            self.rc.stop_robot()
            self.motion=self.where_turn()
            self.rc.turn(self.motion,self.speed,self.time)
            print("turning ", self.motion)
            distance=self.dist()
    def where_turn(self):
        self.d=self.rc.get_laser_full()
        l1=[]
        l2=[]
        cnt=len(self.d)
        i=0
        j=cnt/2
        while(i<cnt/2):
            l1.append(self.d[i])
            i=i+1
        while(j<cnt):
            l2.append(self.d[j])
            j=j+1
        v1,v2=self.mean(l1,l2)
        print("sum of right= ",v1)
        print("sum of left= ",v2)

        if(v1>v2):
            self.d=None
            return "clockwise"
        else:
            self.d=None
            return "counter-clockwise"

    def mean(self,x,y):
        x=np.asarray(x)
        y=np.asarray(y)
        m1=np.sum(x)
        m2=np.sum(y)
        return [m1,m2]
예제 #9
0
class MoveRobot:
    def __init__(self, motion, clockwise, speed, time):
        self.RC = RobotControl()
        self.motion = motion
        self.clockwise = clockwise
        self.speed = speed
        self.time = time
        self.time_turn = 7.0

    def move_straight(self):
        self.RC.move_straight_time(self.motion, self.speed, self.time_turn)

    def turn(self):
        self.RC.turn(self.clockwise, self.speed, self.time_turn)

    def do_square(self):
        i = 0
        while (i < 4):
            self.move_straight()
            self.turn()
            i = i + 1
예제 #10
0
def get_highest_lowest():
    from robot_control_class import RobotControl
    rc = RobotControl()

    lr_list = []
    lr_list = rc.get_laser_full()
    max_val = 0
    min_val = 100000000000000000000000
    max_pos = 0
    min_pos = 0

    for item in range(0, 720):
        if lr_list[item] > max_val and lr_list[item] != float("inf"):
            max_val = lr_list[item]
            max_pos = item

        if lr_list[item] < min_val:
            min_val = lr_list[item]
            min_pos = item

    return max_pos, min_pos
예제 #11
0
class square:
    def __init__(self, motion, clockwise, speed, time):
        self.rc = RobotControl()
        self.motion = motion
        self.clockwise = clockwise
        self.speed = speed
        self.time = time
        self.turn_time = 7

    def sq(self):
        i = 0
        while i < 4:
            self.move_straight()
            self.turn()
            i += 1

    def move_straight(self):
        self.rc.move_straight_time(self.motion, self.speed, self.time)

    def turn(self):
        self.rc.turn(self.clockwise, self.speed, self.turn_time)
예제 #12
0
class MoveRobot:
    def __init__(self, motion, clockwise, speed, time):
        self.robotcontrol = RobotControl(robot_name="summit")
        self.motion = motion
        self.clockwise = clockwise
        self.speed = speed
        self.time = time
        self.time_turn = 7.0 # This is an estimate time in which the robot will rotate 90 degrees

    def do_square(self):

        i = 0

        while (i < 4):
            self.move_straight()
            self.turn()
            i+=1

    def move_straight(self):
        self.robotcontrol.move_straight_time(self.motion, self.speed, self.time)

    def turn(self):
        self.robotcontrol.turn(self.clockwise, self.speed, self.time_turn)
def get_highest_lowest():
    rc = RobotControl()
    laser = rc.get_laser_full()
    laser_dict = {}
    output = []
    for i, elem in enumerate(laser):
        if not math.isinf(elem):
            laser_dict[i] = elem
    max_val = max(laser_dict.values())
    min_val = min(laser_dict.values())
    print(max_val, min_val)

    for key, val in laser_dict.items(
    ):  # for name, age in dictionary.iteritems():  (for Python 2.x)
        if val == max_val:
            output.append(key)
            break

    for key, val in laser_dict.items(
    ):  # for name, age in dictionary.iteritems():  (for Python 2.x)
        if val == min_val:
            output.append(key)
            break
    return output
 def main(self):
     rc = RobotControl()
     d_left, d_right = self.get_laser_readings()
     print(d_left, d_right)
     while True:
         rc.move_straight()
         d_left, d_right = self.get_laser_readings()
         print(d_left, d_right)
         if (math.isinf(d_left)) and (math.isinf(d_right)):
             break
     rc.stop_robot()
예제 #15
0
파일: task3.py 프로젝트: sreejen/ROS
class ExamControl:
    def __init__(self):
        self.rc = RobotControl()

    def get_laser_readings(self):
        self.lf = self.rc.get_laser(719)
        self.rf = self.rc.get_laser(0)
        return self.lf, self.rf

    def main(self):
        self.l, self.r = self.get_laser_readings()
        #print (self.l,self.r)
        while not math.isinf(self.l) or not math.isinf(self.r):
            self.rc.move_straight()
            self.l, self.r = self.get_laser_readings()
        self.rc.stop_robot()
예제 #16
0
from robot_control_class import RobotControl

rc = RobotControl()

a = rc.get_laser(360)

if a < 1:
    rc.stop_robot()

else:
    rc.move_straight()

print(a)
예제 #17
0
파일: lists.py 프로젝트: iv20023/marcus_ws
from robot_control_class import RobotControl

rc = RobotControl()

l = rc.get_laser_full()

print("Position 0: ", l[0])
print("Position 360: ", l[360])
print("Position 719: ", l[719])
예제 #18
0
from robot_control_class import RobotControl

robotcontrol = RobotControl()

robotcontrol.turn("counter-clockwise", 0.3, 4)
robotcontrol.move_straight_time("forward", 0.3, 6)
robotcontrol.turn("counter-clockwise", 0.3, 4)
robotcontrol.move_straight_time("forward", 0.3, 7)
예제 #19
0
#!/usr/bin/env python

import sys
from robot_control_class import RobotControl

rc = RobotControl()

all_dist = rc.get_laser_full()
min_dist = min(all_dist)

while min_dist > 0.3:
    rc.move_straight()
    all_dist = rc.get_laser_full()
    min_dist = min(all_dist)
    print("The minimal distance to an object is {}".format(min_dist))

rc.stop_robot()

print("The final minimal distance is {}".format(min_dist))
예제 #20
0
from robot_control_class import RobotControl

rc = RobotControl()

rc.stop_robot()
while True:
    d = rc.get_laser(360)
    print(d)

    if (d > 1):
        rc.move_straight()
    else:
        rc.stop_robot()
        l = rc.get_laser(719)
        r = rc.get_laser(1)
        if (l > r):
            rc.turn("counter-clockwise",4,.399)
        else:
            rc.turn("clockwise",4,.399)
        
예제 #21
0
from robot_control_class import RobotControl

rc = RobotControl()

#exercise 4.3
#rc.move_straight_time("forward", 1.0, 5)
#rc.turn("clockwise", 190, 7)

#exercise 4.4
rc.move_straight_time("forward", 1.0, 2)
rc.turn("clockwise", 1.0, 7)
rc.move_straight_time("forward", 1.0, 2.2)
rc.turn("clockwise", 1.0, 7)
rc.move_straight_time("forward", 1.0, 5)
예제 #22
0
from robot_control_class import RobotControl

import time

robotcontrol = RobotControl()

class MoveRobot:
    def __init__(self, motion, clockwise, speed, time):
        self.robot = RobotControl()
        self.motion = motion
        self.clockwise = clockwise
        self.speed = speed
        self.time = time
        self.time_turn = 2.5
        self.turn_speed = speed
        self.full_laser = self.robot.get_laser_full()
        self.full_laser2 = self.robot.get_laser_full()
        #Code above initialize the construct and the variable class wich belongs the class MoveROBOT
    def out_maze(self):
        corner = 0
        maximo = 0
        #While loop used to find the labirint exit, by searching the door though the sensor "inf" value
        #When the door is found then start the door_maze function below this one
        #The full laser data is get setting the maximp< infinito, so it will always get the data
        while(maximo < float("inf")):
            self.full_laser = self.robot.get_laser_full()
            maximo = 0
#The maximo was set to =0 above to enter in the while loop,but must be update in this loop to achieve a value
#bigger than 1 and so the robot contemplate a escape of a wall that it is close it. The code below is useful
#to let the robot get free from a "trap", in other words when it be very close to a wall
#The block below will turn the robot until if finds the higher distance value, while it is close the wall
예제 #23
0
#Exercise 3,1
#Arnaldo Jr
import time
from robot_control_class import RobotControl  #importa uma classe
robotcontrol = RobotControl()  #criando um objeto


def robotmove(a):
    robotcontrol.move_straight()
    time.sleep(a)
    robotcontrol.stop_robot()


print('Forneca 3 valores entre 0 e 719.')
value = [0, 1, 2]
value[0] = input('valor 1:')
value[1] = input('valor 2:')
value[2] = input('valor 3:')
print(value)

#robotmove(5)
laser1 = robotcontrol.get_laser(360)
print(laser1)
예제 #24
0
def sleept(t=5):
    rc = RobotControl()
    rc.move_straight()
    time.sleep(t)
    rc.stop_robot()
예제 #25
0
class MoveRobot:
    def __init__(self, motion, clockwise, speed, time):
        self.robot = RobotControl()
        self.motion = motion
        self.clockwise = clockwise
        self.speed = speed
        self.time = time
        self.time_turn = 2.5
        self.turn_speed = speed
        self.full_laser = self.robot.get_laser_full()
        self.full_laser2 = self.robot.get_laser_full()
        #Code above initialize the construct and the variable class wich belongs the class MoveROBOT
    def out_maze(self):
        corner = 0
        maximo = 0
        #While loop used to find the labirint exit, by searching the door though the sensor "inf" value
        #When the door is found then start the door_maze function below this one
        #The full laser data is get setting the maximp< infinito, so it will always get the data
        while(maximo < float("inf")):
            self.full_laser = self.robot.get_laser_full()
            maximo = 0
#The maximo was set to =0 above to enter in the while loop,but must be update in this loop to achieve a value
#bigger than 1 and so the robot contemplate a escape of a wall that it is close it. The code below is useful
#to let the robot get free from a "trap", in other words when it be very close to a wall
#The block below will turn the robot until if finds the higher distance value, while it is close the wall
            while(maximo < 1):
                #For loop to get the maximum value from the laser scan reading
                for value in self.full_laser:
                    if value > maximo:
                        maximo = value

                if(maximo < 1):
                    self.turn()
            print("Current Maximum laser distace is %f" % maximo)
#After getting the maximum value you need to make the robot move in its direction.Turn the robot around
#till its frontal laser is the close enough to the maximum value - this is represented in the code by max-1
#and max!=infinite arguments. now its facing the right direction, or at least almost there.The codebelow
#will turn the robot around until the FRONT LASER BEAM = 360 find the max distance and get out the turn loop
#To be honest the loop would calculate forever the max value because it has 720 beams so each beam should be
#compared while turning to give back the biggest value. This is done faster using a tolerance,. This tolerance
#is put with maximo - [value] in this case 1 meter, so when the robot beams have a value of max aroun 6 meters
#for example it will fast accecpt the distance of 5 meter as the "infinite" distance and get out the turn loop
#to start the move_straight loop
            while(self.robot.get_front_laser() < maximo -1 and maximo != float("inf")):
                print("Robot frontal laser distance: %f", self.robot.get_front_laser())
                self.turn()
#The code above is turning the robot until it finds the "first" distance shorter or close to the infinite
#distance value, when it arrives in this value (represented by max-1) it will get out the loop and stop
#turning. Then the code below enters in action ( to be honest is being compiled in paralell) so if the robot
#is not turning mean it is going ahead until find a wall (laser<1), then this programming block will stop_robot
# and the previous blocks will work (turn and turn the robot until find again an "almost-infinite" value)
#When one of these 3 blocks be reached the function stop_robot will work, avoiding simultaneously confusion
#while executing a move
            while (self.robot.get_front_laser() > 1):
                self.move_straight()
            self.stop_robot()

    def door_maze(self):
        #Define the region frontal the robot to laser reading, 270 - 470 correspond 45 degrees of range which
        #the robot will consider to calculate the max distace === infinit
        #Here the laser scan data will calculate the most distance value = infinit. If not achieve the infinit
        #value it means that it is near a wall and thus will go to the second loop (to turn and find the next
        #laser scan data which is "infinite") the counter pass reading all the matrix laser data values, until
        #get out the loop and then move_straight
#Her if the robot frontal (45 degrees cone range: 270:450) is already getting the infinite value, so the robot
#will go toward it. The counter +=1 is just to read all the values inside user laser ( the beams 270 to 450). If
#any of them calculate an infinite value the robot will go and try get out the maze
        i_counter = 0
        self.full_laser = self.robot.get_laser_full()
        use_laser = self.full_laser[270:450]
        for i in use_laser:
            if i == float("inf"):
                i_counter += 1

        #Just enter in this loop if the door is not find at first
        #Then the robot starts turn around until its facing the door
        #The counter is used to define wheter the robot is in the rigth direction or not
        #In case its not, then the robot will turn again till the criteria is met
#If the robot still did not find the infinite value (more distance from a wall), so it will need to turns
#because maybe it is turned with its back for the free destination. So the counter will read again the
#laser scan front robot range and turn and turn until find the infinite value (more distant from a obstacle)
#to get out the loop ( already read all the use_laser matrix values with counter and comapared to find the big one)
#and all the beams=90. So it can get out the loop, because found the greatest value and move straight out the maze!
        while(i_counter < 90):
            self.turn()
            self.full_laser = self.robot.get_laser_full()
            use_laser = self.full_laser[270:450]

            i_counter = 0
            for i in use_laser:
                if i == float("inf"):
                    i_counter += 1

        self.move_straight_time()



    def move_straight_time(self):
        self.robot.move_straight_time(self.motion, self.speed, self.time)
    def move_straight(self):
        self.robot.move_straight()
    def turn(self):
        self.robot.turn(self.clockwise,self.turn_speed,self.time_turn)

    def stop_robot(self):
        self.robot.stop_robot()
예제 #26
0
from robot_control_class import RobotControl


robot = RobotControl()

def movimento():

    global a
    global b

    a = "forward"
    b = "counter-clockwise"

movimento()
direcao = robot.move_straight_time(a, 0.75, 5)
giro = robot.turn(b, 0.45, 10)


print ("O robo se deslocou com os seguinte parametros:", direcao )

print ("O robo girou com os seguintes parametros:", giro )
예제 #27
0
from robot_control_class import RobotControl

rc = RobotControl()
rc.stop_robot()

rc.move_straight_time("forward", 4, 0.15)
rc.turn("counter-clockwise", 4, .5)
rc.move_straight_time("forward", 4, .5)
rc.turn("counter-clockwise", 4, .5)
rc.move_straight_time("forward", 10, .2)
        R2 = robocontrol.get_laser(0)
        R2 = limited_decimals(R)
    if (l == 1):
        L1 = robocontrol.get_laser(600)
        L1 = limited_decimals(L1)
    elif (l == 2):
        L2 = robocontrol.get_laser(719)
        L2 = limited_decimals(L)
    if (r == 1):
        return L1, F, R1
    else:
        return L2, F, R2


x = time.time()
robocontrol = RobotControl()

while True:
    L, F, R = get_laser(1, 1)
    print("L =", L, "F =", F, "R =", R)
    if (L < 100 or F < 100 or R < 100):
        if (((R < 0.6 or L < 0.6) and F > 1.3) or (L < 0.4 or R < 0.4)):
            robocontrol.stop_robot()
            if (R < 0.6):
                print("go left_forward")
                robocontrol.move_straight_time("backward", 0.3, 3)
                robocontrol.turn("counter-clockwise", 0.3, 0.5)
                robocontrol.move_straight()
            elif (L < 0.6):
                print("go right_forward")
                robocontrol.move_straight_time("backward", 0.3, 3)
예제 #29
0
from robot_control_class import RobotControl

rc = RobotControl()

laser1 = rc.get_laser(280)
print("laser1=", laser1)

laser2 = rc.get_laser(420)
print("laser2=", laser2)

laser3 = rc.get_laser(500)
print("laser3=", laser3)

#print ("The distance measured is: ", a)
예제 #30
0
#!/usr/bin/env python

import sys
from robot_control_class import RobotControl

rc = RobotControl()

dist = rc.get_laser(0)

while dist > 1:
    rc.move_straight()
    dist = rc.get_laser(0)
    print("The distance to a wall is {}".format(dist))

rc.stop_robot()

print("The final distance is {}".format(dist))