def set_units(self, distance_units=None, speed_units=None, acceleration_units=None): """ Sets the units this instance will use. These units are used in with settings and the data returned. By default SI units (m and m/s) are used. It is a good idea to set the units before any other commands are sent if using non-default units. :param distance_units: The distance units to use: "mm", "cm", "m", "km", "in", "ft", "mi" :type distance_units: str :param speed_units: The speed units to use: "mm/s", "cm/s", "m/s", "km/h", "in/s", "ft/s", "mi/h" :type speed_units: str :param acceleration_units: The acceleration units to use: "mm/s^2", "m/s^2", "in/s^2", "ft/s^2" :type acceleration_units: str """ try: # Performing a units conversion will throw an exception if the units are not valid if distance_units is not None: units.convert_distance_to_si(distance_units, 1) self.distance_units = distance_units if speed_units is not None: units.convert_speed_to_si(speed_units, 1) self.speed_units = speed_units if acceleration_units is not None: units.convert_acceleration_to_si(acceleration_units, 1) self.acceleration_units = acceleration_units except ValueError as err: raise ValueError(err)
def test_convert_from_meters_per_second_to_meters_per_second(self): # Test the identity conversion converted = units.convert_speed_to_si('m/s', 1.001) self.assertEqual(1.001, converted)
def test_convert_from_mi_per_hour_to_meters_per_second(self): # Test conversions of speeds to SI units converted = units.convert_speed_to_si('mi/h', 14) self.assertEqual(6.258, converted)
def test_convert_from_ft_per_second_to_meters_per_second(self): # Test conversions of speeds to SI units converted = units.convert_speed_to_si('ft/s', 23) self.assertEqual(7.01, converted)
def test_convert_from_km_per_hour_to_meters_per_second(self): # Test conversions of speeds to SI units converted = units.convert_speed_to_si('km/h', 13) self.assertEqual(3.611, converted)
def test_convert_from_mm_per_second_to_meters_per_second(self): # Test conversions of speeds to SI units converted = units.convert_speed_to_si('mm/s', 11) self.assertEqual(0.011, converted)