Both sides previous revision
Poprzednia wersja
Nowa wersja
|
Poprzednia wersja
|
pl:miw:miw08_mindstormscontrols [2008/04/07 19:54] miw |
pl:miw:miw08_mindstormscontrols [2019/06/27 15:50] (aktualna) |
| |
| |
| ===== 080408 ===== |
| * zapis protokołu kom w prologu tak jak poniżej |
| * upload do wiki opisu FIXME |
| * testy komunikacji, flush? |
| * [[https://akela.mendelu.cz/swi-prolog/syntax.html|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 ====== |
| |
| <code> |
| |
===== 080408 ===== | % C = getbatterylevel |
* zapis protokołu kom w prologu tak jak poniżej | %nxt_com(getbatterylevel, Ret) |
* upload do wiki opisu FIXME | |
* testy komunikacji, flush? | nxt_com(C) :- |
* [[https://akela.mendelu.cz/swi-prolog/syntax.html|zapis szesnastkowy w ISO Prologu]], proszę się upewnić, że to (hexy) się | % nxt_open(Fd), |
już nigdzie nie gubi przy ew. konwersji... | 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) |
| </code> |
| |
<code> | <code> |
| |
% czy porty dla sensorow sa abcd, czy 1,2,3,4? | % czy porty dla sensorow sa abcd, czy 1,2,3,4? |
nxt_port(a,['\x00\']). | |
% etc | |
| |
</code> | </code> |
dla serwo 0, 1, 2, sensory do sprawdzenia. | 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; |
<code> | <code> |
| % 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(no_sensor, ['\x00\']). |
nxt_sensor_mode(anglestepmode, ['\xE0\']). | nxt_sensor_mode(anglestepmode, ['\xE0\']). |
nxt_sensor_mode(slopemask, ['\x1F\']). | nxt_sensor_mode(slopemask, ['\x1F\']). |
nxt_sensor_mode(modemask, ['\xE0\']). % patrz 2 wyżej! | 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(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(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). |
| |
%% nxt_prot(+Command, -NxtCmd, +Port, +Type, +Mode) | |
% return a nxt command with a given port, type, and mode (for setinputmode) | % return a nxt command with a given port, type, and mode (for setinputmode) |
nxt_prot(setinputmode, NxtCmd, Port, Type, Mode) :- | nxt_prot(setinputmode, NxtCmd, Port, Type, Mode) :- |
nxt_sensor_mode(Mode, ModeCmd), | nxt_sensor_mode(Mode, ModeCmd), |
flatten([Cmd, PortCmd,TypeCmd,ModeCmd],NxtCmd). | 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_prot(messagewrite, NxtCmd, Inbox, Size,Data) :- |
Size < 60, % vide doc! | Size < 60, % vide doc! |
flatten([Cmd,Inbox,Size,Data],NxtCmd). | 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! | % tu nalezy jeszcze sprawdzic null termination vide dokuemntacja, ew dodac jak go nie ma! |
FIXME: proszę dopisać URL gdzie za strony LEGO Pan to pobrał, czy to jest w BT dev guide? | FIXME: proszę dopisać URL gdzie za strony LEGO Pan to pobrał, czy to jest w BT dev guide? |
| |
====== Projekt ====== | |
===== Milestones ===== | ===== Milestones ===== |
* komunikacja z nxt z prolog, potrafimy wyslac trywialne rozkazy, np. obroc silniczkem nr. 2 | * komunikacja z nxt z prolog, potrafimy wyslac trywialne rozkazy, np. obroc silniczkem nr. 2 |