Skip to content

Commit 2b3ca35

Browse files
authored
Merge pull request #151 from cogip/150-avoidance-robot-in-obstacle-goes-outside-the-table
cpp: libraries: fix ObstacleCircle nearest_point() method
2 parents 057c58b + b1da20d commit 2b3ca35

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ ENV UV_PYTHON_INSTALL_DIR=/opt/python
1919
# Required because mcu-firmware is not compatible with uv
2020
ENV PATH="/src/.venv/bin:${PATH}"
2121

22+
# Set frozen uv.lock globally
23+
ENV UV_FROZEN=1
24+
2225
# Pre-install some Python requirements for COGIP tools
2326
RUN --mount=type=bind,source=uv.lock,target=uv.lock \
2427
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
2528
--mount=type=bind,source=.python-version,target=.python-version \
26-
uv sync --no-install-project --frozen
29+
uv sync --no-install-project
2730

2831
FROM uv_base AS cogip-console
2932

@@ -59,7 +62,7 @@ RUN group_exists=$(getent group ${GID} || true) && echo $group_exists \
5962

6063
ADD .python-version uv.lock pyproject.toml CMakeLists.txt LICENSE /src/
6164
ADD cogip /src/cogip
62-
RUN uv sync --frozen
65+
RUN uv sync
6366

6467
CMD ["sleep", "infinity"]
6568

cogip/cpp/libraries/avoidance/Avoidance.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ bool Avoidance::avoidance(const models::Coords& start,
5858
}
5959
if (current_obstacle.is_point_inside(start_pose_)) {
6060
start_pose_ = current_obstacle.nearest_point(start_pose_);
61+
logger_.debug() << "start pose inside obstacle, updated: " << start_pose_ << std::endl;
6162
}
6263
}
6364

cogip/cpp/libraries/obstacles/ObstacleCircle.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,26 @@ bool ObstacleCircle::is_segment_crossing(const models::Coords& a, const models::
8383

8484
models::Coords ObstacleCircle::nearest_point(const models::Coords& p)
8585
{
86+
// Vector from the circle center to the given point
8687
models::Coords vect(p.x() - data_->center.x, p.y() - data_->center.y);
8788
double vect_norm = std::hypot(vect.x(), vect.y());
8889

89-
double scale = (data_->radius * (1 + data_->bounding_box_margin)) / vect_norm;
90+
// Effective radius including the bounding box margin
91+
double effective_radius = data_->radius + data_->bounding_box_margin;
9092

93+
// Special case: if the point is exactly at the center, return a point on the circle
94+
// This case should never
95+
if (vect_norm == 0) {
96+
return models::Coords(
97+
data_->center.x + effective_radius,
98+
data_->center.y
99+
);
100+
}
101+
102+
// Scale the vector to project the point onto the circle perimeter
103+
double scale = effective_radius / vect_norm;
104+
105+
// Return the projected point on the circle
91106
return models::Coords(
92107
data_->center.x + vect.x() * scale,
93108
data_->center.y + vect.y() * scale

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ x-robot: &robot
138138
- -x
139139
- -c
140140
- |
141-
uv sync --frozen --reinstall-package cogip-tools -C build-dir=/src/build/$${ROBOT_ID}
141+
uv sync --reinstall-package cogip-tools -C build-dir=/src/build/$${ROBOT_ID}
142142
gosu $${UID}:$${GID} uv run cogip-server &
143143
wait-for-it -t 0 localhost:809$${ROBOT_ID}
144144
gosu $${UID}:$${GID} uv run cogip-planner &
@@ -187,7 +187,7 @@ x-pami: &pami
187187
- -x
188188
- -c
189189
- |
190-
uv sync --frozen --reinstall-package cogip-tools -C build-dir=/src/build/$${ROBOT_ID}
190+
uv sync --reinstall-package cogip-tools -C build-dir=/src/build/$${ROBOT_ID}
191191
gosu $${UID}:$${GID} uv run cogip-server &
192192
wait-for-it -t 0 localhost:809$${ROBOT_ID}
193193
gosu $${UID}:$${GID} uv run cogip-planner &

0 commit comments

Comments
 (0)