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

commit by robo pro coding

parents
No related branches found
No related tags found
No related merge requests found
{"uuid":"4b9d875a-1e6c-414e-bd37-19775d09d755","name":"Advanced_2_wheeled_robot_4","mode":"ADVANCED","version":"1.0","controller":"RX"}
\ No newline at end of file
This diff is collapsed.
import asyncio
import random
import user.lib.controller as controller
from fischertechnik.controller.Motor import Motor
from fischertechnik.logging import log as print
speed = None
directions = None
async def backward(speed):
global directions
controller.RX_M1_motor.set_speed(int(speed), Motor.CW)
controller.RX_M1_motor.start()
controller.RX_M2_motor.set_speed(int(speed), Motor.CW)
controller.RX_M2_motor.start()
async def forward(speed):
global directions
controller.RX_M1_motor.set_speed(int(speed), Motor.CCW)
controller.RX_M1_motor.start()
controller.RX_M2_motor.set_speed(int(speed), Motor.CCW)
controller.RX_M2_motor.start()
async def turn_left():
global speed, directions
controller.RX_M1_motor.set_speed(int(250), Motor.CW)
controller.RX_M1_motor.start()
controller.RX_M2_motor.set_speed(int(250), Motor.CCW)
controller.RX_M2_motor.start()
async def turn_right():
global speed, directions
controller.RX_M1_motor.set_speed(int(250), Motor.CCW)
controller.RX_M1_motor.start()
controller.RX_M2_motor.set_speed(int(250), Motor.CW)
controller.RX_M2_motor.start()
async def stop():
global speed, directions
controller.RX_M1_motor.stop()
controller.RX_M2_motor.stop()
async def follow_line():
global speed, directions
while ((controller.RX_I7_trail_follower.get_state() == 0) or (controller.RX_I8_trail_follower.get_state() == 0)) and (controller.RX_I2C_1_gesture_sensor.get_proximity()) < 240:
if controller.RX_I8_trail_follower.get_state() == 1:
await turn_left()
await asyncio.sleep(0.05)
if controller.RX_I7_trail_follower.get_state() == 1:
await turn_right()
await asyncio.sleep(0.05)
if (controller.RX_I7_trail_follower.get_state() == 0) and (controller.RX_I8_trail_follower.get_state() == 0):
await forward(250)
await asyncio.sleep(0.01)
if (controller.RX_I2C_1_gesture_sensor.get_proximity()) >= 240:
await backward(250)
await asyncio.sleep(1)
if 1 == random.randint(1, 2):
directions = 'Right'
await turn_right()
else:
directions = 'Left'
await turn_left()
await asyncio.sleep(0.5)
async def find_line(directions):
global speed
while (controller.RX_I7_trail_follower.get_state() == 1) and (controller.RX_I8_trail_follower.get_state() == 1):
if directions == 'Right':
await turn_right()
else:
await turn_left()
await asyncio.sleep(0.01)
async def run(instance):
global speed, directions
await controller.init(instance)
controller.RX_I2C_1_gesture_sensor.enable_proximity()
directions = 'Left'
while True:
await find_line(directions)
await follow_line()
await asyncio.sleep(0.01)
<xml xmlns="https://developers.google.com/blockly/xml" version="15"><block type="rx_controller" id="F{dqcdhfNR!daaA/Amcp" x="18" y="8"><mutation><arg type="Input" name="Input-1" value="I7"/><arg type="Input" name="Input-2" value="I8"/><arg type="Input" name="Input-0" value="-"/><arg type="Output" name="Output-0" value="-"/><arg type="Motor" name="Motor-0" value="M1"/><arg type="Motor" name="Motor-1" value="M2"/><arg type="Motor" name="Motor-2" value="-"/><arg type="I2C" name="I2C-0" value="I2C_1"/><arg type="I2C" name="I2C-1" value="-"/></mutation><field name="controller_name">RX</field><field name="Input-1">I7</field><field name="Input-2">I8</field><field name="Input-0">-</field><field name="Output-0">-</field><field name="Motor-0">M1</field><field name="Motor-1">M2</field><field name="Motor-2">-</field><field name="I2C-0">I2C_1</field><field name="I2C-1">-</field><value name="Input-1"><block type="trail_follower" id="U4]r+{fsm~ciQyQHS$xn"/></value><value name="Input-2"><block type="trail_follower" id="|Wyj4^V*L.J!b8SVC(Gd"/></value><value name="Motor-0"><block type="motor" id="SD/n[+bi,BfGY~A=zm:W"/></value><value name="Motor-1"><block type="motor" id="Kfl.c){Uc6NV*s@jGRWn"/></value><value name="I2C-0"><block type="gesture_sensor" id=")nuf/Hy7N3)uO,7+g[Mq"/></value></block></xml>
\ No newline at end of file
import asyncio
import fischertechnik.factories as rx_factory
from fischertechnik.logging import log as print
async def init(controller):
global RX_I7_trail_follower
global RX_I8_trail_follower
global RX_M1_motor
global RX_M2_motor
global RX_I2C_1_gesture_sensor
rx_factory.init_controller_factory()
rx_factory.init_input_factory()
rx_factory.init_motor_factory()
rx_factory.init_i2c_factory()
RX_I7_trail_follower = rx_factory.input_factory.create_trail_follower(controller, 7)
RX_I8_trail_follower = rx_factory.input_factory.create_trail_follower(controller, 8)
RX_M1_motor = rx_factory.motor_factory.create_motor(controller, 1)
RX_M2_motor = rx_factory.motor_factory.create_motor(controller, 2)
RX_I2C_1_gesture_sensor = rx_factory.i2c_factory.create_gesture_sensor(controller, 1)
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