First steps

Connection test


$ pl
?- [plnxt].
?- nxt_open.

Pay attention to the established connection symbol on the brick display.


Checking the battery level (the simplest command, which writes and reads from the device):

?- nxt_voltage_millivolt(Voltage).

You should receive the battery voltage, if not, there is a problem!


?- nxt_close.

Pay attention to the established connection symbol on the brick display. It has gone.

Using SWIPL shell

Please run the SWIPL shell and load the file ([plnxt].). Then:

  • Open connection: nxt_open.
  • Perform a series of selected commands (movement, sensors readings). For example:
    • nxt_go(300). % Moving forward at a speed of 300 degrees/second.
    • nxt_stop.
    • nxt_go_cm(400,80). % Moving 80 cm forward at a speed of 400 degrees/second.
    • nxt_touch(Value). % Reading touch sensor.
    • nxt_sound(Value). % Reading sound sensor.
    • nxt_light(Value). % Reading light sensor.
    • nxt_light_LED(activate). % Turning a light sensor diode on.
    • nxt_light(Value).
    • nxt_light_LED(passivate).
    • nxt_ultrasonic(Value).
    • nxt_rotate(350,360). % Rotating 360 degrees to the right at a speed of 350 degrees/second.
    • nxt_play_tone(500,2000). % Playing tone at frequency 500 Hz for 2000 ms.
  • Close connection: nxt_close.

File programs

Most of predicates have their version with a force option (e.g. nxt_go(400, force).), which causes the immediate execution of the command. The lack of this option makes the command execution waiting till the robot is stopped.
This allows to write sequential programs, such as the following example.

Please copy the code below into a file and consult it in SWIPL.

:- consult('plnxt.pl_path').
start :-
	nxt_go_cm(400,80), % Moving 80 cm forward at a speed of 400 degrees/second.
	nxt_go_cm(-400,80), % Moving 80 cm backward at a speed of 400 degrees/second.
:- start.

What in this case is the 'force' option needed for?

Please test the simple examples of using the trigger mechanism (FIXME documentation).

Example 1

:- consult('plnxt.pl_path').
start :-
check_distance :-
	Distance < 15.

The trigger will be fired, when check_distance is true. Then the robot will be stopped and the connection closed.
Therefore, it is a simple program: robot moves forward till encounters an obstacle.
The measurement of distance is cyclic. Without the 'force' option it would take place after the engines stopped (in this case “never”).
The robot would painfully encounter an obstacle.

Example 2

:- consult('../').
go_on_buddy :-
        sleep(1), % Short break, so one clap would not be recognized as two.
wait_a_second_buddy :-
% Verifying if the sound intensity exceeds the threshold value.
clap :-
	Value > 15.
% Verifying if the touch sensor is pressed.
pushed :-

The robot moves forward. Stops after a clap. Moves farther after an another clap.
It stops and closes the connection after pressing touch sensor.
Choose a threshold for detecting a clap sound.
Too low value can cause a loop.
Too high will make you will have to punch the sensor instead of clapping.

mindstorms/plnxt/first_steps.txt · Last modified: 2017/07/17 08:08 (external edit) Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0