jrullan / statemachine Goto Github PK
View Code? Open in Web Editor NEWState machine library for Arduino
License: MIT License
State machine library for Arduino
License: MIT License
this code work ok
void loop() {
machine.run();
machine.transitionTo(S4);
delay(STATE_DELAY);
}
but this code not work
void state0(){
Serial.println("State 0");
if(machine.executeOnce){
Serial.println("Execute Once");
digitalWrite(LED,!digitalRead(LED));
}
machine.transitionTo(S4); //**problem**
}
Hi, there, I wrote a process control program using this library last year, it works fine by then. However, I try to make some modification to the program, and compiler error appears, I remove all modification, compiler error won't disappear. My target board is Arduino mega 2560, my Arduino ide version is 1.8.12, the compiler errors are as following:
Arduino: 1.8.12 (Windows Store 1.8.33.0) (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
In file included from C:\Users\17629\Documents\Arduino\libraries\StateMachine\src/StateMachine.h:1:0,
from D:\code\arduino\NEATOS\neat_rzcp_an\neat_rzcp\neat_rzcp.ino:28:
C:\Users\17629\Documents\Arduino\libraries\LinkedList/LinkedList.h: In instantiation of 'ListNode* LinkedList::getNode(int) [with T = Transition*]':
C:\Users\17629\Documents\Arduino\libraries\LinkedList/LinkedList.h:314:28: required from 'T LinkedList::get(int) [with T = Transition*]'
C:\Users\17629\Documents\Arduino\libraries\StateMachine\src/State.h:83:32: required from here
C:\Users\17629\Documents\Arduino\libraries\LinkedList/LinkedList.h:160:9: error: cannot convert 'bool' to 'ListNode<Transition*>*' in return
return false;
^~~~~
C:\Users\17629\Documents\Arduino\libraries\LinkedList/LinkedList.h: In instantiation of 'ListNode* LinkedList::getNode(int) [with T = State*]':
C:\Users\17629\Documents\Arduino\libraries\LinkedList/LinkedList.h:314:28: required from 'T LinkedList::get(int) [with T = State*]'
C:\Users\17629\Documents\Arduino\libraries\StateMachine\src/StateMachine.h:54:41: required from here
C:\Users\17629\Documents\Arduino\libraries\LinkedList/LinkedList.h:160:9: error: cannot convert 'bool' to 'ListNode<State*>*' in return
exit status 1
Error compiling for board Arduino Mega or Mega 2560.
Does someone else have encountered this problem and how could I fix it?
When creating a project in VScode with the Platformio plugin, it becomes necessary to re-include the library header file in several files, for example, to use the extern
keyword.
The original version of the library does not allow this. I separated the class methods into .cpp files, now the library header files can be included in several compilation units.
Please, see my pull request #10
FYI: For some reason it is version 1.0.11 that is available in the Platform.io library manager and not the latest (1.0.13).
I had to manually download and copy this library to the project folder use it.
Hello,
Just started using your library and this puzzles me:
S0->addTransition(&transitionS0,S0); // Transition to itself (see transition logic for details)
Where exactly is the "transition logic" explained ?
Hello
I use the transitionTo() like this
else
{
XPNet.getLocoInfo(0, 3);
stm.transitionTo(stPowerOn);
}
but there is no state change...
The state machine keeps in the state where it was as shown in the logging
StateMachine::run() : 5
StateGetLocInfo
StateMachine::run() : 5
StateMachine::transitionTo() : 3
StateMachine::run() : 5
What I'm doing wrong?
Hi there. Using your library for state machines in an Arduino project and ran into an issue with the following error. I do have the latest LinkedList version available through the Arduino library. Unless perhaps I installed incorrectly?
In file included from C:\Users\Daniel\Documents\Arduino\libraries\StateMachine\src\State.h:1:0,
from C:\Users\Daniel\Documents\Arduino\libraries\StateMachine\src\State.cpp:1:
C:\Users\Daniel\Documents\Arduino\libraries\LinkedList/LinkedList.h: In instantiation of 'ListNode* LinkedList::getNode(int) [with T = Transition*]':
C:\Users\Daniel\Documents\Arduino\libraries\LinkedList/LinkedList.h:314:28: required from 'T LinkedList::get(int) [with T = Transition*]'
C:\Users\Daniel\Documents\Arduino\libraries\StateMachine\src\State.cpp:46:32: required from here
C:\Users\Daniel\Documents\Arduino\libraries\LinkedList/LinkedList.h:160:9: error: cannot convert 'bool' to 'ListNode<Transition*>' in return
return false;
^~~~~
In file included from C:\Users\Daniel\Documents\Arduino\libraries\StateMachine\src\StateMachine.h:1:0,
from C:\Users\Daniel\Documents\Arduino\libraries\StateMachine\src\StateMachine.cpp:1:
C:\Users\Daniel\Documents\Arduino\libraries\LinkedList/LinkedList.h: In instantiation of 'ListNode LinkedList::getNode(int) [with T = State*]':
C:\Users\Daniel\Documents\Arduino\libraries\LinkedList/LinkedList.h:314:28: required from 'T LinkedList::get(int) [with T = State*]'
C:\Users\Daniel\Documents\Arduino\libraries\StateMachine\src\StateMachine.cpp:31:41: required from here
C:\Users\Daniel\Documents\Arduino\libraries\LinkedList/LinkedList.h:160:9: error: cannot convert 'bool' to 'ListNode<State*>*' in return
return false;
^~~~~
exit status 1
Error compiling for board Arduino Uno.
If I try to compile
#include <StateMachine.h>
void setup() {}
void loop() {}
for Arduino Mega with v1.0.13 I get Compilation error: Error: 2 UNKNOWN: exit status 1
.
Am interested in learning about State Machines so downloaded the one produced by jrullan. Unfortunately I found it would not compile so followed the step suggested by mccartes commenting out two lines and it compiled and downloaded ok.
Issue I have is it does not output anything to the serial monitor in IDE. I have set the baud rate to 19200 in the program and on IDE but its make no difference. I am a novice so on a steep learning curve so any help greatly received.
In State.h, the following error since some Arduino IDE update:
Arduino/libraries/StateMachine/src/State.h:11:1: warning: 'typedef' was ignored in this declaration typedef struct Transition{ ^~~~~~~
I can read on Stack Overflow that:
It is a degenerate syntax that is allowed but provides no benefit. Most modern compilers can be provoked into emitting a
warning about it; by default, they may not. [...]
C Standard
In ISO/IEC 9899:1999 (that's the C standard), we find:
§6.7 Declarations
Syntax
declaration: [...]
Source: https://stackoverflow.com/a/6399998/5631432
I delete "typedef" before "struct Transition{" in State.h and there is no more warning about this.
Let me know what you think.
Btw. thank you for your library
Just tried to compile the example.ino for a WEMOS D1 mini target (ESP8266). Upfront I installed from .zip the StateMachine and the LinkedList libraries. Compile run (more precisely the linker) throws error messages below. Any help is highly appreciated.
Regs Martin
Arduino: 1.8.13 (Linux), Board: "WeMos D1 R2 & mini, 80 MHz, 921600, 4M (3M SPIFFS)"
.
.
.
Linking everything together...
/home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/xtensa-lx106-elf-gcc -g -w -Os -nostdlib -Wl,--no-check-sections -u call_user_start -u _printf_float -u _scanf_float -Wl,-static -L/home/martin/Arduino/hardware/esp8266com/esp8266/tools/sdk/lib -L/home/martin/Arduino/hardware/esp8266com/esp8266/tools/sdk/ld -L/home/martin/Arduino/hardware/esp8266com/esp8266/tools/sdk/libc/xtensa-lx106-elf/lib -Teagle.flash.4m.ld -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,register_chipv6_phy -o /tmp/arduino_build_785427/StateMachineTest.ino.elf -Wl,--start-group /tmp/arduino_build_785427/sketch/StateMachineTest.ino.cpp.o /tmp/arduino_build_785427/libraries/LinkedList-master/tests.cpp.o /tmp/arduino_build_785427/arduino.ar -lhal -lphy -lpp -lnet80211 -llwip_gcc -lwpa -lcrypto -lmain -lwps -laxtls -lespnow -lsmartconfig -lmesh -lwpa2 -lstdc++ -lm -lc -lgcc -Wl,--end-group -L/tmp/arduino_build_785427
/home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/martin/Arduino/hardware/esp8266com/esp8266/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a(lib_a-putc.o): in function _putc_r': /Users/igrokhotkov/e/newlib-xtensa/xtensa-lx106-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/putc.c:97: multiple definition of
_putc_r'; /tmp/arduino_build_785427/arduino.ar(libc_replacements.c.o):/home/martin/Arduino/hardware/esp8266com/esp8266/cores/esp8266/libc_replacements.c:95: first defined here
/home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /tmp/arduino_build_785427/StateMachineTest.ino.elf section .text' will not fit in region
iram1_0_seg'
/home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/martin/Arduino/hardware/esp8266com/esp8266/tools/sdk/lib/libstdc++.a(locale-inst.o):(.literal._ZSt9use_facetISt5ctypeIcEERKT_RKSt6locale[std::ctype const& std::use_facet<std::ctype >(std::locale const&)]+0x4): undefined reference to std::__throw_bad_cast()' /home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/martin/Arduino/hardware/esp8266com/esp8266/tools/sdk/lib/libstdc++.a(locale-inst.o): in function
std::ctype const& std::use_facet<std::ctype >(std::locale const&)':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:136: undefined reference to std::__throw_bad_cast()' /home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/martin/Arduino/hardware/esp8266com/esp8266/tools/sdk/lib/libstdc++.a(locale-inst.o): in function
std::numpunct const& std::use_facet<std::numpunct >(std::locale const&)':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:136: undefined reference to std::__throw_bad_cast()' /home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/martin/Arduino/hardware/esp8266com/esp8266/tools/sdk/lib/libstdc++.a(locale-inst.o): in function
std::num_put<char, std::ostreambuf_iterator<char, std::char_traits > > const& std::use_facet<std::num_put<char, std::ostreambuf_iterator<char, std::char_traits > > >(std::locale const&)':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:136: undefined reference to std::__throw_bad_cast()' /home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/martin/Arduino/hardware/esp8266com/esp8266/tools/sdk/lib/libstdc++.a(locale-inst.o): in function
std::num_get<char, std::istreambuf_iterator<char, std::char_traits > > const& std::use_facet<std::num_get<char, std::istreambuf_iterator<char, std::char_traits > > >(std::locale const&)':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:136: undefined reference to std::__throw_bad_cast()' /home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/martin/Arduino/hardware/esp8266com/esp8266/tools/sdk/lib/libstdc++.a(locale-inst.o):/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:136: more undefined references to
std::__throw_bad_cast()' follow
/home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/martin/Arduino/hardware/esp8266com/esp8266/tools/sdk/lib/libstdc++.a(c++locale.o):(.literal.ZNSt6locale5facet18_S_create_c_localeERPiPKcS1+0x4): undefined reference to std::__throw_runtime_error(char const*)' /home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/martin/Arduino/hardware/esp8266com/esp8266/tools/sdk/lib/libstdc++.a(c++locale.o): in function
std::locale::facet::_S_create_c_locale(int*&, char const*, int*)':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/src/c++98/c++locale.cc:218: undefined reference to std::__throw_runtime_error(char const*)' /home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/martin/Arduino/hardware/esp8266com/esp8266/tools/sdk/lib/libstdc++.a(ios-inst.o):(.literal._ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate[std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)]+0x4): undefined reference to
std::__throw_ios_failure(char const*)'
/home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/martin/Arduino/hardware/esp8266com/esp8266/tools/sdk/lib/libstdc++.a(ios-inst.o): in function std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)': /Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/basic_ios.tcc:48: undefined reference to
std::__throw_ios_failure(char const*)'
/home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/martin/Arduino/hardware/esp8266com/esp8266/tools/sdk/lib/libstdc++.a(ios-inst.o): in function std::basic_ios<wchar_t, std::char_traits<wchar_t> >::clear(std::_Ios_Iostate)': /Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/basic_ios.tcc:48: undefined reference to
std::__throw_ios_failure(char const*)'
/home/martin/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/martin/Arduino/hardware/esp8266com/esp8266/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a(lib_a-putc.o): in function `putc':
/Users/igrokhotkov/e/newlib-xtensa/xtensa-lx106-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/putc.c:122:(.text+0xc5): dangerous relocation: call0: call target out of range: _putc_r
collect2: error: ld returned 1 exit status
Bibliothek StateMachine-master in Version 1.0.11 im Ordner: /home/martin/Arduino/libraries/StateMachine-master wird verwendet
Bibliothek LinkedList-master in Version 1.3.1 im Ordner: /home/martin/Arduino/libraries/LinkedList-master wird verwendet
exit status 1
Fehler beim Kompilieren für das Board WeMos D1 R2 & mini.
I get the following errors when trying to compile the state machine example for the Arduino Portenta using the Arduino CLI:
"
arduino-cli compile ~/Arduino/libraries/StateMachine/examples/arduino_state_machine -b arduino:mbed_portenta:envie_m7 --libraries ~/Arduino/libraries/
/home/cellula/Arduino/libraries/StateMachine/src/State.cpp: In member function 'void State::addTransition(bool ()(), State)':
/home/cellula/Arduino/libraries/StateMachine/src/State.cpp:19:16: error: 'class LinkedList<Transition*>' has no member named 'add'
transitions->add(t);
^~~
/home/cellula/Arduino/libraries/StateMachine/src/State.cpp: In member function 'void State::addTransition(bool ()(), int)':
/home/cellula/Arduino/libraries/StateMachine/src/State.cpp:32:16: error: 'class LinkedList<Transition>' has no member named 'add'
transitions->add(t);
^~~
/home/cellula/Arduino/libraries/StateMachine/src/State.cpp: In member function 'int State::evalTransitions()':
/home/cellula/Arduino/libraries/StateMachine/src/State.cpp:42:19: error: 'class LinkedList<Transition*>' has no member named 'size'
if(transitions->size() == 0) return index;
^~~~
/home/cellula/Arduino/libraries/StateMachine/src/State.cpp:45:30: error: 'class LinkedList<Transition*>' has no member named 'size'
for(int i=0;isize();i++){
^~~~
/home/cellula/Arduino/libraries/StateMachine/src/State.cpp:46:27: error: 'class LinkedList<Transition*>' has no member named 'get'
result = transitions->get(i)->conditionFunction();
^~~
/home/cellula/Arduino/libraries/StateMachine/src/State.cpp:48:27: error: 'class LinkedList<Transition*>' has no member named 'get'
return transitions->get(i)->stateNumber;
^~~
/home/cellula/Arduino/libraries/StateMachine/src/State.cpp: In member function 'int State::setTransition(int, int)':
/home/cellula/Arduino/libraries/StateMachine/src/State.cpp:68:18: error: 'class LinkedList<Transition*>' has no member named 'size'
if(transitions->size() == 0) return -1;
^~~~
/home/cellula/Arduino/libraries/StateMachine/src/State.cpp:69:15: error: 'class LinkedList<Transition*>' has no member named 'get'
transitions->get(index)->stateNumber = stateNo;
^~~
/home/cellula/Arduino/libraries/StateMachine/src/StateMachine.cpp: In member function 'void StateMachine::run()':
/home/cellula/Arduino/libraries/StateMachine/src/StateMachine.cpp:20:17: error: 'class LinkedList<State*>' has no member named 'size'
if(stateList->size() == 0) return;
^~~~
/home/cellula/Arduino/libraries/StateMachine/src/StateMachine.cpp:32:25: error: 'class LinkedList<State*>' has no member named 'get'
int next = stateList->get(currentState)->execute();
^~~
/home/cellula/Arduino/libraries/StateMachine/src/StateMachine.cpp: In member function 'State* StateMachine::addState(void ()())':
/home/cellula/Arduino/libraries/StateMachine/src/StateMachine.cpp:46:14: error: 'class LinkedList<State>' has no member named 'add'
stateList->add(s);
^~~
/home/cellula/Arduino/libraries/StateMachine/src/StateMachine.cpp:47:25: error: 'class LinkedList<State*>' has no member named 'size'
s->index = stateList->size()-1;
^~~~
/home/cellula/Arduino/libraries/StateMachine/src/StateMachine.cpp: In member function 'int StateMachine::transitionTo(int)':
/home/cellula/Arduino/libraries/StateMachine/src/StateMachine.cpp:66:21: error: 'class LinkedList<State*>' has no member named 'size'
if(i < stateList->size()){
^~~~
Error during build: exit status 1
"
Arduino CLI version 0.20.2
Arduino Portenta core version 2.6.1
StateMachine library version 1.0.13
LinkedList library version 1.3.2
I tried LinkedList library version 1.2.3 and get the same errors.
I tried compiling this for the Arduino Mega and get the same errors as in this issue
The StateMachine class' executeOnce
attribute effectively handles the on-enter behaviour of a state. However, it would also be nice to have somewhere to put code that needs executing on leaving a state, regardless of the state being transitioned to next. Maybe an executeLast
attribute?
If you would like me to make a PR for this, please reply to this issue so I know whether this repo is being maintained or not.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.