Skip to content
Snippets Groups Projects
Commit f938db76 authored by ft-Demo's avatar ft-Demo
Browse files

commit by robo pro coding

parent 49c12fec
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
from lib.controller import *
import time
from fischertechnik.controller.Motor import Motor
import math
from lib.controller import *
from fischertechnik.controller.Motor import Motor
from lib.camera import *
from numbers import Number
......@@ -16,12 +17,14 @@ last_deviation = None
change = None
speed_left = None
speed_right = None
def lines_callback(event):
global speed, index, kp, deviation, line_color, speed_alignment, last_deviation, change, speed_left, speed_right
index = 1
while index <= len(event.value):
line_color = event.value[int(index-1)].color.rgb
if line_color[0] < 100 and line_color[1] < 100 and line_color[2] < 100:
line_color = event.value[int(index-1)].color.get_rgb()
if line_color[0] < 50 and line_color[1] < 50 and line_color[2] < 50:
deviation = event.value[int(index-1)].position
break
index = (index if isinstance(index, Number) else 0) + 1
......@@ -29,42 +32,43 @@ def lines_callback(event):
line_detector.add_detection_listener(lines_callback)
def log_data():
global speed, index, kp, deviation, line_color, speed_alignment, last_deviation, change, speed_left, speed_right
print(''.join([str(x) for x in [deviation, ', ', speed_alignment]]))
speed = 350
kp = 1.85
speed = 380
kp = 0.85
deviation = 0
last_deviation = deviation
TXT_O5_led.set_brightness(512)
TXT_M_O5_led.set_brightness(512)
while True:
if (deviation != 0):
break
time.sleep(0.010)
TXT_M1_encodermotor.set_speed(int(speed), Motor.CCW)
TXT_M2_encodermotor.set_speed(int(speed), Motor.CCW)
TXT_M1_encodermotor.start_sync(TXT_M2_encodermotor)
TXT_M_M1_encodermotor.set_speed(int(speed), Motor.CCW)
TXT_M_M1_encodermotor.start_sync()
TXT_M_M2_encodermotor.set_speed(int(speed), Motor.CCW)
TXT_M_M2_encodermotor.start_sync()
while True:
change = deviation - last_deviation
last_deviation = deviation
if change != 0:
speed_alignment = round(deviation * kp)
if speed_alignment > 0:
speed_left = speed
speed_left = speed + min([speed_alignment, 512 - speed])
speed_right = speed - min([speed_alignment, speed])
elif speed_alignment < 0:
speed_left = speed + max([speed_alignment, -speed])
speed_right = speed
speed_right = speed - max([speed_alignment, speed - 512])
else:
speed_left = speed
speed_right = speed
TXT_M1_encodermotor.set_speed(int(speed_left), Motor.CCW)
TXT_M1_encodermotor.start_sync()
TXT_M2_encodermotor.set_speed(int(speed_right), Motor.CCW)
TXT_M2_encodermotor.start_sync()
TXT_M_M1_encodermotor.set_speed(int(speed_left), Motor.CCW)
TXT_M_M1_encodermotor.start_sync()
TXT_M_M2_encodermotor.set_speed(int(speed_right), Motor.CCW)
TXT_M_M2_encodermotor.start_sync()
log_data()
time.sleep(0.02)
......@@ -2,11 +2,12 @@
from lib.controller import *
import fischertechnik.factories as txt_factory
TXT_USB_1_camera.set_width(320)
TXT_USB_1_camera.set_height(240)
TXT_USB_1_camera.set_fps(15)
TXT_USB_1_camera.start()
TXT_M_USB_1_camera.set_rotate(False)
TXT_M_USB_1_camera.set_height(240)
TXT_M_USB_1_camera.set_width(320)
TXT_M_USB_1_camera.set_fps(15)
TXT_M_USB_1_camera.start()
line_detector = txt_factory.camera_factory.create_line_detector(0, 60, 320, 20, 30, 100, -100, 100, 3)
TXT_USB_1_camera.add_detector(line_detector)
line_detector = txt_factory.camera_factory.create_line_detector(0, 60, 320, 20, 30, 130, -160, 160, 3)
TXT_M_USB_1_camera.add_detector(line_detector)
<xml type="camera" verion="1" width="320" height="240" fps="15" version="2"><item id="2" class="LineDetector"><name>line_detector</name><min_line_width>30</min_line_width><max_line_width>100</max_line_width><start_range_value>-100</start_range_value><end_range_value>100</end_range_value><number_of_lines>3</number_of_lines><geometry><x>0</x><y>60</y><width>320</width><height>20</height></geometry></item></xml>
\ No newline at end of file
<xml type="camera" verion="1" width="320" height="240" fps="15" version="2"><item id="2" class="LineDetector"><name>line_detector</name><min_line_width>30</min_line_width><max_line_width>130</max_line_width><start_range_value>-160</start_range_value><end_range_value>160</end_range_value><number_of_lines>3</number_of_lines><geometry><x>0</x><y>60</y><width>320</width><height>20</height></geometry></item></xml>
\ No newline at end of file
<xml xmlns="https://developers.google.com/blockly/xml" version="9">
<xml xmlns="https://developers.google.com/blockly/xml" version="12">
<block type="txt4_controller" id="v}Wf^VN(H6-Q3:$II]KJ" x="86" y="69">
<mutation>
<arg type="Input" name="Input-0" value="-"/>
......@@ -27,7 +27,7 @@
<field name="USB-0">USB_1</field>
<field name="USB-1">-</field>
<value name="Output-0">
<block type="led" id="]Wq5=g5:oL3DUYw`fO#7"/>
<block type="led" id="kh$y;?n1!R6~k@Hvxg{u"/>
</value>
<value name="Motor-0">
<block type="encodermotor" id="WpKi`VJ3XVuCOUuTc^=w"/>
......
import fischertechnik.factories as txt_factory
txt_factory.init_controller_factory()
txt_factory.init()
txt_factory.init_output_factory()
txt_factory.init_motor_factory()
txt_factory.init_usb_factory()
txt_factory.init_camera_factory()
TXT_M = txt_factory.controller_factory.create_graphical_controller()
TXT_M_O5_led = txt_factory.output_factory.create_led(TXT_M, 5)
TXT_M_M1_encodermotor = txt_factory.motor_factory.create_encodermotor(TXT_M, 1)
TXT_M_M2_encodermotor = txt_factory.motor_factory.create_encodermotor(TXT_M, 2)
TXT_M_USB_1_camera = txt_factory.usb_factory.create_camera(TXT_M, 1)
TXT = txt_factory.controller_factory.create_graphical_controller()
TXT_O5_led = txt_factory.output_factory.create_led(TXT, 5)
TXT_M1_encodermotor = txt_factory.motor_factory.create_encodermotor(TXT, 1)
TXT_M2_encodermotor = txt_factory.motor_factory.create_encodermotor(TXT, 2)
TXT_USB_1_camera = txt_factory.usb_factory.create_camera(TXT, 1)
txt_factory.initialized()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment