Commit a13f6d14 authored by JasonChmn's avatar JasonChmn

Edit bezier and bezier_t for bezier3 and bezier3_t, add comments in test.py

parent 9ae40c19
......@@ -242,7 +242,7 @@ BOOST_PYTHON_MODULE(curves)
/** BEGIN bezier curve**/
class_<bezier3_t>
("bezier", no_init)
("bezier3", no_init)
.def("__init__", make_constructor(&wrapBezierConstructor))
.def("__init__", make_constructor(&wrapBezierConstructorBounds))
.def("__init__", make_constructor(&wrapBezierConstructorConstraints))
......
......@@ -6,7 +6,7 @@ from numpy import matrix
from numpy.linalg import norm
from numpy.testing import assert_allclose
from curves import bezier, bezier6, curve_constraints, exact_cubic, from_bezier, polynom, spline_deriv_constraint
from curves import bezier3, bezier6, curve_constraints, exact_cubic, from_bezier, polynom, spline_deriv_constraint
class TestSpline(unittest.TestCase):
......@@ -15,10 +15,17 @@ class TestSpline(unittest.TestCase):
waypoints6 = matrix([[1., 2., 3., 7., 5., 5.], [4., 5., 6., 4., 5., 6.]]).T
time_waypoints = matrix([0., 1.]).T
# testing bezier curve
a = bezier6(waypoints6)
a = bezier(waypoints, 3.)
# Test : Bezier3/Bezier6, polynom, exact_cubic, curve_constraints, spline_deriv_constraints, bernstein
# Done : Bezier3/Bezier6, polynom, exact_cubic, curve_constraints, spline_deriv_constraints
# To do ? Bernstein
# TESTING BEZIER CURVE
# - Functions : constructor, min, max, derivate,compute_derivate, compute_primitive
# - Variables : degree, nbWayPoints
# Create bezier6 and bezier3
a = bezier6(waypoints6)
a = bezier3(waypoints, 3.)
# Test : Degree, min, max, derivate
self.assertEqual(a.degree, a.nbWaypoints - 1)
a.min()
a.max()
......@@ -26,26 +33,25 @@ class TestSpline(unittest.TestCase):
assert_allclose(a.derivate(0.4, 0), a(0.4))
a.derivate(0.4, 2)
a = a.compute_derivate(100)
prim = a.compute_primitive(1)
# Check primitive and derivate - order 1
for i in range(10):
t = float(i) / 10.
assert_allclose(a(t), prim.derivate(t, 1))
assert_allclose(prim(0), matrix([0., 0., 0.]).T)
# Check primitive and derivate - order 2
prim = a.compute_primitive(2)
for i in range(10):
t = float(i) / 10.
assert_allclose(a(t), prim.derivate(t, 2), atol=1e-20)
assert_allclose(prim(0), matrix([0., 0., 0.]).T)
# Create new bezier3 curve
waypoints = matrix([[1., 2., 3.], [4., 5., 6.], [4., 5., 6.], [4., 5., 6.], [4., 5., 6.]]).T
a0 = bezier(waypoints)
a1 = bezier(waypoints, 3.)
a0 = bezier3(waypoints)
a1 = bezier3(waypoints, 3.)
prim0 = a0.compute_primitive(1)
prim1 = a1.compute_primitive(1)
# Check change in argument time_t of bezier3
for i in range(10):
t = float(i) / 10.
assert_allclose(a0(t), a1(3 * t))
......@@ -55,20 +61,20 @@ class TestSpline(unittest.TestCase):
assert_allclose(prim(0), matrix([0., 0., 0.]).T)
with self.assertRaises(AssertionError):
assert_allclose(prim(0), matrix([0., 0., 0.]))
# testing bezier with constraints
c = curve_constraints()
c.init_vel = matrix([0., 1., 1.]).T
c.end_vel = matrix([0., 1., 1.]).T
c.init_acc = matrix([0., 1., -1.]).T
c.end_acc = matrix([0., 100., 1.]).T
#Check derivate with constraints
waypoints = matrix([[1., 2., 3.], [4., 5., 6.]]).T
a = bezier(waypoints, c)
a = bezier3(waypoints, c)
assert_allclose(a.derivate(0, 1), c.init_vel)
assert_allclose(a.derivate(1, 2), c.end_acc)
# testing polynom function
# TESTING POLYNOM FUNCTION
# - Functions : constructor, min, max, derivate
a = polynom(waypoints)
a = polynom(waypoints, -1., 3.)
a.min()
......@@ -77,7 +83,8 @@ class TestSpline(unittest.TestCase):
assert_allclose(a.derivate(0.4, 0), a(0.4))
a.derivate(0.4, 2)
# testing exact_cubic function
# TESTING EXACT_CUBIC FUNCTION
# - Functions : constructor, min, max, derivate
a = exact_cubic(waypoints, time_waypoints)
a.min()
a.max()
......@@ -85,24 +92,22 @@ class TestSpline(unittest.TestCase):
assert_allclose(a.derivate(0.4, 0), a(0.4))
a.derivate(0.4, 2)
# testing spline_deriv_constraints
# TESTING SPLINE_DERIV_CONSTRAINTS
# - Functions : constructor, min, max, derivate
c = curve_constraints()
c.init_vel
c.end_vel
c.init_acc
c.end_acc
c.init_vel = matrix([0., 1., 1.]).T
c.end_vel = matrix([0., 1., 1.]).T
c.init_acc = matrix([0., 1., 1.]).T
c.end_acc = matrix([0., 1., 1.]).T
a = spline_deriv_constraint(waypoints, time_waypoints)
a = spline_deriv_constraint(waypoints, time_waypoints, c)
# converting bezier to polynom
a = bezier(waypoints)
# CONVERTING BEZIER TO POLYNOM
a = bezier3(waypoints)
a_pol = from_bezier(a)
assert_allclose(a(0.3), a_pol(0.3))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment