Skip to content

Interface misuse checks - #231

Closed
maltehue wants to merge 9 commits into
semantic_world_integrationfrom
interface-misuse-checks
Closed

Interface misuse checks#231
maltehue wants to merge 9 commits into
semantic_world_integrationfrom
interface-misuse-checks

Conversation

@maltehue

Copy link
Copy Markdown
Contributor

PR for the todo card: Implement interface misuse checks#201
One commit for each of the tasks

  • Goals cannot have EndMotion
  • MotionStatechart.compile() raises exception if we have constraints but not qp controller config as param
  • Nodes cannot have themselves as start_condition
  • Assigning start etc conditions check if all variables are observation variables
  • Nodes cannot be added to multiple Goals/statecharts

regarding the MotionStatechart.compile() issue i added two tests test_compile_without_qp_controller_when_no_constraints and test_compile_raises_when_constraints_present_but_no_qp_config that in my opinion test the desired behavior that was already present. Or did that issue mean something else?

@maltehue
maltehue requested a review from ichumuh November 21, 2025 13:53
Comment thread giskardpy/motion_statechart/graph_node.py Outdated
Comment thread giskardpy/motion_statechart/graph_node.py Outdated
Comment thread giskardpy/motion_statechart/graph_node.py Outdated
Comment thread giskardpy/motion_statechart/graph_node.py Outdated
if (
node._motion_statechart is not None
and node._motion_statechart is not self.motion_statechart
):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of these errors are special cases of this if. I think the code gets cleaner if you first check if the backreference is None and if yes, you add the node.
if not none, but the backreference is the same as the goal, you do nothing.
then you check your special cases and since you know the node already belongs to a statechart, you don't need many of the is not None checks anymore. you might even be able to use match/case

goal = TestGoal()
msc.add_node(goal)
with pytest.raises(InvalidSelfReferenceInStartCondition):
goal.start_condition = goal.observation_variable > 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests that the other conditions are fine

n3 = ConstTrueNode()
msc.add_node(n1)
msc.add_node(n2)
msc.add_node(n3)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use add_nodes

assert str(err.variable_name) == str(n1.life_cycle_variable.name)


def test_end_condition_requires_observation_variables():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about reset?

n = ConstTrueNode()

msc.add_node(g1)
msc.add_node(g2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msc.add_nodes([
    g1 := TestGoal(),
    g2:= TestGoal(),
])

# Conflicts:
#	giskardpy/motion_statechart/exceptions.py
#	giskardpy/motion_statechart/graph_node.py
#	giskardpy/motion_statechart/motion_statechart.py
#	test/test_motion_statechart/test_motion_statechart.py
@ichumuh ichumuh closed this Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants