From 7361f1b09370c153f427bc9b4d3084095f5bd831 Mon Sep 17 00:00:00 2001 From: Tanja Sukal Date: Tue, 10 Sep 2024 12:43:29 +0000 Subject: [PATCH] Update 'Object_Sorting/Program/Object_sorter.py' --- Object_Sorting/Program/Object_sorter.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Object_Sorting/Program/Object_sorter.py b/Object_Sorting/Program/Object_sorter.py index af7f529..0ad4dfb 100644 --- a/Object_Sorting/Program/Object_sorter.py +++ b/Object_Sorting/Program/Object_sorter.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 - +# Version 2.1 from 12/07/24 from time import sleep from ev3dev2.motor import Motor, MoveTank, SpeedPercent, OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D from ev3dev2.sensor import INPUT_2,INPUT_3,INPUT_4 @@ -70,10 +70,10 @@ class Object_Sorter(): # Define method/state search def search (self): # turn slowly aroud on place and search for blocks, - # if nothing is found change searchplace + # if nothing is found change search place self.leds.set_color("LEFT", "BLACK") self.leds.set_color("RIGHT", "BLACK") - # turn on place to the right + # turn on spot to the right self.m_right.on(SpeedPercent(-1*self.params["slow"])) self.m_left.on(SpeedPercent(self.params["slow"])) # search for blocks @@ -94,7 +94,7 @@ class Object_Sorter(): self.last_state = self.state self.state = "avoid" elif self.gyro.angle > 720: # when the robot does not find a block drive a little bit forward - rounds=0 # rounds of driving forward + rounds = 0 # control variable of rounds driving forward while self.cs.reflected_light_intensity > self.params["line"] and rounds <= 5: self.tank.on(self.params["fast"],self.params["fast"]) sleep(0.2) @@ -104,7 +104,6 @@ class Object_Sorter(): self.last_state = self.state self.state = "edge" self.gyro.reset() - rounds=0 # Reset control variable # Define method/state get def get (self): @@ -118,12 +117,12 @@ class Object_Sorter(): if nr_sort > 0: # if block is found again get position x = sort_block[0].x_center #get where in the field of vision the block lays self.cycles = 0 - else: # when block is not found, virtually place the robot in the middle of the vision + else: # when block is not found, virtually place the cube in the middle of the vision x = 130 self.cycles +=1 if 4 <= self.cycles < 6: # camera has not found block for 4 cycles self.tank.on_for_seconds(-1*self.params["fast"],-1*self.params["fast"],0.4) # drive backwards max. 2 times - elif 6 == self.cycles: # if block is not found drive a little bit to left + elif 6 == self.cycles: # if block is not found turn a little bit to left self.m_right.on(SpeedPercent(self.params["slow"])) self.m_left.on(SpeedPercent(-1*self.params["slow"])) sleep(0.2) @@ -135,7 +134,7 @@ class Object_Sorter(): if self.cs.reflected_light_intensity < self.params["line"]: # robot detected line change to edge self.tank.stop() self.last_state = self.state - self.state = "edge" # When colorsensor detects line then switch state + self.state = "edge" # When color sensor detects line then switch state elif self.us.distance_centimeters <= self.params["dist_us"]: # block is in the arms of robot change to sort self.last_state = self.state self.state = "sort" # when block distance is small switch state @@ -201,9 +200,11 @@ class Object_Sorter(): self.state = "search" self.gyro.reset() # reset gyro sensor again - def get_params(self): + # Method for getting parameters of the object + def get_params(self): return self.params + # Method that is used for executing def run(self): print('start') while True: # endless-loop for switching states