Skip to content

Commit

Permalink
add test for different baud rates
Browse files Browse the repository at this point in the history
  • Loading branch information
yconst committed Apr 21, 2024
1 parent f555ea2 commit f464ddb
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions studio/Python/tests/test_as5047.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,59 @@ def test_b_position_control_following_sensor_change(self):
time.sleep(0.2)


def test_c_position_control_change_baud_rates(self):
"""
Test position control with external sensor and
different baud rates.
"""
self.check_state(0)
self.tm.erase_config()
time.sleep(0.2)

self.configure_sensors(self.tm.sensors.setup.external_spi.type.AS5047)
self.select_sensors(self.tm.sensors.select.position_sensor.connection.ONBOARD, self.tm.sensors.select.position_sensor.connection.EXTERNAL_SPI)

self.tm.motor.I_cal = 0.8

self.try_calibrate()

self.tm.controller.position.p_gain = 9
self.tm.controller.velocity.p_gain = 2e-5
self.tm.controller.velocity.i_gain = 0

self.tm.controller.position_mode()
self.check_state(2)

for _ in range(10):
new_pos = random.uniform(-20000, 20000)
self.tm.controller.position.setpoint = new_pos * tick
time.sleep(tsleep)
self.assertAlmostEqual(
self.tm.sensors.user_frame.position_estimate,
self.tm.controller.position.setpoint,
delta=2000 * tick,
)

self.tm.controller.idle()

self.tm.sensors.setup.external_spi.rate = "1_5Mbps"
time.sleep(0.1)

self.tm.controller.position_mode()
self.check_state(2)

for _ in range(10):
new_pos = random.uniform(-20000, 20000)
self.tm.controller.position.setpoint = new_pos * tick
time.sleep(tsleep)
self.assertAlmostEqual(
self.tm.sensors.user_frame.position_estimate,
self.tm.controller.position.setpoint,
delta=2000 * tick,
)

self.tm.controller.idle()


if __name__ == "__main__":
unittest.main()

0 comments on commit f464ddb

Please sign in to comment.