Skip to content

Commit

Permalink
Fixes to inability to control the area radius of 3-RPR config
Browse files Browse the repository at this point in the history
  • Loading branch information
schukark committed Apr 23, 2024
1 parent ddf0e42 commit f6fc7d7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
57 changes: 45 additions & 12 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,50 @@
import intervalpy as ival
import numpy as np

# Choose solver
solver = KrawczykSolver("2-RPR")
# Choose drawer and its parameters (depend on the configuration)
drawer = AreaCalculator("2-RPR", [3, 15, 8])
# Choose grid
grid = AreaCalculator.make_grid2d(left_bottom=(-20, -20), right_top=(20, 20), N=128)
config = "3-RPR"

# Choose lengths of rods in the 2-RPR configuration
x_num = np.array([ival.Interval([3, 15])] * 2)
# Solve the area
inside, border = solver.solve(SymbolicEquationSolver("2-RPR", [8]), grid, x_num)
if config == "2-RPR":
# Choose solver
solver = KrawczykSolver("2-RPR")
# Choose drawer and its parameters (depend on the configuration)
drawer = AreaCalculator("2-RPR", [3, 15, 8])
# Choose grid
grid = AreaCalculator.make_grid2d(left_bottom=(-20, -20), right_top=(20, 20), N=128)

# Plot the computed area
drawer.uni_plotter(inside, border, size=2, ini_box=[[-20, 20]] * 2, title="Krawczyk")
# Choose lengths of rods in the 2-RPR configuration
x_num = np.array([ival.Interval([3, 15])] * 2)
# Solve the area
inside, border = solver.solve(SymbolicEquationSolver("2-RPR", [8]), grid, x_num)

# Plot the computed area
drawer.uni_plotter(inside, border, size=2, ini_box=[[-20, 20]] * 2, title="Krawczyk")
elif config == "3-RPR":
# Choose solver
solver = KrawczykSolver("3-RPR")

# Choose parameters (this code just rotates the circles around the point 150 degrees)
import math
phi = math.radians(150)
x_a = [-15, 15, 0]
y_a = [-5 * np.sqrt(3), -5 * np.sqrt(3), 10 * np.sqrt(3)]
x_b = [-5, 5, 0]
y_b = [-5 * np.sqrt(3) / 3, -5 * np.sqrt(3) / 3, 10 * np.sqrt(3) / 3]
x_c = np.zeros(3)
y_c = np.zeros(3)

for i in range(3):
x_c[i] = x_a[i] - x_b[i] * np.cos(phi) + y_b[i] * np.sin(phi)
y_c[i] = y_a[i] - x_b[i] * np.sin(phi) - y_b[i] * np.cos(phi)

# Choose drawer
drawer = AreaCalculator("3-RPR", [x_c, y_c, 12, 27])
# Choose grid
grid = AreaCalculator.make_grid2d(left_bottom=(-20, -20), right_top=(20, 20), N=128)

# Choose lengths of rods in the 2-RPR configuration
x_num = np.array([ival.Interval([12, 27])] * 3)
# Solve the area
inside, border = solver.solve(SymbolicEquationSolver("3-RPR", [x_c, y_c]), grid, x_num)

# Plot the computed area
drawer.uni_plotter(inside, border, size=2, ini_box=[[-20, 20]] * 2, title="Krawczyk")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "intervalpylib"
version = "0.1.0"
version = "0.1.2"
authors = [{ name = "Schukark", email = "schukark2004@gmail.com" }]
description = "An interval solver for robots' workspace area"
readme = "README.md"
Expand Down
8 changes: 5 additions & 3 deletions src/intervalpylib/AreaCalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,19 @@ def make_boxes_list(grid: List[float], dim: int, uniform=True) -> List[tuple]:
grid_n_size = list(it.product(*grid_variants))
return grid_n_size

def __plot_area_3RPR(self, ax: plt.axes, x_c: List[float], y_c: List[float]):
def __plot_area_3RPR(self, ax: plt.axes, x_c: List[float], y_c: List[float], r_0: float, r_1: float):
"""private function to plot the workspace area of the 3-RPR robot
Args:
ax (plt.ax): the axes where to plot the area
x_c (List): the x-coordinates of the 3 circles' centers
y_c (List): the y-coordinates of the 3 circles' centers
r_0 (float): the radius of the inner circle
r_1 (float): the radius of the outer circle
"""
for i in range(3):
circle = plt.Circle((x_c[i], y_c[i]), radius=12, fc='y', fill=False)
circle1 = plt.Circle((x_c[i], y_c[i]), radius=27, fc='y', fill=False)
circle = plt.Circle((x_c[i], y_c[i]), radius=r_0, fc='y', fill=False)
circle1 = plt.Circle((x_c[i], y_c[i]), radius=r_1, fc='y', fill=False)
ax.add_patch(circle)
ax.add_patch(circle1)
ax.grid()
Expand Down

0 comments on commit f6fc7d7

Please sign in to comment.