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

Implemented Chip Pass Modeling #3229

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/extlibs/er_force_sim/src/amun/simulator/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ qt_cc_library(
"@qt//:qt_core",
"@qt//:qt_gui",
"@qt//:qt_widgets",
"//software/logger:logger",
"//proto/message_translation:tbots_protobuf"
],
#linkstatic = True,
alwayslink = True,
Expand Down
11 changes: 11 additions & 0 deletions src/extlibs/er_force_sim/src/amun/simulator/simball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include "extlibs/er_force_sim/src/core/vector.h"
#include "proto/ssl_vision_detection.pb.h"
#include "simulator.h"
#include "software/logger/logger.h"
#include "proto/message_translation/tbots_protobuf.h"

// #include "software/logger/logger.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

remember to re-comment this back in


using namespace camun::simulator;

Expand Down Expand Up @@ -82,6 +86,13 @@ void SimBall::begin(bool robot_collision)
// custom implementation of rolling friction
const btVector3 p = m_body->getWorldTransform().getOrigin();
const btVector3 velocity = m_body->getLinearVelocity();
LOG(PLOTJUGGLER) << *createPlotJugglerValue({
{"dist", std::sqrt(pow(p.x() - 0, 2) + pow(p.y() - 0, 2))},
{"z", p.z()},
{"speed", velocity.length()}
});

std::cout << "SPEED: " << velocity.length() << std::endl;
if (p.z() < static_cast<float>(BALL_MAX_RADIUS_METERS) * 1.1f * SIMULATOR_SCALE)
{ // ball is on the ground
bool is_stationary =
Expand Down
6 changes: 5 additions & 1 deletion src/extlibs/er_force_sim/src/amun/simulator/simrobot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ void SimRobot::begin(SimBall *ball, double time)

stopDribbling();


std::cout << "ANGLE: " << m_sslCommand.kick_angle() << std::endl;

if (m_sslCommand.kick_angle() == 0)
{
// we subtract the current speed of the ball from the intended kick speed
Expand Down Expand Up @@ -453,13 +456,14 @@ void SimRobot::begin(SimBall *ball, double time)
{
// if the ball hits the robot the chip distance actually decreases
const btVector3 relBallSpeed = relativeBallSpeed(ball) / SIMULATOR_SCALE;

return std::max((btScalar)0, relBallSpeed.y()) -
qBound((btScalar)0, (btScalar)0.5 * relBallSpeed.y(),
(btScalar)0.5 * dirFloor);
}
};
const float speedCompensation = getSpeedCompensation();
ball->kick(t * btVector3(0, dirFloor * power + speedCompensation, dirUp * power) *
ball->kick(t * btVector3(0, dirFloor * power - speedCompensation, dirUp * power) *
Copy link
Contributor

Choose a reason for hiding this comment

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

why do you need this change?

(1.0f / static_cast<float>(time)) * SIMULATOR_SCALE *
static_cast<float>(BALL_MASS_KG));
// discharge
Expand Down
1 change: 1 addition & 0 deletions src/proto/message_translation/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ cc_library(
"//shared:robot_constants",
"//software/geom:angle",
"//software/logger",
"//proto/message_translation:tbots_protobuf"
],
)

Expand Down
31 changes: 23 additions & 8 deletions src/proto/message_translation/tbots_protobuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,17 +376,32 @@ std::unique_ptr<TbotsProto::PassVisualization> createPassVisualization(

for (const auto& pass_with_rating : passes_with_rating)
{
auto pass_msg = std::make_unique<TbotsProto::Pass>();
*(pass_msg->mutable_passer_point()) =
*createPointProto(pass_with_rating.pass.passerPoint());
*(pass_msg->mutable_receiver_point()) =
*createPointProto(pass_with_rating.pass.receiverPoint());
pass_msg->set_pass_speed_m_per_s(pass_with_rating.pass.speed());

auto pass_with_rating_msg = std::make_unique<TbotsProto::PassWithRating>();
pass_with_rating_msg->set_rating(pass_with_rating.rating);
*(pass_with_rating_msg->mutable_pass_()) = *pass_msg;

auto pass = pass_with_rating.pass;

auto base_pass_msg = std::make_unique<TbotsProto::BasePass>();
*(base_pass_msg->mutable_passer_point()) =
*createPointProto(pass.passerPoint());
*(base_pass_msg->mutable_receiver_point()) =
*createPointProto(pass.receiverPoint());

if (pass.type() == PassType::CHIP_PASS)
{
auto chip_pass_msg = std::make_unique<TbotsProto::ChipPass>();
*(chip_pass_msg->mutable_pass_coords()) = *base_pass_msg;
chip_pass_msg->set_chip_distance_meters(reinterpret_cast<ChipPass*>(&pass)->firstBounceRange());
*(pass_with_rating_msg->mutable_pass_()->mutable_chip_pass()) = *chip_pass_msg;
}
else
{
auto pass_msg = std::make_unique<TbotsProto::Pass>();
*(pass_msg->mutable_pass_coords()) = *base_pass_msg;
pass_msg->set_pass_speed_m_per_s(reinterpret_cast<Pass*>(&pass)->speed());
*(pass_with_rating_msg->mutable_pass_()->mutable_ground_pass()) = *pass_msg;
}

*(pass_visualization_msg->add_best_passes()) = *pass_with_rating_msg;
}
return pass_visualization_msg;
Expand Down
2 changes: 2 additions & 0 deletions src/proto/message_translation/tbots_protobuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "software/ai/navigator/trajectory/bang_bang_trajectory_1d_angular.h"
#include "software/ai/navigator/trajectory/trajectory_path.h"
#include "software/ai/passing/pass_with_rating.h"
#include "software/ai/passing/pass.h"
#include "software/ai/passing/chip_pass.h"
#include "software/world/world.h"

/**
Expand Down
20 changes: 14 additions & 6 deletions src/proto/visualization.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ message PlotJugglerValue

message PassWithRating
{
double rating = 1;
Pass pass_ = 2; // needs the _ because pass is a keyword in python
double rating = 1;
oneof pass_ // needs the _ because pass is a keyword in python
{
Pass ground_pass = 2;
ChipPass chip_pass = 3;
}
}

message PassVisualization
Expand All @@ -35,10 +39,14 @@ message PassVisualization

message AttackerVisualization
{
optional Pass pass_ = 1; // needs the _ because pass is a keyword in python
bool pass_committed = 2;
optional Shot shot = 3;
optional Point chip_target = 4;
oneof pass_ // needs the _ because pass is a keyword in python
{
Pass ground_pass = 1;
ChipPass chip_pass = 2;
}
bool pass_committed = 3;
optional Shot shot = 4;
optional Point chip_target = 5;
}

message CostVisualization
Expand Down
19 changes: 17 additions & 2 deletions src/proto/world.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,31 @@ message SimulationState
required double simulation_speed = 2 [default = 1.0];
}

message Pass
message BasePass
{
// The location of the passer
required Point passer_point = 1;

// The location of the receiver
required Point receiver_point = 2;
}

message Pass
{
// The pass coordinates
required BasePass pass_coords = 1;

// The speed of the pass in meters/second
required double pass_speed_m_per_s = 3;
required double pass_speed_m_per_s = 2;
}

message ChipPass
{
// The pass coordinates
required BasePass pass_coords;

// The range of the first bounce of the chip
required double chip_distance_meters = 3;
}

message Shot
Expand Down
1 change: 1 addition & 0 deletions src/shared/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ static const double MIN_CAPACITOR_VOLTAGE = 0;
static const double MAX_CAPACITOR_VOLTAGE = 250.0 + 50.0; // +50v headroom

static const unsigned int ROBOT_CHIP_ANGLE_DEGREES = 45;
static const double ROBOT_CHIP_ANGLE_RADIANS = ROBOT_CHIP_ANGLE_DEGREES * M_PI / 180;
static const double CHICKER_TIMEOUT = 3 * MILLISECONDS_PER_SECOND;
// How many robots are allowed in each division
static const unsigned DIV_A_NUM_ROBOTS = 11;
Expand Down
29 changes: 22 additions & 7 deletions src/software/ai/hl/stp/tactic/attacker/attacker_tactic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,28 @@ void AttackerTactic::visualizeControlParams(

if (control_params.best_pass_so_far.has_value())
{
TbotsProto::Pass pass_msg;
*(pass_msg.mutable_passer_point()) =
*createPointProto(control_params.best_pass_so_far->passerPoint());
*(pass_msg.mutable_receiver_point()) =
*createPointProto(control_params.best_pass_so_far->receiverPoint());
pass_msg.set_pass_speed_m_per_s(control_params.best_pass_so_far->speed());
*(pass_visualization_msg.mutable_pass_()) = pass_msg;
auto pass = control_params.best_pass_so_far;

auto base_pass_msg = std::make_unique<TbotsProto::BasePass>();
*(base_pass_msg->mutable_passer_point()) =
*createPointProto(pass.passerPoint());
*(base_pass_msg->mutable_receiver_point()) =
*createPointProto(pass.receiverPoint());

if (pass.type() == PassType::CHIP_PASS)
{
auto chip_pass_msg = std::make_unique<TbotsProto::ChipPass>();
*(chip_pass_msg->mutable_pass_coords()) = *base_pass_msg;
chip_pass_msg->set_chip_distance_meters(reinterpret_cast<ChipPass*>(&pass)->firstBounceRange());
*(pass_visualization_msg->mutable_pass_()->mutable_chip_pass()) = *chip_pass_msg;
}
else
{
auto pass_msg = std::make_unique<TbotsProto::Pass>();
*(pass_msg->mutable_pass_coords()) = *base_pass_msg;
pass_msg->set_pass_speed_m_per_s(reinterpret_cast<Pass*>(&pass)->speed());
*(pass_visualization_msg->mutable_pass_()->mutable_ground_pass()) = *pass_msg;
}
}

pass_visualization_msg.set_pass_committed(pass_committed);
Expand Down
66 changes: 34 additions & 32 deletions src/software/ai/hl/stp/tactic/chip/chip_tactic_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TEST_P(ChipTacticTest, chip_test)
Vector ball_offset_from_robot = std::get<0>(GetParam());
Angle angle_to_kick_at = std::get<1>(GetParam());

Point robot_position = Point(0, 0);
Point robot_position = Point(-0.5, 0);
BallState ball_state(robot_position + ball_offset_from_robot, Vector(0, 0));

auto friendly_robots =
Expand All @@ -35,47 +35,49 @@ TEST_P(ChipTacticTest, chip_test)

auto tactic = std::make_shared<ChipTactic>();
tactic->updateControlParams(robot_position + ball_offset_from_robot, angle_to_kick_at,
5);
2);
setTactic(1, tactic);

std::vector<ValidationFunction> terminating_validation_functions = {
[angle_to_kick_at, tactic](std::shared_ptr<World> world_ptr,
ValidationCoroutine::push_type& yield) {
while (!tactic->done())
{
yield("Tactic did not complete!");
}
ballKicked(angle_to_kick_at, world_ptr, yield);
}};
// std::vector<ValidationFunction> terminating_validation_functions = {
// [angle_to_kick_at, tactic](std::shared_ptr<World> world_ptr,
// ValidationCoroutine::push_type& yield) {
// while (!tactic->done())
// {
// yield("Tactic did not complete!");
// }
// ballKicked(angle_to_kick_at, world_ptr, yield);
// }};
Comment on lines +41 to +49
Copy link
Contributor

Choose a reason for hiding this comment

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

remember to comment this back in


std::vector<ValidationFunction> terminating_validation_functions = {};
std::vector<ValidationFunction> non_terminating_validation_functions = {};

runTest(field_type, ball_state, friendly_robots, enemy_robots,
terminating_validation_functions, non_terminating_validation_functions,
Duration::fromSeconds(5));
Duration::fromSeconds(15));
}

INSTANTIATE_TEST_CASE_P(
BallLocations, ChipTacticTest,
::testing::Values(
// place the ball directly to the left of the robot
std::make_tuple(Vector(0, 0.5), Angle::zero()),
// place the ball directly to the right of the robot
std::make_tuple(Vector(0, -0.5), Angle::zero()),
// place the ball directly infront of the robot
std::make_tuple(Vector(0.5, 0), Angle::zero()),
// place the ball directly behind the robot
std::make_tuple(Vector(-0.5, 0), Angle::zero()),
// place the ball in the robots dribbler
std::make_tuple(Vector(ROBOT_MAX_RADIUS_METERS, 0), Angle::zero()),
// Repeat the same tests but kick in the opposite direction
// place the ball directly to the left of the robot
std::make_tuple(Vector(0, 0.5), Angle::half()),
// place the ball directly to the right of the robot
std::make_tuple(Vector(0, -0.5), Angle::half()),
// place the ball directly infront of the robot
std::make_tuple(Vector(0.5, 0), Angle::half()),
// place the ball directly behind the robot
std::make_tuple(Vector(-0.5, 0), Angle::half()),
// place the ball in the robots dribbler
std::make_tuple(Vector(ROBOT_MAX_RADIUS_METERS, 0), Angle::zero())));
// std::make_tuple(Vector(0, 0.5), Angle::zero()),
// // place the ball directly to the right of the robot
// std::make_tuple(Vector(0, -0.5), Angle::zero())
// // place the ball directly infront of the robot
std::make_tuple(Vector(0.5, 0), Angle::zero())
// // place the ball directly behind the robot
// std::make_tuple(Vector(-0.5, 0), Angle::zero()),
// // place the ball in the robots dribbler
// std::make_tuple(Vector(ROBOT_MAX_RADIUS_METERS, 0), Angle::zero()),
// // Repeat the same tests but kick in the opposite direction
// // place the ball directly to the left of the robot
// std::make_tuple(Vector(0, 0.5), Angle::half()),
// // place the ball directly to the right of the robot
// std::make_tuple(Vector(0, -0.5), Angle::half()),
// // place the ball directly infront of the robot
// std::make_tuple(Vector(0.5, 0), Angle::half()),
// // place the ball directly behind the robot
// std::make_tuple(Vector(-0.5, 0), Angle::half()),
// // place the ball in the robots dribbler
// std::make_tuple(Vector(ROBOT_MAX_RADIUS_METERS, 0), Angle::zero())
));
Comment on lines 62 to +83
Copy link
Contributor

Choose a reason for hiding this comment

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

remember to revert these when you're done

38 changes: 35 additions & 3 deletions src/software/ai/passing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cc_library(
hdrs = ["cost_function.h"],
deps = [
":pass",
":chip_pass",
"//proto/message_translation:tbots_protobuf",
"//software/ai/evaluation:calc_best_shot",
"//software/ai/evaluation:time_to_travel",
Expand Down Expand Up @@ -35,9 +36,30 @@ cc_library(
srcs = ["pass.cpp"],
hdrs = ["pass.h"],
deps = [
":base_pass",
"//shared:constants",
"//software/time:timestamp",
"//software/world:field",
"//software/time:timestamp"
],
)

cc_library(
name = "base_pass",
srcs = ["base_pass.cpp"],
hdrs = ["base_pass.h"],
deps = [
"//software/geom:point",
"//software/time:duration"
],
)

cc_library(
name = "chip_pass",
srcs = ["chip_pass.cpp"],
hdrs = ["chip_pass.h"],
deps = [
":base_pass",
"//shared:constants",
"//software/geom/algorithms"
],
)

Expand All @@ -51,12 +73,22 @@ cc_test(
],
)

cc_test(
name = "chip_pass_test",
srcs = ["chip_pass_test.cpp"],
deps = [
":chip_pass",
"//shared/test_util:tbots_gtest_main",
"//software/test_util",
],
)

cc_library(
name = "pass_with_rating",
srcs = ["pass_with_rating.cpp"],
hdrs = ["pass_with_rating.h"],
deps = [
":pass",
":base_pass",
],
)

Expand Down
Loading