|
1 | 1 | Tutorial
|
2 | 2 | ========
|
3 | 3 |
|
4 |
| -Work in progress... |
| 4 | +First, make sure that NXT-Python is installed correctly, see |
| 5 | +:doc:`/installation`. |
| 6 | + |
| 7 | +This is not a Python tutorial, you must know how to program using Python to |
| 8 | +use NXT-Python. |
| 9 | + |
| 10 | +First step when writing a NXT-Python script is to find the brick. This is the |
| 11 | +role of the :func:`nxt.locator.find` function: |
| 12 | + |
| 13 | +.. literalinclude:: ../../examples/tutorial/find.py |
| 14 | + |
| 15 | +Once the brick is found, the :func:`nxt.locator.find` function returns an |
| 16 | +object to interact with it: the :class:`~nxt.brick.Brick` object. Here the |
| 17 | +script query device information and play a tone. |
| 18 | + |
| 19 | +Now something a little bit more interesting, plug a motor on the port A and |
| 20 | +try the following script: |
| 21 | + |
| 22 | +.. literalinclude:: ../../examples/tutorial/motor.py |
| 23 | + |
| 24 | +Try changing the parameters and see what happen. You can of course drive |
| 25 | +several motors, just use the :func:`~nxt.brick.Brick.get_motor` function for |
| 26 | +each one. |
| 27 | + |
| 28 | +You can also get information from sensors: |
| 29 | + |
| 30 | +.. literalinclude:: ../../examples/tutorial/sensor_us.py |
| 31 | + |
| 32 | +Digital sensors can be automatically detected as long as the corresponding |
| 33 | +module is loaded. In the retail set, only the ultra-sound distance sensor is |
| 34 | +digital, all the other sensors are analog. When using an analog sensor, you |
| 35 | +must give the sensor class explicitly: |
| 36 | + |
| 37 | +.. literalinclude:: ../../examples/tutorial/sensor_touch.py |
| 38 | + |
| 39 | +If you run into problems, you can increase the log level. NXT-Python is using |
| 40 | +the :mod:`logging` module from the standard Python distribution. Try this |
| 41 | +script: |
| 42 | + |
| 43 | +.. literalinclude:: ../../examples/tutorial/debug.py |
| 44 | + |
| 45 | +You should now have enough information to start playing with NXT-Python. See |
| 46 | +the :doc:`/api/index`, or the :doc:`/handbook/tips` pages for more informations. |
0 commit comments