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 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
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
8 changes: 8 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,10 @@ 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()}
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 remove this when you're done

});
if (p.z() < static_cast<float>(BALL_MAX_RADIUS_METERS) * 1.1f * SIMULATOR_SCALE)
{ // ball is on the ground
bool is_stationary =
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 @@ -162,6 +162,7 @@ cc_library(
"//shared:robot_constants",
"//software/geom:angle",
"//software/logger",
"//proto/message_translation:tbots_protobuf"
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "shared/constants.h"
#include "software/geom/angle.h"
#include "software/logger/logger.h"
#include "proto/message_translation/tbots_protobuf.h"

// Converts rpm and wheel_radius_meters [m] to speed [m/s]
float rpm_to_m_per_s(float rpm, float wheel_radius_meters)
Expand Down Expand Up @@ -79,10 +80,13 @@ std::unique_ptr<SSLSimulationProto::RobotCommand> getRobotCommandFromDirectContr
float numerator =
range *
static_cast<float>(ACCELERATION_DUE_TO_GRAVITY_METERS_PER_SECOND_SQUARED);
float denominator = static_cast<float>(2.0f * (chip_angle * 2.0f).sin());
float denominator = static_cast<float>(2.0f * (chip_angle * 2.0f).22());
Copy link
Contributor

Choose a reason for hiding this comment

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

.22()?

float chip_speed = static_cast<float>(std::sqrt(numerator / denominator));

kick_speed = chip_speed;
LOG(PLOTJUGGLER) << *createPlotJugglerValue({
{"speed", chip_speed}
});
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 remove when you're done

kick_angle = chip_angle.toDegrees();
break;
}
Expand Down Expand Up @@ -115,7 +119,7 @@ std::unique_ptr<SSLSimulationProto::RobotCommand> getRobotCommandFromDirectContr
float numerator =
range *
static_cast<float>(
ACCELERATION_DUE_TO_GRAVITY_METERS_PER_SECOND_SQUARED);
ACCELERATION_DUE_TO_GRAVITY_METERS_PER_SECOND_SQUARED);
float denominator =
static_cast<float>(2.0f * (chip_angle * 2.0f).sin());
float chip_speed =
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
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

34 changes: 32 additions & 2 deletions src/software/ai/passing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,29 @@ 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"
],
)

Expand All @@ -51,6 +71,16 @@ 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"],
Expand Down
49 changes: 49 additions & 0 deletions src/software/ai/passing/base_pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "software/ai/passing/base_pass.h"

BasePass::BasePass(Point passer_point, Point receiver_point)
: passer_point(passer_point),
receiver_point(receiver_point) {}

Point BasePass::receiverPoint() const
{
return receiver_point;
}

Angle BasePass::receiverOrientation() const
{
return (passerPoint() - receiverPoint()).orientation();
}

Angle BasePass::passerOrientation() const
{
return (receiverPoint() - passerPoint()).orientation();
}

Point BasePass::passerPoint() const
{
return passer_point;
}

double BasePass::length() const
{
return std::sqrt(std::pow(receiverPoint().x() - passerPoint().x(), 2) + std::pow(receiverPoint().y() - passerPoint().y(), 2));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return std::sqrt(std::pow(receiverPoint().x() - passerPoint().x(), 2) + std::pow(receiverPoint().y() - passerPoint().y(), 2));
return (receiverPoint() - passerPoint()).length()

}

std::array<double, NUM_PARAMS_TO_OPTIMIZE> BasePass::toPassArray() const
{
return {receiver_point.x(), receiver_point.y()};
}

// std::ostream& printHelper(std::ostream& output_stream, const BasePass& pass)
// {
// output_stream << "Pass from " << pass.passer_point
// << " to: " << pass.receiver_point;

// return output_stream;
// }
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 remove this when you're done


bool BasePass::operator==(const BasePass& other) const
{
return this->passer_point == other.passer_point &&
this->receiver_point == other.receiver_point;
}
109 changes: 109 additions & 0 deletions src/software/ai/passing/base_pass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#pragma once

#include <array>
#include <cstdlib>
#include <iostream>

#include "software/geom/point.h"
#include "software/time/duration.h"


// The number of parameters (representing a pass) that we optimize
// (receive_location_x, receive_location_y)
static const int NUM_PARAMS_TO_OPTIMIZE = 2;

class BasePass
Copy link
Contributor

Choose a reason for hiding this comment

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

missing class docs

{
public:
BasePass() = delete;

/**
* Gets the value of the passer point
*
* @return The value of the passer point
*/
Point passerPoint() const;

/**
* Gets the value of the receiver point
*
* @return The value of the receiver point
*/
Point receiverPoint() const;

/**
* Given the ball position, returns the angle the receiver should be
* facing to receive the pass.
*
* @return The angle the receiver should be facing
*/
Angle receiverOrientation() const;

/**
* Given the ball position, returns the angle the passer should be
* facing to pass.
*
* @return The angle the passer should be facing
*/
Angle passerOrientation() const;

/**
* Gets the length of the pass in metres
*
* @return The length of the pass in metres
*/
double length() const;

/**
* Estimate how long the pass will take, from kicking to receiving
*
* This estimate does not account for friction on the ball
*
* @return An estimate of how long the pass will take, from kicking to receiving
*/
virtual Duration estimatePassDuration() const
{
return Duration::fromSeconds(0);
}
Comment on lines +67 to +70
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems a bit of a useless implementation, why not do virtual Duration estimatePassDuration() const = 0?


/**
* Converts a pass to an array
*
* @returns the pass array: [receiver_point.x(), receiver_point.y()]
*/
std::array<double, NUM_PARAMS_TO_OPTIMIZE> toPassArray() const;

protected:
/**
* Create a pass with given parameters
*
* @param passer_point The point the pass should start at
* @param receiver_point The point the receiver should be at to receive the pass
*/
BasePass(Point passer_point, Point receiver_point);

/**
// * Implement the "<<" operator for printing
// *
// * @param output_stream The stream to print to
// * @param pass The pass to print
// * @return The output stream with the string representation of the class appended
// */
// friend std::ostream& printHelper(std::ostream& output_stream, const BasePass& pass);
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this declared as a friend function?


/**
* Compares Passes for equality. Passes are considered
* equal if all their member variables are equal.
*
* @param other the Pass to compare with for equality
*
* @return true if the Passes are equal and false otherwise
*/
virtual bool operator==(const BasePass& other) const;

// The location of the passer
Point passer_point;

// The location of the receiver
Point receiver_point;
};
Loading
Loading