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

Reset - End of the Year Challenge 2022 Final Submission #140

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion controllers/rcj_soccer_ball/rcj_soccer_ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
data = [True] # Packet cannot be empty
packet = struct.pack("?", *data)

while robot.step(32) != -1:
while robot.step(8) != -1:
Adman marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

@Adman Adman Jan 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the time step reduced to 8? Did 32 cause any problems?

Copy link
Author

@resetteam2023 resetteam2023 Jan 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Adman,

Yes, since the physics computation is now a lot more complicated than before, changing the value for the basic time step of the world would drastically affect the way that robots move and perform. After testing, we found that setting the basic time step of the world to 8 is the most ideal. When we set the basic time step to a value greater than 8, Webots would have trouble computing the physics correctly when collision between robots happen (the physics-related warning message WARNING: The current physics step could not be computed correctly. Your world may be too complex. If this problem persists, try simplifying your bounding object(s), reducing the number of joints, or reducing WorldInfo.basicTimeStep. appeared more frequently). On the other hand, when we set the basic time step to a value lower than 8, the robots no longer moved as we expected and the simulation ran slower.

Let us know if you have any other questions regarding this issue!

Team Reset

ball_emitter.send(packet)
4 changes: 2 additions & 2 deletions controllers/rcj_soccer_referee_supervisor/referee/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
FIELD_X_UPPER_LIMIT = 0.655
FIELD_X_LOWER_LIMIT = -0.655

TIME_STEP = 32
TIME_STEP = 8
ROBOT_NAMES = ["B1", "B2", "B3", "Y1", "Y2", "Y3"]
N_ROBOTS = len(ROBOT_NAMES)

Expand All @@ -38,7 +38,7 @@
BLUE_RIGHT_NS: (-0.3, 0.3),
}

OBJECT_DEPTH = 0.042
OBJECT_DEPTH = 0.0380918

ROBOT_INITIAL_TRANSLATION = {
"B1": [0.3, 0.3, OBJECT_DEPTH],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def is_progress(self) -> bool:
"""
s = sum(self.samples)

# We we haven't tracked at least as many samples as the number of
# We haven't tracked at least as many samples as the number of
Adman marked this conversation as resolved.
Show resolved Hide resolved
# steps, our default position is "benefit of doubt": we assume enough
# progress has been made.
if self.iterator < self.steps:
Expand Down
40 changes: 31 additions & 9 deletions controllers/rcj_soccer_team_blue/rcj_soccer_robot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import math
import struct

TIME_STEP = 32
TIME_STEP = 8
ROBOT_NAMES = ["B1", "B2", "B3", "Y1", "Y2", "Y3"]
N_ROBOTS = len(ROBOT_NAMES)

Expand Down Expand Up @@ -38,14 +38,26 @@ def __init__(self, robot):
self.sonar_back = self.robot.getDevice("distancesensor back")
self.sonar_back.enable(TIME_STEP)

self.left_motor = self.robot.getDevice("left wheel motor")
self.right_motor = self.robot.getDevice("right wheel motor")

self.left_motor.setPosition(float("+inf"))
self.right_motor.setPosition(float("+inf"))

self.left_motor.setVelocity(0.0)
self.right_motor.setVelocity(0.0)
self.front_left_motor = self.robot.getDevice("front left motor")
self.front_right_motor = self.robot.getDevice("front right motor")
self.rear_left_motor = self.robot.getDevice("rear left motor")
self.rear_right_motor = self.robot.getDevice("rear right motor")
self.dribbler_motor = self.robot.getDevice("dribbler motor")
self.kicker_motor = self.robot.getDevice("kicker motor")

self.front_left_motor.setPosition(float("+inf"))
self.front_right_motor.setPosition(float("+inf"))
self.rear_left_motor.setPosition(float("+inf"))
self.rear_right_motor.setPosition(float("+inf"))
self.dribbler_motor.setPosition(float("+inf"))
self.kicker_motor.setPosition(0)

self.front_left_motor.setVelocity(0.0)
self.front_right_motor.setVelocity(0.0)
self.rear_left_motor.setVelocity(0.0)
self.rear_right_motor.setVelocity(0.0)
self.dribbler_motor.setVelocity(0.0)
self.kicker_motor.setVelocity(5.0)

def parse_supervisor_msg(self, packet: str) -> dict:
"""Parse message received from supervisor
Expand Down Expand Up @@ -139,6 +151,7 @@ def get_new_ball_data(self) -> dict:
}
"""
_ = self.ball_receiver.getData()

data = {
"direction": self.ball_receiver.getEmitterDirection(),
"strength": self.ball_receiver.getSignalStrength(),
Expand Down Expand Up @@ -191,5 +204,14 @@ def get_sonar_values(self) -> dict:
"back": self.sonar_back.getValue(),
}


def kick_ball(self, state, velocity=20):
if state == 1:
self.kicker_motor.setVelocity(velocity)
self.kicker_motor.setPosition(0.042)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@resetteam2023 is there any reason for the exact value of 0.042 in here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @mrshu,

Yes, the value of 0.042 here represents the furthest position that the kicker could move to without moving beyond the frame of the robot (the greater the value, the further the center of the kicker is away from the center of the robot).

When we were making the kicker in the Webots world, we only made sure that the kicker position had to be between 0 and 0.042. While this means that the kicker could be moved to positions between 0 and 0.042, the kicker would not be kicking rthe ball as hard in those cases.

If you would like, we could add a parameter to the kick_ball function that would allow the kicker to be moved to specific positions between 0 and 0.042.

Thank you!

Team Reset

elif state == 0:
self.kicker_motor.setVelocity(velocity)
self.kicker_motor.setPosition(0)

def run(self):
raise NotImplementedError
46 changes: 34 additions & 12 deletions controllers/rcj_soccer_team_blue/robot1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import utils
from rcj_soccer_robot import RCJSoccerRobot, TIME_STEP


class MyRobot1(RCJSoccerRobot):
def run(self):
kick_time = 0
while self.robot.step(TIME_STEP) != -1:
kick_time += TIME_STEP # Time in milliseconds
if self.is_new_data():
data = self.get_new_data() # noqa: F841

Expand All @@ -22,8 +23,10 @@ def run(self):
ball_data = self.get_new_ball_data()
else:
# If the robot does not see the ball, stop motors
self.left_motor.setVelocity(0)
self.right_motor.setVelocity(0)
self.front_left_motor.setVelocity(0.0)
self.front_right_motor.setVelocity(0.0)
self.rear_left_motor.setVelocity(0.0)
self.rear_right_motor.setVelocity(0.0)
continue

# Get data from compass
Expand All @@ -38,18 +41,37 @@ def run(self):
# Compute the speed for motors
direction = utils.get_direction(ball_data["direction"])

# If the robot has the ball right in front of it, go forward,
# rotate otherwise
"""
Wheel motors (max velocity: 40, +: counterclockwise, -: clockwise)
Dribbler motor (max velocity: 50, +: hold, -: release)
Kicker motor (max velocity: 20, state 1: out, state 0: in, call kickBall function)
"""

# If the robot has the ball right in front of it, go forward, rotate otherwise
# Set the speed to motors
if direction == 0:
left_speed = 7
right_speed = 7
move_speed = 40
self.front_left_motor.setVelocity(move_speed)
self.rear_left_motor.setVelocity(move_speed)
self.front_right_motor.setVelocity(-move_speed)
self.rear_right_motor.setVelocity(-move_speed)
else:
left_speed = direction * 4
right_speed = direction * -4
turn_speed = -direction * 20
self.front_left_motor.setVelocity(turn_speed)
self.rear_left_motor.setVelocity(turn_speed)
self.front_right_motor.setVelocity(turn_speed)
self.rear_right_motor.setVelocity(turn_speed)

# Set the speed to motors
self.left_motor.setVelocity(left_speed)
self.right_motor.setVelocity(right_speed)
# Dribble the ball at a velocity of 50
self.dribbler_motor.setVelocity(50)

# Kick the ball for 0.5 seconds every 5 seconds
if 5000 < kick_time < 5500:
self.kick_ball(1, 20)
elif kick_time > 5500:
kick_time = 0
else:
self.kick_ball(0, 20)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@resetteam2023 just out of curiosity, what would happen if this call wasn't made (i.e. kick_ball would never be executed with state=0)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @mrshu,

If kick_ball is never executed with state = 0, after kick_ball is executed with state = 1, the kicker would remain in the "outward" position (the center of the kicker would be at a position of 0.042). This means that the robot would not be able to kick the ball again and would not be able to dribble the ball.

Let us know if you have any further questions!

Team Reset


# Send message to team robots
self.send_data_to_team(self.player_id)
49 changes: 37 additions & 12 deletions controllers/rcj_soccer_team_blue/robot2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import utils
from rcj_soccer_robot import RCJSoccerRobot, TIME_STEP


class MyRobot2(RCJSoccerRobot):
def run(self):
kick_time = 0
while self.robot.step(TIME_STEP) != -1:
kick_time += TIME_STEP # Time in milliseconds
if self.is_new_data():
data = self.get_new_data() # noqa: F841

Expand All @@ -22,8 +23,10 @@ def run(self):
ball_data = self.get_new_ball_data()
else:
# If the robot does not see the ball, stop motors
self.left_motor.setVelocity(0)
self.right_motor.setVelocity(0)
self.front_left_motor.setVelocity(0.0)
self.front_right_motor.setVelocity(0.0)
self.rear_left_motor.setVelocity(0.0)
self.rear_right_motor.setVelocity(0.0)
continue

# Get data from compass
Expand All @@ -32,21 +35,43 @@ def run(self):
# Get GPS coordinates of the robot
robot_pos = self.get_gps_coordinates() # noqa: F841

# Get data from sonars
sonar_values = self.get_sonar_values() # noqa: F841

# Compute the speed for motors
direction = utils.get_direction(ball_data["direction"])

# If the robot has the ball right in front of it, go forward,
# rotate otherwise
"""
Wheel motors (max velocity: 40, +: counterclockwise, -: clockwise)
Dribbler motor (max velocity: 50, +: hold, -: release)
Kicker motor (max velocity: 20, state 1: out, state 0: in, call kickBall function)
"""

# If the robot has the ball right in front of it, go forward, rotate otherwise
# Set the speed to motors
if direction == 0:
left_speed = 7
right_speed = 7
move_speed = 40
self.front_left_motor.setVelocity(move_speed)
self.rear_left_motor.setVelocity(move_speed)
self.front_right_motor.setVelocity(-move_speed)
self.rear_right_motor.setVelocity(-move_speed)
else:
left_speed = direction * 4
right_speed = direction * -4
turn_speed = -direction * 20
self.front_left_motor.setVelocity(turn_speed)
self.rear_left_motor.setVelocity(turn_speed)
self.front_right_motor.setVelocity(turn_speed)
self.rear_right_motor.setVelocity(turn_speed)

# Set the speed to motors
self.left_motor.setVelocity(left_speed)
self.right_motor.setVelocity(right_speed)
# Dribble the ball at a velocity of 50
self.dribbler_motor.setVelocity(50)

# Kick the ball for 0.5 seconds every 5 seconds
if 5000 < kick_time < 5500:
self.kick_ball(1, 20)
elif kick_time > 5500:
kick_time = 0
else:
self.kick_ball(0, 20)

# Send message to team robots
self.send_data_to_team(self.player_id)
46 changes: 34 additions & 12 deletions controllers/rcj_soccer_team_blue/robot3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import utils
from rcj_soccer_robot import RCJSoccerRobot, TIME_STEP


class MyRobot3(RCJSoccerRobot):
def run(self):
kick_time = 0
while self.robot.step(TIME_STEP) != -1:
kick_time += TIME_STEP # Time in milliseconds
if self.is_new_data():
data = self.get_new_data() # noqa: F841

Expand All @@ -22,8 +23,10 @@ def run(self):
ball_data = self.get_new_ball_data()
else:
# If the robot does not see the ball, stop motors
self.left_motor.setVelocity(0)
self.right_motor.setVelocity(0)
self.front_left_motor.setVelocity(0.0)
self.front_right_motor.setVelocity(0.0)
self.rear_left_motor.setVelocity(0.0)
self.rear_right_motor.setVelocity(0.0)
continue

# Get data from compass
Expand All @@ -38,18 +41,37 @@ def run(self):
# Compute the speed for motors
direction = utils.get_direction(ball_data["direction"])

# If the robot has the ball right in front of it, go forward,
# rotate otherwise
"""
Wheel motors (max velocity: 40, +: counterclockwise, -: clockwise)
Dribbler motor (max velocity: 50, +: hold, -: release)
Kicker motor (max velocity: 20, state 1: out, state 0: in, call kickBall function)
"""

# If the robot has the ball right in front of it, go forward, rotate otherwise
# Set the speed to motors
if direction == 0:
left_speed = 7
right_speed = 7
move_speed = 40
self.front_left_motor.setVelocity(move_speed)
self.rear_left_motor.setVelocity(move_speed)
self.front_right_motor.setVelocity(-move_speed)
self.rear_right_motor.setVelocity(-move_speed)
else:
left_speed = direction * 4
right_speed = direction * -4
turn_speed = -direction * 20
self.front_left_motor.setVelocity(turn_speed)
self.rear_left_motor.setVelocity(turn_speed)
self.front_right_motor.setVelocity(turn_speed)
self.rear_right_motor.setVelocity(turn_speed)

# Set the speed to motors
self.left_motor.setVelocity(left_speed)
self.right_motor.setVelocity(right_speed)
# Dribble the ball at a velocity of 50
self.dribbler_motor.setVelocity(50)

# Kick the ball for 0.5 seconds every 5 seconds
if 5000 < kick_time < 5500:
self.kick_ball(1, 20)
elif kick_time > 5500:
kick_time = 0
else:
self.kick_ball(0, 20)

# Send message to team robots
self.send_data_to_team(self.player_id)
Loading