% % Implementation by Piotr Hołownia % % Copyright (C) 2006-9 by the HeKatE Project % % PlNXT has been develped by the HeKatE Project, % see http://hekate.ia.agh.edu.pl % % This file is part of PlNXT. % % PlNXT is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation, either version 3 of the License, or % (at your option) any later version. % % PlNXT is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with PlNXT. If not, see . % :- module(nxt_sensomoto,[ nxt_connection_open/0, nxt_connection_close/0, nxt_motor/2, nxt_motor/3, nxt_touch_sensor/2, nxt_sound_sensor/2, nxt_light_sensor/2, nxt_light_sensor_LED/2, nxt_ultrasonic_sensor/2, nxt_voltage/1, nxt_voltage_millivolt/1, nxt_start_program/1, nxt_stop_program/0, nxt_play_sound_file/1, nxt_play_sound_file/2, nxt_stop_sound_playback/0, nxt_play_tone/2, nxt_brick_name/1 ]). /** NXT Mindstroms - Sensomoto. @author Piotr Hołownia @license GNU General Public License */ :- use_module(nxt_actions_icommand). :- use_module(threads). %% nxt_connection_open % % Opens connection. nxt_connection_open :- nxt_actions_connection_open. %% nxt_connection_close % % Closes connection. nxt_connection_close :- nxt_actions_connection_close. %% nxt_motor(+Motor,+Speed). %% nxt_motor(+Motor,-Speed). % % Reads speed of the specified motor % or rotates it at specified speed. nxt_motor(_,Speed) :- nonvar(Speed), Speed > 900, writeln('Rotational speed is to high!'). nxt_motor(_,Speed) :- nonvar(Speed), Speed < -900, writeln('Rotational speed is to high!'). nxt_motor(Motor,Speed) :- nonvar(Motor),nonvar(Speed), Speed > 0, nxt_actions_motor_forward(Motor,Speed). nxt_motor(Motor,Speed) :- nonvar(Motor),nonvar(Speed), Speed < 0, BackwardSpeed is -Speed, nxt_actions_motor_backward(Motor,BackwardSpeed). nxt_motor(Motor,Speed) :- % Returns absolute value of speed. nonvar(Motor),var(Speed), nxt_actions_motor_get_speed(Motor,Speed). nxt_motor(Motor,0) :- nonvar(Motor), nxt_actions_motor_stop(Motor). %% nxt_motor(+Motor,+Speed,+Spec). % % Rotates motor forward if Speed is positive, backward if Speed is negative. Character of this rotation depends on Spec. Spec is one of: % % * time(+Time) % Changes motor speed for a specified time. % % * angle(+Angle) % Rotates motor at specified speed. % Motor will stop, when specified revolution (Angle in degrees) is reached. % % * +Angle % The same as angle(+Angle) nxt_motor(_,Speed,_) :- nonvar(Speed), Speed > 900, writeln('Rotational speed is to high!'). nxt_motor(_,Speed,_) :- nonvar(Speed), Speed < -900, writeln('Rotational speed is to high!'). nxt_motor(Motor,Speed,time(Time)) :- nonvar(Motor),nonvar(Speed),nonvar(Time), nxt_motor(Motor,OldSpeed), nxt_motor(Motor,Speed), timer_create(_,Time,nxt_motor(Motor,OldSpeed)). nxt_motor(Motor,Speed,angle(Angle)) :- nonvar(Motor),nonvar(Speed),nonvar(Angle), Speed > 0, nxt_actions_motor_rotate(Motor,Speed,Angle). nxt_motor(Motor,Speed,angle(Angle)) :- nonvar(Motor),nonvar(Speed),nonvar(Angle), Speed < 0, MinusSpeed is -Speed, MinusAngle is -Angle, nxt_actions_motor_rotate(Motor,MinusSpeed,MinusAngle). nxt_motor(Motor,Speed,Angle) :- nxt_motor(Motor,Speed,angle(Angle)). %% nxt_touch_sensor(+Port,-Value). % % Gets touch sensor reading. % Returns 1 if pressed, 0 otherwise nxt_touch_sensor(Port,Value) :- nonvar(Port), nxt_actions_touch_sensor(Port,Value). %% nxt_sound_sensor(+Port,-Value). % % Gets sound sensor reading. nxt_sound_sensor(Port,Value) :- nonvar(Port), nxt_actions_sound_sensor(Port,Value). %% nxt_light_sensor(+Port,-Value). % % Gets light sensor reading. nxt_light_sensor(Port,Value) :- nonvar(Port), nxt_actions_light_sensor(Port,Value). %% nxt_light_sensor_LED(+Port,Setting). % % Sets the LED on if Setting is =activate= or off if =passivate=. nxt_light_sensor_LED(Port,Setting) :- nonvar(Port), nxt_actions_light_sensor_LED(Port,Setting). %% nxt_ultrasonic_sensor(+Port,-Value). % % Gets ultrasonic sensor reading. nxt_ultrasonic_sensor(Port,Value) :- nonvar(Port), nxt_actions_ultrasonic_sensor(Port,Value). %% nxt_voltage(-Voltage). % % Returns battery voltage in V. nxt_voltage(Voltage) :- nxt_actions_voltage(Voltage). %% nxt_voltage_millivolt(-Voltage). % % Returns battery voltage in mV. nxt_voltage_millivolt(Voltage) :- nxt_actions_voltage_millivolt(Voltage). %% nxt_start_program(+File) % % Starts a Lego executable file on the NXT. % DOES NOT WORK PROPERLY!! nxt_start_program(File) :- nxt_actions_start_program(File). %% nxt_stop_program. % % Stops the currently running Lego executable on the NXT. % DOES NOT WORK PROPERLY!! nxt_stop_program :- nxt_actions_stop_program. %% nxt_play_sound_file(+File). %% nxt_play_sound_file(+File,+Repeat). % % Plays a sound file from the NXT. % Files use the .rso extension. % The filename is not case sensitive. % nxt_play_sound_file/1 plays sound once. % nxt_play_sound_file/2 plays sound once if Repeat is true % or till nxt_stop_sound_playback is used if Repeat is % false. % DOES NOT WORK PROPERLY!! nxt_play_sound_file(File) :- nxt_actions_play_sound_file(File,false). nxt_play_sound_file(File,Repeat) :- nxt_actions_play_sound_file(File,Repeat). %% nxt_stop_sound_playback. % % Stops a sound file that has been playing/repeating. % DOES NOT WORK PROPERLY!! nxt_stop_sound_playback :- nxt_actions_stop_sound_playback. %% nxt_play_tone(Frequency,Duration). % % Plays tone at specified frequency. % DOES NOT WORK PROPERLY!! nxt_play_tone(Frequency,Duration) :- nxt_actions_play_tone(Frequency,Duration). %% nxt_brick_name(+Name). %% nxt_brick_name(-Name). % % Gets or sets the name of the brick. % DOES NOT WORK PROPERLY!! nxt_brick_name(Name) :- var(Name), nxt_actions_get_brick_name(Name). nxt_brick_name(Name) :- nonvar(Name), nxt_actions_set_brick_name(Name).