Opis

Marek, Siara, siara@student.agh.edu.pl

:!: Multilayer Stack in Prolog idea:

  • Serial Comm.(USB/BT)
  • low-level Prolog api 4 serial port, NXT comm. protocol, see other envs
  • mid-level NXT abstraction

see MindStormsAPI for other higher levels.

Spotkania

08.03.04

080311

protokół na poziomie kom. po porcie szeregowym http://nxtpp.sourceforge.net/

080318

080401

080408

  • zapis protokołu kom w prologu tak jak poniżej
  • upload do wiki opisu FIXME
  • testy komunikacji, flush?
  • zapis szesnastkowy w ISO Prologu, proszę się upewnić, że to (hexy) się już nigdzie nie gubi przy ew. konwersji…

080415

  • test komunikacji!!!!!!!
  • całośc kom 2 kier na kilku poleceniach

Projekt

% C = getbatterylevel
%nxt_com(getbatterylevel, Ret) 

nxt_com(C) :- 
%  nxt_open(Fd),
  nxt_prot(C, NxtCmd, RL), %Rl=4 bl
  nxt_send(Fd,NxtCmd),
  nxt_recv(Fd,RL,Resp),
  nxt_resp(C, Resp, X). % X = VLMV

%nxt_open(Fd) :-
%
nxt_send(Fd,NxtCmd) :-

nxt_recv(Fd,R) :-

nxt_resp(getbatterylevel)
% uwaga!
% komp w pldoc!
% http://www.swi-prolog.org/packages/pldoc.html
% przemyslec, co da uzycie skladni wiki!

% czy porty dla sensorow sa abcd, czy 1,2,3,4?

Z dokumentacji:

  • Byte 2: Output port (Range: 0 - 2)
  • Byte 2: Input port (Range: 0 - 3)

Z nxt++:

  • Motor A - 0;
  • Motor B - 1;
  • Motor C - 2;
  • Sensor 1 - 0;
  • Sensor 2 - 1;
  • Sensor 3 - 2;
  • Sensor 4 - 3;
% póki co:
nxt_port(0,['\x00\']). % sprawdzić!
nxt_port(1,['\x01\']).
nxt_port(2,['\x02\']).

nxt_sensor_type(no_sensor, ['\x00\']).
nxt_sensor_type(switch, ['\x01\']).
nxt_sensor-type(temperature, ['\x02\']).
nxt_sensor-type(reflection, ['\x03\']).
nxt_sensor-type(angle, ['\x04\']).
nxt_sensor-type(light_active, ['\x05\']).
nxt_sensor-type(light_inactive, ['\x06\']).
nxt_sensor-type(sound_db, ['\x07\']).
nxt_sensor-type(sound_dba, ['\x08\']).
nxt_sensor-type(custom, ['\x09\']).
nxt_sensor-type(low_speed, ['\x0A\']).
nxt_sensor-type(low_speed_9v, ['\x0B\']).
nxt_sensor-type(no_of_sensor_types, ['\x0C\']).

nxt_sensor_mode(rawmode, ['\x00\']).
nxt_sensor_mode(booleanmode, ['\x20\']).
nxt_sensor_mode(transitioncntmode, ['\x40\']).
nxt_sensor_mode(periodcountermode, ['\x60\']).
nxt_sensor_mode(pctfullscalemode, ['\x80\']).
nxt_sensor_mode(celciusmode, ['\xA0\']).
nxt_sensor_mode(fahrenheitmode, ['\xC0\']).
nxt_sensor_mode(anglestepmode, ['\xE0\']).
nxt_sensor_mode(slopemask, ['\x1F\']).
nxt_sensor_mode(modemask, ['\xE0\']). % zbieżność z drugim powyżej, co z tym zrobić ?

nxt_mode(motoron, ['\x01\']).
nxt_mode(brake, ['\x02\']).
nxt_mode(regulated, ['\x04\']).

nxt_regulation_mode(regulation_mode_idle, ['\x00\']).
nxt_regulation_mode(regulation_mode_motor_speed, ['\x01\']).
nxt_regulation_mode(regulation_mode_motor_syns, ['\x02\']).

nxt_run_state(motor_run_state_idle, ['\x00\']).
nxt_run_state(motor_run_state_rampup, ['\x10\']).
nxt_run_state(motor_run_state_running, ['\x20\']).
nxt_run_state(motor_run_state_rampdown, ['\x40\']).

% w nxt++ nie wysyłają na początku bajtu zerowego, to byłoby logiczne, ponieważ zawsze na początku będzie startprogram... :

nxt_cmd(startprogram, ['\x00\','\x00\']). % czy dopisać wszędzie nxt_cmd(Cmd, ['\x80\',_]).  ???
nxt_cmd(stopprogram, ['\x00\','\x01\']).
nxt_cmd(playsoundfile, ['\x00\','\x02\']).
nxt_cmd(playtone, ['\x00\','\x03\']).
nxt_cmd(setoutputstate, ['\x00\','\x04\']).  
nxt_cmd(setinputmode, ['\x00\','\x05\']).
nxt_cmd(getoutputstate, ['\x00\','\x06\']).
nxt_cmd(getinputvalues, ['\x00\','\x07\']).
nxt_cmd(resetinputscaledvalue, ['\x00\','\x08\']).
nxt_cmd(messagewrite, ['\x00\','\x09\']).
nxt_cmd(resetmotorposition, ['\x00\','\x0A\']).
nxt_cmd(getbatterylevel, ['\x00\','\x0B\']).
nxt_cmd(stopsoundplayback, ['\x00\','\x0C\']).
nxt_cmd(keepalive, ['\x00\','\x0D\']).
nxt_cmd(lsgetstatus, ['\x00\','\x0E\']).
nxt_cmd(lswrite, ['\x00\','\x0F\']).
nxt_cmd(lsread, ['\x00\','\x10\']).
nxt_cmd(getcurrentprogramname, ['\x00\','\x11\']).
nxt_cmd(messageread, ['\x00\','\x12\']).

%% nxt_prot(+Command, -NxtCmd, +Port, +Type, +Mode, +Etc)

nxt_prot(startprogram, NxtCmd, FileName) :-
	nxt_cmd(startprogram,Cmd),
	?

nxt_prot(stopprogram, NxtCmd) :-
	nxt_cmd(stopprogram, Cmd),
	flatten([Cmd], NxtCmd).

nxt_prot(playsoundfile, NxtCmd, Loop, FileName) :-
	nxt_cmd(playsoundfile, Cmd),
	boolean(Loop),
	LoopCmd = Loop,
	?

nxt_prot(playtone, NxtCmd, Frequency, Duration) :-
	nxt_cmd(playtone, Cmd),
	FrequencyCmd1 is Frequency mod 256,
	FrequencyCmd2 is (Frequency - (Frequency mod 256)) / 256, % wzięte z nxt++
	DurationCmd1 is Duration mod 256,
	DurationCmd2 is (Duration - (Duration mod 256)) / 256,
	flatten([Cmd, FrequencyCmd1, FrequencyCmd2, DurationCmd1, DurationCmd2], NxtCmd). % <- poprawić na listy!

nxt_prot(setoutputstate, NxtCmd, Port, PowerSetPoint, Mode, RegulationMode, TurnRatio, RunState, TachoLimit) :-
	nxt_cmd(setoutputstate,Cmd),
	nxt_port(Port, PortCmd),
	integer(PowerSetPoint), PowerSetPoint >= -100, PowerSetPoint < 101,
	nxt_mode(Mode, ModeCmd),
	nxt_regulation_mode(RegulationMode, RegulationModeCmd),
	integer(TurnRatio), TurnRatio >= -100, TurnRatio < 101,
	nxt_run_state(RunState, RunStateCmd),
	TachoLimit < (5B value ?),
	flatten([Cmd, Port, PowerSetPoint, Mode, RegulationMode, TurnRatio, RunState, TachoLimit], NxtCmd).

% return a nxt command with a given port, type, and mode (for setinputmode)
nxt_prot(setinputmode, NxtCmd, Port, Type, Mode) :-
	nxt_cmd(setinputmode,Cmd),
	nxt_port(Port, PortCmd),
	nxt_sensor_type(Type, TypeCmd),
	nxt_sensor_mode(Mode, ModeCmd),
	flatten([Cmd, PortCmd,TypeCmd,ModeCmd],NxtCmd).

nxt_prot(getoutputstate, NxtCmd, Port) :-
	nxt_cmd(getoutputstate, Cmd),
	nxt_port(Port, PortCmd),
	flatten([Cmd, PortCmd], NxtCmd).

nxt_prot(getinputvalues, NxtCmd, Port) :-
	nxt_cmd(getinputvalues, Cmd),
	nxt_port(Port, PortCmd),
	flatten([Cmd, PortCmd], NxtCmd).

nxt_prot(resetinputscaledvalue, NxtCmd, Port) :-
	nxt_cmd(resetinputscaledvalue, Cmd),
	nxt_port(Port, PortCmd),
	flatten([Cmd, PortCmd], NxtCmd).

nxt_prot(messagewrite, NxtCmd, Inbox, Size,Data) :-
	nxt_cmd(messagewrite,Cmd),
	integer(Inbox), Inbox < 10, Inbox >= 0,
	length(Data,L),
	Size is L + 3,
	Size < 60, % vide doc!
	flatten([Cmd,Inbox,Size,Data],NxtCmd).

nxt_prot(resermotorposition, NxtCmd, Port, IsRelative) :-
	nxt_cmd(resermotorposition, Cmd),
	nxt_port(Port, PortCmd),
	boolean(IsRelative),
	IsRelativeCmd = IsRelative,
	flatten([Cmd, , PortCmd, IsRelativeCmd], NxtCmd).

nxt_prot(getbatterylevel, NxtCmd) :-
	nxt_cmd(getbatterylevel, Cmd),
	flatten([Cmd], NxtCmd).

nxt_prot(stopsoundplayback, NxtCmd) :-
	nxt_cmd(stopsoundplayback, Cmd),
	flatten([Cmd], NxtCmd).

nxt_prot(keepalive, NxtCmd) :-
	nxt_cmd(keepalive, Cmd),
	flatten([Cmd], NxtCmd).

nxt_prot(lsgetstatus, NxtCmd, Port) :-
	nxt_cmd(lsgetstatus, Cmd),
	nxt_port(Port, PortCmd),
	flatten([Cmd, PortCmd], NxtCmd).

nxt_prot(lswrite, NxtCmd, Port, TxDataLenght, RxDataLength, TxData) :-
	nxt_cmd(lswrite, Cmd),
	nxt_port(Port, PortCmd),
	length(TxData,L),
	TxDatalength is L + 4,
	TxDataLength < (no właśnie, ile?),
	flatten([Cmd, Port, TxDataLength, RxDataLength, TxData], NxtCmd).

nxt_prot(lsread, NxtCmd, Port) :-
	nxt_cmd(lsread, Cmd),
	nxt_port(Port, PortCmd),
	flatten([Cmd, PortCmd], NxtCmd).

nxt_prot(getcurrentprogramname, NxtCmd) :-
	nxt_cmd(getcurrentprogramname, Cmd),
	flatten([Cmd], NxtCmd).

nxt_prot(mesageread, NxtCmd, RemoteInbox, LocalInbox, Remove) :-
	nxt_cmd(messageread, Cmd),
	integer(RemoteInbox), RemoteInbox >= 0, RemoteInbox < 10,
	integer(LocalInbox), LocalInbox >= 0, LocalInbox < 10,
	boolean(Remove),
	RemoveCmd = Remove,
	flatten([Cmd, RemoteInbox, LocalInbox, Remove], NxtCmd).



% tu nalezy jeszcze sprawdzic null termination vide dokuemntacja, ew dodac jak go nie ma!

% nxt_prot(setinputmode,C,a,switch,rawmode).
% nxt_prot(messagewrite,C,3,S,['a','l','a']).
% nxt_prot(messagewrite,C,3,_,['a','l','a']).

% aha, prosze przemyslec i potestowac, czy nie wystarczy powyzej pisac:
% nxt_prot(COSTAM, NxtCmd, Inbox, Size,Data) :-
%	nxt_cmd(COSTAM,Cmd),
% na oko chyba tak!

FIXME :pl:miw:appendix_2-lego_mindstorms_nxt_direct_commands.pdf

FIXME: proszę dopisać URL gdzie za strony LEGO Pan to pobrał, czy to jest w BT dev guide?

Milestones

  • komunikacja z nxt z prolog, potrafimy wyslac trywialne rozkazy, np. obroc silniczkem nr. 2

Sprawozdanie

W związku z tym, że materiały podane poniżej były mało ciekawe, a na stronie producenta ciężko jest cokolwiek znaleźć, zapoznałem się z dokumentacją techniczną i zasadą działania standardu USB. Mam nadzieję, że ta wiedza będzie pomocna, ponieważ poznawanie standardu USB było uciążliwe. Wiele jest ciekawych materiałów w sieci, po przeczytaniu skrócony opis zamieściłem w http://student.agh.edu.pl/~siara/USB.pdf

Materiały

pl/miw/miw08_mindstormscontrols.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0