Comments (9)
Thanks @ZhenshengLee for this ticket. I am not sure if the reason why your state is stuck is because of CbLaunch.
CbRosLaunch has not been extensively tested. In theory, it should not block, even if the roslaunch got stuck.
May that stuck be caused by other different client behavior?
Anyways, It would be nice to get a new example inside sm_reference_library to replicate and that specific case you have.
Now I will answer your generic questions (independently if this is related or not with the CbLaunch functioning)
1 - why this async behavior block? whe this client behavior happen?
Asynchronous client behaviors are just client behaviors that are to to run code of the onEntry function in a detached thread. That is why onEntry "finishes" very fast. However, we asume that the Asyncrhonous Client Behavior "Is Running" while that thread is alive. Something very important to know is that the state cant be left until all the client behaviors threads are finished. In order to do that, the state tries to interrupt all of unfinished ones (but that does not always work and depends on the internal implementation of the asyncrhonous function)
Then, the key question around is the following: What happens our state machine needs to move from one new state leaving the current state with some unfinished asynchronous behavior?
Short answer: If the client behavior gets stuck, the state will also do that.
Good client behavior needs to implement their own mechanisms to be interrupted in the case we are leaving the state.
We have a solution for this, but it is responsibility of the client behavior implementation to use it correctly:
/// \brief onEntry is executed in a new thread. However the current state cannot be left
/// until the onEntry thread finishes. This flag can be checked from the onEntry thread to force finishing the thread.
// All asyncrhonous client behaviors should implement the ability of interruping the onEntry thread.
// to avoid blocking the state machine.
inline bool isShutdownRequested() { return isShutdownRequested_; }
2. when this happens, how to recovery the behavior of state machine? Must I kill the node and restart the node?
I think the only solution is using asyncrhonous behaviors that are prepared to be interrupted.
3. How to avoid this client behavior blocking?
Using uninterruptible client behaviors.
from smacc2.
I think it may be related with std::future, because similar behavior/issue happens with https://github.com/robosoft-ai/SMACC2/blob/galactic/smacc2/include/smacc2/client_behaviors/cb_call_service.hpp
SMACC2/smacc2/include/smacc2/client_behaviors/cb_call_service.hpp
Lines 44 to 46 in 42177d3
SMACC2/smacc2/include/smacc2/client_bases/smacc_service_client.hpp
Lines 58 to 64 in 42177d3
sometimes the call()
function cannot return and the Cb could be stuck, thus making state machine stuck.
from smacc2.
Good client behavior needs to implement their own mechanisms to be interrupted in the case we are leaving the state.
We have a solution for this, but it is responsibility of the client behavior implementation to use it correctly:
I am having the same error even with isShutdownRequested
used the same way as you have in the reference example cb_blinking.hpp
My Entry looks like this and this->checkDistanceToTarget();
is not blocking. The state is set to continue to the next one as checkDistanceToTarget()
calls postSuccessEvent();
.
void onEntry() override {
log_info("OnEntry, Checking pos with 2hz");
rclcpp::Rate rate(2); // 2Hz
// remember to check the shutdown request, so we don't block state transitions
while (!isShutdownRequested()) {
log_info("Is shutdown requested: " + std::to_string(isShutdownRequested()));
log_info("Checking distance...");
this->checkDistanceToTarget();
rate.sleep();
}
log_info("Exited loop...");
}
My log, it will keep repeating these entries which indicates that the function this->checkDistanceToTarget();
keeps being called multiple iterations and the loop never stops. It seems like the isShutdownRequested()
never gets updated.
[navigator_node-2] [WARN] [1669644347.285719186] [navigator]: [navigator::cl_drone_interface::CbTargetPosChecker] waiting for finishing client behavior, before leaving the state. Is the client behavior stuck?
[navigator_node-2] [INFO] [1669645400.507621181] [navigator]: [CbTargetPosChecker] Is shutdown requested: 0
[navigator_node-2] [INFO] [1669644347.664684620] [navigator]: [CbTargetPosChecker] Checking distance...
[navigator_node-2] [INFO] [1669644347.664729279] [navigator]: [CbTargetPosChecker] Dist to target pos: 0.001001, Threshold: 0.1m
[navigator_node-2] [INFO] [1669644347.664740655] [navigator]: [CbTargetPosChecker] At target, returning success
[navigator_node-2] [INFO] [1669644347.664758714] [navigator]: Event smacc2::EvCbSuccess<navigator::cl_drone_interface::CbTargetPosChecker, navigator::OrDroneInterface>
[navigator_node-2] [WARN] [1669644347.664772301] [navigator]: [ISmaccStateMachine] CURRENT STATE SCOPED EVENT DISCARDED, state is exiting/transitioning smacc2::EvCbSuccess<navigator::cl_drone_interface::CbTargetPosChecker, navigator::OrDroneInterface>
Either I am missing something, or it appears that isShutdownRequested()
is not behaving as intended?
from smacc2.
@ZhenshengLee thanks for notifying that problematic use case (CbServiceCall). As I mentioned, ClientBehavior should implement the "interruption ability".
By the moment I created a new PR for galactic (and also for humble) to improve CbServiceCall and allow interruption of the wating process.
https://github.com/robosoft-ai/SMACC2/pull/375/files
from smacc2.
@Crowdedlight your code looks good to me.
When the state is leaving, it must notify all client behaviors to leave via the SmaccAsyncClientBehavior::requestForceFinish() method.
One question, what branch/commit are you using?
from smacc2.
once the PR being merged, this canbe closed.
from smacc2.
PR is merged into galactic.
Humble is in progress.
from smacc2.
CbServiceCall improvements also merged in humble #379
from smacc2.
@Crowdedlight your code looks good to me. When the state is leaving, it must notify all client behaviors to leave via the SmaccAsyncClientBehavior::requestForceFinish() method.
One question, what branch/commit are you using?
Sorry for the late reply @pabloinigoblasco, vacation and sickness kept me away for a while.
Is SmaccAsyncClientBehavior::requestForceFinish()
a method I have to explicitly call when I leave the state or is it called automatically by smacc when a state change is triggered?
We are using branch foxy
atm, but planning to upgrade to humble
within a few months.
from smacc2.
Related Issues (20)
- How to use Action events HOT 5
- warning format occorred. HOT 2
- Look at getting Nvidia GPU to run docker image
- Investigate running UE5 with AMD and Fedora
- Set up ROS2 on Fedora
- feature/sm_dancebot_ue ./run_docker_container_editor.sh doesnt work
- feature/sm_dancebot_ue ./run_editor_smacc.sh-readme
- Update from 0.4.0 to 2.3.18 on 22.04 Humble not transitioning to next inner state HOT 19
- Confusion about rationale behind orthogonal implementation
- Migrate to modern Gazebo HOT 1
- Nav2z client's waypoint Navigator sends goals in odom frame. HOT 2
- Adding manually compiled SMACC2 packages files to /opt/foxy folder HOT 2
- Fastbin Misalignment - Ubuntu 22.04 - Ros Humble HOT 1
- Error!! when build package HOT 4
- error during installation SMACC2 for rolling HOT 2
- SmaccAsyncClientBehavior onExit() freezes when cancelGoal() is called on the attached action client HOT 9
- [Question] Is there a way to access the event from a state that caused the transition to the current state? HOT 2
- Need http client behaviors moved to the Client Behavior Library
- Unit and Integration Testing in SMACC2
- How to Configure Client Behaviors to Run Sequentially? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from smacc2.