-
Notifications
You must be signed in to change notification settings - Fork 24
Reset - End of the Year Challenge 2022 Final Submission #140
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,5 +8,5 @@ | |
| data = [True] # Packet cannot be empty | ||
| packet = struct.pack("?", *data) | ||
|
|
||
| while robot.step(32) != -1: | ||
| while robot.step(8) != -1: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Let us know if you have any other questions regarding this issue! Team Reset |
||
| ball_emitter.send(packet) | ||
| 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) | ||
|
|
||
|
|
@@ -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 | ||
|
|
@@ -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(), | ||
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @resetteam2023 is there any reason for the exact value of
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Thank you! Team Reset |
||
| elif state == 0: | ||
| self.kicker_motor.setVelocity(velocity) | ||
| self.kicker_motor.setPosition(0) | ||
|
|
||
| def run(self): | ||
| raise NotImplementedError | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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 | ||
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello @mrshu, If Let us know if you have any further questions! Team Reset |
||
|
|
||
| # Send message to team robots | ||
| self.send_data_to_team(self.player_id) | ||
Uh oh!
There was an error while loading. Please reload this page.