Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback #1

Open
wants to merge 36 commits into
base: feedback
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9e67c1e
Setting up GitHub Classroom Feedback
github-classroom[bot] Feb 2, 2022
9071c63
pkg created, program init
lu164 Feb 6, 2022
59866aa
Extraction of the minimun laser values in 3 points with an interval
Feb 6, 2022
6674f5a
Laser lectures vector
Feb 8, 2022
cef2e1c
method lock for wall
bb6698 Feb 8, 2022
63459f2
Merge pull request #2 from Docencia-fmrico/LookForWall
angelobarra Feb 8, 2022
44a9f51
method follow wall
lu164 Feb 8, 2022
dbd0799
Merge branch 'laserProcessing' into followTheWall
angelobarra Feb 8, 2022
42fcb30
Merge pull request #3 from Docencia-fmrico/followTheWall
angelobarra Feb 8, 2022
f8096eb
Plan for diagonal lectures
Feb 8, 2022
01f2cce
The robots follows the wall correctly
Feb 9, 2022
9b75db5
Structure package,error dependencies
bb6698 Feb 9, 2022
d82f8a0
Setting CI/CD
fmrico Feb 10, 2022
15d7598
Merge pull request #4 from Docencia-fmrico/set_ci_cd
fmrico Feb 10, 2022
c6503ad
CMakelist.txt solved, comments deleted
bb6698 Feb 10, 2022
46409be
test google
bb6698 Feb 10, 2022
2c49d31
Cambios tests
Feb 10, 2022
3d63457
style problems number 3 rectified
lu164 Feb 12, 2022
07628e1
some tests for angle2pos added
lu164 Feb 12, 2022
b6df875
Laser Callback test
Feb 12, 2022
f1c701c
method CheckState improved and a new state wall_afront added
lu164 Feb 13, 2022
4ae2189
Finished,everything ok
bb6698 Feb 13, 2022
12ca2aa
Merge pull request #5 from Docencia-fmrico/laserProcessing
angelobarra Feb 13, 2022
38a04bd
Change so automatic test passes
angelobarra Feb 13, 2022
5c5566d
Eliminated errors 3 test
bb6698 Feb 13, 2022
d55447d
test ok
bb6698 Feb 13, 2022
81ce4d9
Images README
angelobarra Feb 14, 2022
44244e0
Update README.md
angelobarra Feb 14, 2022
0bba0ae
Fix on_cleanup and later on_configure core
Feb 14, 2022
6a61431
three blank lines erased
lu164 Feb 14, 2022
73faa3d
README.md with videos
angelobarra Feb 14, 2022
38f64d9
small readjustment in angle2pos
lu164 Feb 14, 2022
8e7e44c
Update README.md
lu164 Feb 15, 2022
67f5d84
Nan or Inf values of laser ignored with comparator
Feb 16, 2022
0c018f1
Merge pull request #6 from Docencia-fmrico/min_tests
bb6698 Feb 16, 2022
e2cd682
Video Real Kobuki
angelobarra Feb 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: main

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
build-and-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04]
fail-fast: false
steps:
- name: Setup ROS 2
uses: ros-tooling/[email protected]
with:
required-ros-distributions: foxy
- name: build and test
uses: ros-tooling/[email protected]
with:
package-name: follow_wall_k_bots
import-token: ${{secrets.GITHUB_TOKEN}}
target-ros2-distro: foxy
colcon-defaults: |
{
"test": {
"ctest-args": [
"-LE", "copyright"
]
}
}

17 changes: 17 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/opt/ros/foxy/include"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
86 changes: 86 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
cmake_minimum_required(VERSION 3.5)
project(follow_wall_k_bots)

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_BUILD_TYPE DEBUG)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

list(APPEND AMENT_LINT_AUTO_EXCLUDE
ament_cmake_copyright
)

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
find_package(ament_cmake_gtest)

find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()

# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

ament_add_gtest(node_test test/node_test.cpp)
target_link_libraries(node_test ${PROJECT_NAME})

set(dependencies
rclcpp
rclcpp_lifecycle
std_msgs
sensor_msgs
geometry_msgs
)

include_directories(include)

add_library(${PROJECT_NAME} SHARED
src/follow_wall/follow_wall.cpp
)

add_executable(follow_wall_main src/follow_wall_main.cpp)
ament_target_dependencies(follow_wall_main ${dependencies})

target_link_libraries(follow_wall_main ${PROJECT_NAME})

install(TARGETS
follow_wall_main
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION lib/${PROJECT_NAME}
)
install(DIRECTORY include/
DESTINATION include/
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all
# source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()


ament_export_include_directories(include)
ament_export_libraries(${PROJECT_NAME})
ament_export_dependencies(${dependencies})
ament_target_dependencies(${PROJECT_NAME} ${dependencies})

ament_package()
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,48 @@
[![Open in Visual Studio Code](https://classroom.github.com/assets/open-in-vscode-f059dc9a6f8d3a56e377f745f24479a46679e63a5d9fe6f495e02850cd0d8118.svg)](https://classroom.github.com/online_ide?assignment_repo_id=6883151&assignment_repo_type=AssignmentRepo)
# folllow_wall

[![GitHub Action
Status](https://github.com/Docencia-fmrico/follow-wall-k-bots/workflows/main/badge.svg)](https://github.com/Docencia-fmrico/follow-wall-k-bots)


# Follow_Wall
## Introducción
En esta práctica realizaremos un algoritmo basado en seguir la pared, para ello utilizamos el sensor láser y los LifeCycle nodes de ROS2.
## Extracción valores del láser
Para saber donde están los obstáculos, en este caso la pared, usamos el láser. Como procesado, extraemos la medida mínima en un cono de amplitud de 10º centrado en tres regiones: la frontal (0), la izquierda (pi/2) y la derecha (-pi/2). Finalmente, las tres medidas se guardan en un vector.
<p align="center">
<img src="./images/laserregions.png" width="75%" height="75%">
</p align>

## Control de Movimiento
Aprovechando las características de los LifeCycle Nodes y sus estados y transiciones, usamos la transición on_configure() para ver si el robot tiene algún obstáculo cercano a izquierda o derecha y comenzar siguiendo ese lado del robot directamente. Si no hay nada cerca, se elige un lado del robot para seguir la pared al azar.
```
FollowWallNode::on_configure() {
// Esperar por medidas del láser
while (laser_regions.size() == 0) {continue;}

// Elegir un lado a seguir
if (laser_regions[A] < distance) {side = LEFT;}
else if (laser_regions[C] < distance) {side = RIGHT;}
else {
if (rand() % 2 == 0) {side = LEFT;}
else {side = RIGHT;}
}
}
```
Una vez se ha realizado la configuración, se espera a que el nodo sea activado para comenzar a mover el robot. Si se desease cambiar la configuración de qué lado sigue el robot, basta con volver a ejecutar la transición on_configure().

[[Video de reconfiguración]](https://youtu.be/Y4X0Fe2ARrQ)

Cuando se active el nodo se realizará el siguiente proceso de comprobación. Una vez hecho, en función del estado seleccionado se seleccionarán velocidades lineales y angulares correspondientes a cada estado:
<p align="center">
<img src="./images/casecontrol.png" width="75%" height="75%">
</p align>
En el caso de que se aleje al robot de la pared, este comenzará a girar hacía el lado que estaba siguiendo. Se ha contemplado que si ha entrado en dicho estado, un número concreto de iteraciones, el robot deje de hacer este movimiento y vuelva a buscar la pared avanzando hacia una dirección hasta volver a encontrarla.

[[Video de alejar de pared]](https://youtu.be/vCkj9qj-gTk)

## Video DEMO

[[Demo]](https://youtu.be/Omu6V5bajiw)
[[Demo Kobuki Real]](https://youtu.be/rBmrcK2q36I)

Binary file added images/casecontrol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/laserregions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/lifecyclenode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions include/follow_wall/follow_wall.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2022 K-Bots
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef FOLLOW_WALL__FOLLOW_WALL_HPP_

#define FOLLOW_WALL__FOLLOW_WALL_HPP_

#include <vector>

#include "geometry_msgs/msg/twist.hpp"
#include "lifecycle_msgs/msg/state.hpp"
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_lifecycle/lifecycle_node.hpp"
#include "sensor_msgs/msg/laser_scan.hpp"

class FollowWallNode : public rclcpp_lifecycle::LifecycleNode
{
public:
FollowWallNode();

using CallbackReturnT = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;

CallbackReturnT on_configure(const rclcpp_lifecycle::State & state);
CallbackReturnT on_activate(const rclcpp_lifecycle::State & state);
CallbackReturnT on_deactivate(const rclcpp_lifecycle::State & state);
CallbackReturnT on_cleanup(const rclcpp_lifecycle::State & state);
CallbackReturnT on_shutdown(const rclcpp_lifecycle::State & state);
CallbackReturnT on_error(const rclcpp_lifecycle::State & state);

static bool comparator(float a, float b);

void LaserCallback(const sensor_msgs::msg::LaserScan::SharedPtr msg);

int angle2pos(float angle, float min, float max, int size);
void CheckState();
void FollowTheWall();
void do_work();
void LookForWall();

std::vector<float> laser_regions;

private:
rclcpp::Subscription<sensor_msgs::msg::LaserScan>::SharedPtr laserSub_;
rclcpp_lifecycle::LifecyclePublisher<geometry_msgs::msg::Twist>::SharedPtr pubVelocity_;

const float LINEAL_VELOCITY = 0.6;
const float ANGULAR_VELOCITY = 1;
const float MAX_DISTANCE = 0.5;
const float MIN_DISTANCE = 0.4;
const float RESTART_VALUE = 1.5;
const int MAX_ITERATIONS = 50;
bool wall_found = false;

int counter_ = 0;
int state_ = GOING_FORWARD;
int side_ = 0;

enum robot_side
{
LEFT_SIDE = 1,
RIGHT_SIDE
};

enum movement
{
GOING_FORWARD = 1,
TURN_SAME_SIDE,
TURN_OPPOSITE_SIDE,
WALL_AHEAD
};

enum laser_side
{
LEFT = 0,
CENTER,
RIGHT
};
};

#endif // FOLLOW_WALL__FOLLOW_WALL_HPP_
23 changes: 23 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>follow_wall_k_bots</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="[email protected]">lucia</maintainer>
<license>TODO: License declaration</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<depend>rclcpp</depend>
<depend>rclcpp_lifecycle</depend>
<depend>std_msgs</depend>
<depend>geometry_msgs</depend>
<depend>sensor_msgs</depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Loading