Lesson 1 of 5Robotics with fischertechnik
Robotics with fischertechnik · Lesson 1 · 25 minutes
The TXT 4.0 and ftrobopy
What you'll learn
- Know the M, O, I and C ports of the TXT 4.0
- Connect to the TXT with ftrobopy
- Give feedback with
print()and a lamp
The code in this lesson comes from the book “Python for Robots”, Chapter 3.1, and runs unchanged in the simulator. German edition on Amazon ↗
The controller for your fischertechnik models
The TXT 4.0 from fischertechnik is a small computer with a battery, Wi-Fi, a touch display and lots of ports. It’s made for bigger, stronger models – conveyor belts, traffic lights or sorting machines.
Here you program it with ftrobopy. That’s real Python, no blocks at all. In the browser a simulated TXT runs: below every program you see a control panel with motors, lamps and buttons.
The ports
| Port | What it’s for |
|---|---|
| M1 – M4 | motor outputs for XS motors (with encoder) |
| O1 – O8 | simple outputs for lamps and LEDs |
| I1 – I8 | inputs for sensors and buttons |
| C1 – C4 | counter inputs for the encoder pulses |
You count like the labels on the case: M1 is txt.motor(1), O1 is txt.output(1), I1 is txt.input(1). So here you start at 1, not at 0 like with lists.
Connecting to the TXT
Every ftrobopy program from the book starts like this:
# ftrobopy connects our Python program to the TXT 4.0 controller.
import ftrobopy
# Establish a connection ("localhost" if the program runs directly on the TXT,
# otherwise the TXT's IP address on the Wi-Fi network)
txt = ftrobopy.ftrobopy("localhost", 65000)
print("Connected to the TXT 4.0!")On the real TXT, "localhost" is right when the program runs directly on the controller. If it runs on your computer, the TXT’s IP address on the Wi-Fi goes there. In the browser it doesn’t matter – there’s only the simulated TXT.
Feedback without a screen: ftrobopy can’t write on the TXT’s display. So you see messages with
print()in the console. Or you use a lamp on an O output as a signal. That’s exactly what you practise in the task.
Your task
Your turn
Exercise 3.1 from the book: write a connection check. After connecting, the program prints Connection successful with print(). Then it switches on the lamp on O1 for one second (setLevel(512), sleep(1), setLevel(0)).
import ftrobopy
from time import sleep
txt = ftrobopy.ftrobopy("localhost", 65000)
# Print the message
# Switch on the lamp on O1 for one second- Something to think about
print("Connection successful") - Which command helps?
lamp
=txt.output(1), thenlamp.setLevel(512),sleep(1)andlamp.setLevel(0). - Gap code – fill in the ___
import ftrobopy from time import sleep txt = ftrobopy.ftrobopy("localhost", 65000) print(___) lamp = ___ lamp.setLevel(___) sleep(___) lamp.setLevel(___)
Solve it without hints to earn a ⭐ on your progress page.
Show solution🔒 Unlocks after all hints or 2 checks
Try it yourself first – mistakes teach you the most. Here is one possible solution:
import ftrobopy
from time import sleep
txt = ftrobopy.ftrobopy("localhost", 65000)
print("Connection successful")
lamp = txt.output(1)
lamp.setLevel(512)
sleep(1)
lamp.setLevel(0)