Skip to content

Commit

Permalink
Merge branch 'base/RL' into feature/RL
Browse files Browse the repository at this point in the history
  • Loading branch information
Akram authored and Akram committed Jul 29, 2024
2 parents f69babc + 8211836 commit daf8e1e
Show file tree
Hide file tree
Showing 25 changed files with 254,629 additions and 220 deletions.
29 changes: 28 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,31 @@ jobs:

- name: Print doxygen warnings
if: ${{ failure() }}
run: cat ./doc/doxygen/doxygen_warnings.txt
run: cat ./doc/doxygen/doxygen_warnings.txt

# Lint Python code
lint:
# The type of runner that the job will run on.
runs-on: ubuntu-latest
needs: intro
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]

# Steps represent a sequence of tasks that will be executed as part of the job.
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip install pylint
- name: Analysing the code with pylint
run: |
pylint ./webots/controllers/*/*.py
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ lib/Webots
*.wbproj
webots/worlds/*.jpg
doc/doxygen/*/*
__pycache__
__pycache__
tmp/
4 changes: 2 additions & 2 deletions lib/APPLineFollower/src/StartupState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ void StartupState::process(StateMachine& sm)
Board& board = Board::getInstance();
IButton& buttonA = board.getButtonA();

/* Start line sensor calibration? */
/* Start motor calibration? */
if (true == Util::isButtonTriggered(buttonA, m_isButtonAPressed))
{
sm.setState(&LineSensorsCalibrationState::getInstance());
sm.setState(&MotorSpeedCalibrationState::getInstance());
}

/* If the max. motor speed calibration is done, it will be possible to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" Controller for Obstacle proto."""

import sys
from controller import Robot
from controller import Robot # pylint: disable=import-error

# Debounce time of collision in seconds.
DEBOUNCE_TIME = 1
Expand Down
85 changes: 0 additions & 85 deletions webots/controllers/PlatoonSupervisor/PlatoonSupervisor.py

This file was deleted.

8 changes: 6 additions & 2 deletions webots/controllers/Supervisor/robot_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

import math


class RobotObserver():
"""The robot observer provides position and orientation information
about a robot by using a supervisor.
"""

def __init__(self, robot_node):
self._robot_node = robot_node
self._ref_position = [0, 0, 0] # x, y, z
self._ref_orientation_euler = [0, 0, 0, 0] # roll, pitch and yaw angle
self._ref_position = [0, 0, 0] # x, y, z
self._ref_orientation_euler = [0, 0, 0, 0] # roll, pitch and yaw angle
self._factor_m_to_mm = 1000

def _get_position(self):
Expand Down Expand Up @@ -133,6 +135,7 @@ def rad_to_deg(angle_rad):
"""
return angle_rad * 180 / math.pi


def has_position_changed(position, position_old):
"""Returns whether the position changed.
Expand All @@ -152,6 +155,7 @@ def has_position_changed(position, position_old):

return has_changed


def has_orientation_changed(orientation, orientation_old):
"""Returns whether the orientation changed.
Expand Down
88 changes: 88 additions & 0 deletions webots/controllers/platoon_supervisor/platoon_supervisor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
""" Platoon Supervisor controller for Webots.
Moves the obstacle up and down when the space key is pressed. """

import sys
from controller import Supervisor # pylint: disable=import-error

DEBOUNCE_TIME = 0.2 # Debounce time for the spacebar in seconds
OBSTACLE_NAME = "OBSTACLE" # Name of the obstacle node
TRANSLATION_FIELD = "translation" # Field name for the translation

RAISED_HEIGHT = 0.4 # Active height in meters
LOWERED_HEIGHT = 0.06 # Rest height in meters

# Create the Supervisor instance.
supervisor = Supervisor()

# Get the keyboard device
keyboard = supervisor.getKeyboard()


def main_loop():
"""Main loop:
- Perform simulation steps until Webots is stopping the controller-
Returns:
number: Status
"""

status = 0

# Get the obstacle node
obstacle_node = supervisor.getFromDef(OBSTACLE_NAME)

if obstacle_node is None:

print(f"Robot DEF {OBSTACLE_NAME} not found.")
status = -1

else:
# Get the translation field of the obstacle node
translation_field = obstacle_node.getField(TRANSLATION_FIELD)

if translation_field is None:
print(
f"Translation field {TRANSLATION_FIELD} of {OBSTACLE_NAME} not found.")
status = -1

if status == 0:
# Get the time step of the current world.
timestep = int(supervisor.getBasicTimeStep())

# Enable the keyboard device
keyboard.enable(timestep)

# Get current time for debouncing
last_time = supervisor.getTime()

# Set the initial state to raised obstacle
is_obstacle_lowered = False
curr_pos = translation_field.getSFVec3f()
translation_field.setSFVec3f(
[curr_pos[0], curr_pos[1], RAISED_HEIGHT])

while supervisor.step(timestep) != -1:
if keyboard.getKey() == ord(' '): # If space key is pressed
if (supervisor.getTime() - last_time) > DEBOUNCE_TIME: # Debounce space key

# Update last time
last_time = supervisor.getTime()

# Get the current position of the obstacle
curr_pos = translation_field.getSFVec3f()

# Move the obstacle
if is_obstacle_lowered is True: # Raise the obstacle
translation_field.setSFVec3f(
[curr_pos[0], curr_pos[1], RAISED_HEIGHT])
else: # Lower the obstacle
translation_field.setSFVec3f(
[curr_pos[0], curr_pos[1], LOWERED_HEIGHT])

# Toggle the obstacle state
is_obstacle_lowered = not is_obstacle_lowered

return status


sys.exit(main_loop())
2 changes: 1 addition & 1 deletion webots/protos/Obstacle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ PROTO Obstacle [
]
name IS name
boundingObject USE BODY
controller "Obstacle"
controller "obstacle"
}
}
Loading

0 comments on commit daf8e1e

Please sign in to comment.