def test(self): prev_value = self.ids.slider.value try: value = limit2(float(self.ids.text.text), self.ids.slider.min, self.ids.slider.max) self.ids.slider.value = value self.ids.text.text = "{:.4f}".format(value) except ValueError: #self.value = prev_value self.ids.text.text = "{:.4f}".format(prev_value)
def test(self): prev_value = self.value try: value = limit2(float(self.ids.text.text), self.ids.slider.min, self.ids.slider.max) self.value = value self.ids.text.text = str(value) except ValueError: self.value = prev_value self.ids.text.text = str(prev_value)
def add_point(self): """Adds a point to current trajectory""" dx = [50.0, 120.0] dy = [-30.0, 30.0] dt = [-20.0, 20.0] # Generate semi - random point (Previous point + dx, dy, dt) pose = self.current_trajectory.poses[len(self.current_trajectory.poses) - 1].transform(to_pose(uniform(dx[0], dx[1]), uniform(dy[0], dy[1]), uniform(dt[0], dt[1]))) pose.translation.x = limit2(pose.translation.x, 15, 614.25) pose.translation.y = limit2(pose.translation.y, -146.625, 146.625) # Add new point to trajectory self.current_trajectory.add_pose(pose) # Add new point to GUI self.screen.ids.point_list.add_widget(PointDrawer()) self.screen.ids.point_list.children[0].ids.left_container.initial_update(pose.translation.x, pose.translation.y, pose.rotation.get_degrees()) # Re-draw points to include new pose self.update_points()
def update_y(self): """Updates y""" try: value = float(self.children[1].text) value = limit2(value, -161.625 + RADIUS, 161.625 - RADIUS) self.children[1].text = "{:.3f}".format(value) MDApp.get_running_app().current_trajectory.update_pose(self.get_index(), value, "y") MDApp.get_running_app().update_points() except ValueError: self.children[1].text = self.prev_y pass self.prev_y = self.children[1].text
def test_util(self): """Tests util methods""" # Test limit2 self.assertAlmostEqual(1.0, limit2(1.0, -2.0, 4.0)) self.assertAlmostEqual(-0.0, limit2(1.0, -2.0, -0.0)) self.assertAlmostEqual(-2.0, limit2(-5.0, -2.0, -0.0)) # Test limit self.assertAlmostEqual(1.0, limit(1.0, 4.0)) self.assertAlmostEqual(4.0, limit(6.0, 4.0)) self.assertAlmostEqual(-3.0, limit(-5.0, 3.0)) # Test interpolate self.assertAlmostEqual(1.0, interpolate(.0, 4.0, .25)) self.assertAlmostEqual(1.0, interpolate(-1, 4.0, .4)) self.assertAlmostEqual(1.0, interpolate(4.0, 0.0, .75)) # Test epsilon_equals self.assertTrue(epsilon_equals(1, 1.5, .5)) self.assertTrue(epsilon_equals(2, 1.5, .5)) self.assertFalse(epsilon_equals(1, 1.5))
def update_x(self): """Updates x""" try: value = float(self.children[2].text) value = limit2(value, 0 + RADIUS, 629.25 - RADIUS) self.children[2].text = "{:.3f}".format(value) # https://stackoverflow.com/questions/32162180/how-can-i-refer-to-kivys-root-widget-from-python MDApp.get_running_app().current_trajectory.update_pose(self.get_index(), value, "x") MDApp.get_running_app().update_points() except ValueError: self.children[2].text = self.prev_x pass self.prev_x = self.children[2].text
def advance(self, additional_progress): """Returns the current sample after moving forward by additional_progress""" self.progress = limit2(additional_progress, self.start_t, self.end_t) self.current_sample = self.sample(self.progress) return self.current_sample