Skip to content

Commit

Permalink
Update integration tests for handling *NaN* inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanscherzinger committed Apr 8, 2024
1 parent db22061 commit c84c492
Showing 1 changed file with 35 additions and 37 deletions.
72 changes: 35 additions & 37 deletions cartesian_controller_tests/integration_tests/integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,46 +155,44 @@ def test_inputs_with_nans(self):
The controllers' callbacks store them even when in inactive state after startup.
We then check if every controller can be activated normally.
"""
# Target pose
target_pose = PoseStamped()
target_pose.header.frame_id = "base_link"
target_pose.pose.position.x = float("nan")
target_pose.pose.position.y = float("nan")
target_pose.pose.position.z = float("nan")
target_pose.pose.orientation.x = float("nan")
target_pose.pose.orientation.y = float("nan")
target_pose.pose.orientation.z = float("nan")
target_pose.pose.orientation.w = float("nan")
self.target_pose_pub.publish(target_pose)

# Force-torque sensor
ft_sensor_wrench = WrenchStamped()
ft_sensor_wrench.wrench.force.x = float("nan")
ft_sensor_wrench.wrench.force.y = float("nan")
ft_sensor_wrench.wrench.force.z = float("nan")
ft_sensor_wrench.wrench.torque.x = float("nan")
ft_sensor_wrench.wrench.torque.y = float("nan")
ft_sensor_wrench.wrench.torque.z = float("nan")
self.ft_sensor_wrench_pub.publish(ft_sensor_wrench)

# Target wrench
target_wrench = WrenchStamped()
target_wrench.wrench.force.x = float("nan")
target_wrench.wrench.force.y = float("nan")
target_wrench.wrench.force.z = float("nan")
target_wrench.wrench.torque.x = float("nan")
target_wrench.wrench.torque.y = float("nan")
target_wrench.wrench.torque.z = float("nan")
self.target_wrench_pub.publish(target_wrench)

time.sleep(1) # give the controllers some time to process
def publish_nan_targets():
# Target pose
target_pose = PoseStamped()
target_pose.header.frame_id = "base_link"
target_pose.pose.position.x = float('nan')
target_pose.pose.position.y = float('nan')
target_pose.pose.position.z = float('nan')
target_pose.pose.orientation.x = float('nan')
target_pose.pose.orientation.y = float('nan')
target_pose.pose.orientation.z = float('nan')
target_pose.pose.orientation.w = float('nan')
self.target_pose_pub.publish(target_pose)

# Force-torque sensor
ft_sensor_wrench = WrenchStamped()
ft_sensor_wrench.wrench.force.x = float('nan')
ft_sensor_wrench.wrench.force.y = float('nan')
ft_sensor_wrench.wrench.force.z = float('nan')
ft_sensor_wrench.wrench.torque.x = float('nan')
ft_sensor_wrench.wrench.torque.y = float('nan')
ft_sensor_wrench.wrench.torque.z = float('nan')
self.ft_sensor_wrench_pub.publish(ft_sensor_wrench)

# Target wrench
target_wrench = WrenchStamped()
target_wrench.wrench.force.x = float('nan')
target_wrench.wrench.force.y = float('nan')
target_wrench.wrench.force.z = float('nan')
target_wrench.wrench.torque.x = float('nan')
target_wrench.wrench.torque.y = float('nan')
target_wrench.wrench.torque.z = float('nan')
self.target_wrench_pub.publish(target_wrench)

for name in self.our_controllers:
self.start_controller(name)
time.sleep(3) # process some update() cycles
self.assertTrue(
self.check_state(name, "active"), f"{name} survives inputs with NaNs"
)
publish_nan_targets()
time.sleep(3) # process some update() cycles
self.assertTrue(self.check_state(name, 'active'), f"{name} survives inputs with NaNs")
self.stop_controller(name)

def check_state(self, controller, state):
Expand Down

0 comments on commit c84c492

Please sign in to comment.