Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arithmetic operations on Post Conditions (Success | Failure) | Not working #539

Closed
ephson24 opened this issue Mar 31, 2023 · 3 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@ephson24
Copy link

ephson24 commented Mar 31, 2023

Hi Davide,

I find trying to set arithmetic operations using _onSuccess and _onFailure does not work.
However using _onpost works as expected.

E.g XML (not working)

<Sequence>
              <TestCanDo state="false"
                         _onFailure="loop_count  += 1"/>
              <SendWarning deviceStatus="{isLowBattery}"
                           deviceType="BATT"/>
</Sequence>

But this works:

<Sequence>
              <TestCanDo state="false"
                         _onpost="loop_count  += 1"/>
              <SendWarning deviceStatus="{isLowBattery}"
                           deviceType="BATT"/>
</Sequence>

C++ code

BT::NodeStatus testCanDo(BT::TreeNode &self)
{
  bool state;
  if(auto res = self.getInput<bool>("state"))
    state = res.value();
  else
    throw std::runtime_error(res.error());
  return (state)? BT::NodeStatus::SUCCESS : BT::NodeStatus::FAILURE;
}

Could this be a bug of sorts?

PS: TestCanDo is a simple condition node

@ephson24
Copy link
Author

ephson24 commented Apr 3, 2023

Solved by removing the spacing between the variable and arithmetic operations
Solution

<Sequence>
              <TestCanDo state="false"
                         _onFailure="loop_count+=1"/>
              <SendWarning deviceStatus="{isLowBattery}"
                           deviceType="BATT"/>
</Sequence>

@ephson24 ephson24 closed this as completed Apr 3, 2023
@facontidavide
Copy link
Collaborator

That is still a bug, even with spacing, it should work.

@facontidavide facontidavide reopened this Apr 3, 2023
@facontidavide facontidavide self-assigned this Apr 3, 2023
@facontidavide facontidavide added the bug Something isn't working label Apr 3, 2023
facontidavide added a commit that referenced this issue May 10, 2023
@facontidavide
Copy link
Collaborator

I added a specific unit test for your case, but can not reproduce the error:

https://github.com/BehaviorTree/BehaviorTree.CPP/blob/master/tests/gtest_postconditions.cpp#L41-L62

Closing. If youcan create a variant of the unit test that show the issue, let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants