-
Notifications
You must be signed in to change notification settings - Fork 110
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
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 |
---|---|---|
|
@@ -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" | ||
|
||
using namespace camun::simulator; | ||
|
||
|
@@ -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()} | ||
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. 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 = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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()); | ||
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.
|
||
float chip_speed = static_cast<float>(std::sqrt(numerator / denominator)); | ||
|
||
kick_speed = chip_speed; | ||
LOG(PLOTJUGGLER) << *createPlotJugglerValue({ | ||
{"speed", chip_speed} | ||
}); | ||
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. remember to remove when you're done |
||
kick_angle = chip_angle.toDegrees(); | ||
break; | ||
} | ||
|
@@ -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 = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = | ||
|
@@ -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
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. 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
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. remember to revert these when you're done |
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)); | ||||||
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.
Suggested change
|
||||||
} | ||||||
|
||||||
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; | ||||||
// } | ||||||
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. 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; | ||||||
} |
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 | ||
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. 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
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. this seems a bit of a useless implementation, why not do |
||
|
||
/** | ||
* 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); | ||
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 this declared as a |
||
|
||
/** | ||
* 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; | ||
}; |
There was a problem hiding this comment.
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