From 4e8d89511c91451905ff97d1b6ea73f370e0ac61 Mon Sep 17 00:00:00 2001 From: josep Date: Wed, 18 Dec 2024 20:11:26 +0900 Subject: [PATCH] =?UTF-8?q?imu=20roll=20pitch=20yaw=20=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=EC=9D=84=20x,y,z=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/basic_usage_examples/imu_example.py | 6 ++--- examples/creation_examples/brush.py | 4 +-- examples/creation_examples/dodge.py | 6 ++--- modi_plus/module/input_module/imu.py | 26 ++++++++++---------- modi_plus/module/setup_module/network.py | 18 +++++++------- modi_plus/util/usage_util.py | 6 ++--- tests/module/input_module/test_imu.py | 20 +++++++-------- tests/module/setup_module/test_network.py | 18 +++++++------- 8 files changed, 52 insertions(+), 52 deletions(-) diff --git a/examples/basic_usage_examples/imu_example.py b/examples/basic_usage_examples/imu_example.py index dd4282f..24d8af8 100644 --- a/examples/basic_usage_examples/imu_example.py +++ b/examples/basic_usage_examples/imu_example.py @@ -11,9 +11,9 @@ imu = bundle.imus[0] while True: - print(f"Pitch: {imu.pitch:<10}" - f"Roll: {imu.roll:<10}" - f"Yaw: {imu.yaw:<10}" + print(f"Angle_y: {imu.angle_y:<10}" + f"Angle_x: {imu.angle_x:<10}" + f"Angle_z: {imu.angle_z:<10}" f"Vel x: {imu.angular_vel_x:<10}" f"Vel y: {imu.angular_vel_y:<10}" f"Vel z: {imu.angular_vel_z:<10}" diff --git a/examples/creation_examples/brush.py b/examples/creation_examples/brush.py index a525f72..cc2aa3b 100644 --- a/examples/creation_examples/brush.py +++ b/examples/creation_examples/brush.py @@ -15,8 +15,8 @@ def setup(self): def update(self): h, w = self.height // 2, self.width // 2 - self.cursor.y = h - h * sin(radians(-self.imu.roll)) - self.cursor.x = w - w * sin(radians(-self.imu.pitch)) + self.cursor.y = h - h * sin(radians(-self.imu.angle_x)) + self.cursor.x = w - w * sin(radians(-self.imu.angle_y)) if self.button.pressed: self.add_object(Brush((self.cursor.x, self.cursor.y), "x")) diff --git a/examples/creation_examples/dodge.py b/examples/creation_examples/dodge.py index 0c0823e..e283d2b 100644 --- a/examples/creation_examples/dodge.py +++ b/examples/creation_examples/dodge.py @@ -34,10 +34,10 @@ def setup(self): self.fire.x, self.fire.y = 25, 20 def update(self): - pitch = -self.imu.pitch - if pitch < -5 and self.player.x < 48: + angle_y = -self.imu.angle_y + if angle_y < -5 and self.player.x < 48: self.player.x += 30 * self.delta_time - elif pitch > 5 and self.player.x > 0: + elif angle_y > 5 and self.player.x > 0: self.player.x -= 30 * self.delta_time self.fire.y -= 15 * self.delta_time if self.fire.y < 0: diff --git a/modi_plus/module/input_module/imu.py b/modi_plus/module/input_module/imu.py index db9821f..b5a5dbe 100644 --- a/modi_plus/module/input_module/imu.py +++ b/modi_plus/module/input_module/imu.py @@ -24,10 +24,10 @@ class Imu(InputModule): PROPERTY_OFFSET_VIBRATION = 0 @property - def roll(self) -> float: - """Returns the roll angle of the imu + def angle_x(self) -> float: + """Returns the angle_x angle of the imu - :return: The imu's roll angle. + :return: The imu's angle_x angle. :rtype: float """ @@ -37,10 +37,10 @@ def roll(self) -> float: return data @property - def pitch(self) -> float: - """Returns the pitch angle of the imu + def angle_y(self) -> float: + """Returns the angle_y angle of the imu - :return: The imu's pitch angle. + :return: The imu's angle_y angle. :rtype: float """ @@ -50,10 +50,10 @@ def pitch(self) -> float: return data @property - def yaw(self) -> float: - """Returns the yaw angle of the imu + def angle_z(self) -> float: + """Returns the angle_zle_z angle of the imu - :return: The imu's yaw angle. + :return: The imu's angle_z angle. :rtype: float """ @@ -64,17 +64,17 @@ def yaw(self) -> float: @property def angle(self) -> Tuple[float, float, float]: - """Returns the roll, pitch and yaw angle of the imu + """Returns the angle_x, angle_y and angle_z angle of the imu - :return: The imu's angles of roll, pitch and yaw. + :return: The imu's angles of angle_x, angle_y and angle_z. :rtype: tuple """ - return self.roll, self.pitch, self.yaw + return self.angle_x, self.angle_y_y, self.angle_z @property def angular_vel_x(self) -> float: - """Returns the roll angle of the imu + """Returns the angle_x angle of the imu :return: The imu's angular velocity the about x-axis. :rtype: float diff --git a/modi_plus/module/setup_module/network.py b/modi_plus/module/setup_module/network.py index bf3bdc5..9a17cfc 100644 --- a/modi_plus/module/setup_module/network.py +++ b/modi_plus/module/setup_module/network.py @@ -245,10 +245,10 @@ def time_up(self) -> bool: @property @check_connection - def imu_roll(self) -> int: - """Returns the roll angle of the MODI Play imu + def imu_angle_x(self) -> int: + """Returns the angle_x angle of the MODI Play imu - :return: Roll angle. + :return: Angle_x angle. :rtype: int """ @@ -261,10 +261,10 @@ def imu_roll(self) -> int: @property @check_connection - def imu_pitch(self) -> int: - """Returns the pitch angle of the MODI Play imu + def imu_angle_y(self) -> int: + """Returns the angle_y angle of the MODI Play imu - :return: Pitch angle. + :return: Angle_y angle. :rtype: int """ @@ -277,10 +277,10 @@ def imu_pitch(self) -> int: @property @check_connection - def imu_yaw(self) -> int: - """Returns the yaw angle of the MODI Play imu + def imu_angle_zle_z(self) -> int: + """Returns the angle_z angle of the MODI Play imu - :return: Yaw angle. + :return: Angle_z angle. :rtype: int """ diff --git a/modi_plus/util/usage_util.py b/modi_plus/util/usage_util.py index f3b21a2..fa8b347 100644 --- a/modi_plus/util/usage_util.py +++ b/modi_plus/util/usage_util.py @@ -154,9 +154,9 @@ def run_imu_manual(self): imu = bundle.imus[0] while True: - print(f"Gyro ({imu.id}) roll: {imu.roll}") - print(f"Gyro ({imu.id}) pitch: {imu.pitch}") - print(f"Gyro ({imu.id}) yaw: {imu.yaw}") + print(f"Gyro ({imu.id}) angle_x: {imu.angle_x}") + print(f"Gyro ({imu.id}) angle_y: {imu.angle_y}") + print(f"Gyro ({imu.id}) angle_z: {imu.angle_z}") print(f"Gyro ({imu.id}) angular_vel_x: {imu.angular_vel_x}") print(f"Gyro ({imu.id}) angular_vel_y: {imu.angular_vel_y}") print(f"Gyro ({imu.id}) angular_vel_z: {imu.angular_vel_z}") diff --git a/tests/module/input_module/test_imu.py b/tests/module/input_module/test_imu.py index 9998c2e..1d23bfd 100644 --- a/tests/module/input_module/test_imu.py +++ b/tests/module/input_module/test_imu.py @@ -20,30 +20,30 @@ def tearDown(self): del self.imu - def test_get_roll(self): - """Test get_roll method.""" + def test_get_angle_x(self): + """Test get_angle_x method.""" - _ = self.imu.roll + _ = self.imu.angle_x self.assertEqual( self.connection.send_list[0], parse_get_property_message(-1, Imu.PROPERTY_ANGLE_STATE, self.imu.prop_samp_freq) ) self.assertEqual(_, 0.0) - def test_get_pitch(self): - """Test get_pitch method.""" + def test_get_angle_y(self): + """Test get_angle_y method.""" - _ = self.imu.pitch + _ = self.imu.angle_y self.assertEqual( self.connection.send_list[0], parse_get_property_message(-1, Imu.PROPERTY_ANGLE_STATE, self.imu.prop_samp_freq) ) self.assertEqual(_, 0.0) - def test_get_yaw(self): - """Test get_yaw method.""" + def test_get_angle_z(self): + """Test get_angle_z method.""" - _ = self.imu.yaw + _ = self.imu.angle_z self.assertEqual( self.connection.send_list[0], parse_get_property_message(-1, Imu.PROPERTY_ANGLE_STATE, self.imu.prop_samp_freq) @@ -121,7 +121,7 @@ def test_get_vibration(self): self.assertEqual(_, 0.0) def test_get_angle(self): - """Test get_yaw method.""" + """Test get_angle_z method.""" _ = self.imu.angle self.assertEqual( diff --git a/tests/module/setup_module/test_network.py b/tests/module/setup_module/test_network.py index 7a7f7ca..aa7abc3 100644 --- a/tests/module/setup_module/test_network.py +++ b/tests/module/setup_module/test_network.py @@ -110,30 +110,30 @@ def test_time_up(self): ) self.assertEqual(_, False) - def test_imu_roll(self): - """Test imu_roll method.""" + def test_imu_angle_x(self): + """Test imu_angle_x method.""" - _ = self.network.imu_roll + _ = self.network.imu_angle_x self.assertEqual( self.connection.send_list[0], parse_get_property_message(-1, Network.PROPERTY_NETWORK_IMU, self.network.prop_samp_freq) ) self.assertEqual(_, 0) - def test_imu_pitch(self): - """Test imu_pitch method.""" + def test_imu_angle_y(self): + """Test imu_angle_y method.""" - _ = self.network.imu_pitch + _ = self.network.imu_angle_y self.assertEqual( self.connection.send_list[0], parse_get_property_message(-1, Network.PROPERTY_NETWORK_IMU, self.network.prop_samp_freq) ) self.assertEqual(_, 0) - def test_imu_yaw(self): - """Test imu_yaw method.""" + def test_imu_angle_z(self): + """Test imu_angle_z method.""" - _ = self.network.imu_yaw + _ = self.network.imu_angle_z self.assertEqual( self.connection.send_list[0], parse_get_property_message(-1, Network.PROPERTY_NETWORK_IMU, self.network.prop_samp_freq)