Skip to content

Commit

Permalink
runner?
Browse files Browse the repository at this point in the history
  • Loading branch information
Squid5678 committed Oct 15, 2023
1 parent 49d711e commit f12fee6
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 1 deletion.
2 changes: 1 addition & 1 deletion launch/soccer.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def generate_launch_description():
"""

# LaunchConfiguration objects are like uninitialized variables, e.g.
# > bool run_sim;
# > bool _sim;
# to be later filled in by a LaunchArgument

# output port from field comp's perspective (NetworkRadio only)
Expand Down
82 changes: 82 additions & 0 deletions soccer/src/soccer/strategy/agent/position/runner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "runner.hpp"
#include "planning/instant.hpp"

namespace strategy {

Runner::Runner(int r_id) : Position(r_id) {
position_name_ = "Runner";
}

std::optional<RobotIntent> Runner::derived_get_task(RobotIntent intent) {
latest_state_ = update_state();
return state_to_task(intent);
}

Runner::State Runner::update_state() {
WorldState* world_state = this->world_state();
rj_geometry::Point robot_position = world_state->get_robot(true, robot_id_).pose.position();
switch (latest_state_) {
case IDLING:
initial_position_ = robot_position;
return RUN_FIRST_SIDE;
case RUN_FIRST_SIDE:
if ((robot_position.y() - initial_position_.y()) > kSideLength) {
initial_position_ = robot_position;
return RUN_SECOND_SIDE;
}
case RUN_SECOND_SIDE:
if ((initial_position_.x() - robot_position.x()) > kSideLength) {
initial_position_ = robot_position;
return RUNTHIRDSIDE;
}
case RUN_THIRD_SIDE:
if ((initial_position_.y() - robot_position.y()) > kSideLength) {
initial_position_ = robot_position;
return RUNFOURTHSIDE;
}
case RUN_FOURTH_SIDE:
if ((robot_position.x() - initial_position_.x() > kSideLength)) {
initial_position_ = robot_position;
return IDLING;
}
default:
return latest_state_;
}
}

//produces errors, update to enums - 10/8
std::optional<RobotIntent> Runner::state_to_task(RobotIntent intent) {
planning::LinearMotionInstant target;
switch (latest_state_) {
case IDLING:
return intent;
case RUN_FIRST_SIDE:
target = planning::LinearMotionInstant(
rj_geometry::Point(initial_position_.x(), initial_position_.y() + kSideLength));
intent.motion_command =
planning::MotionCommand{"path_target", target, planning::FaceTarget{}, true};
return intent;
case RUN_SECOND_SIDE:
target = planning::LinearMotionInstant(
rj_geometry::Point(initial_position_.x() - kSideLength, initial_position_.y()));
intent.motion_command =
planning::MotionCommand{"path_target", target, planning::FaceTarget{}, true};
return intent;
case RUN_THIRD_SIDE:
target = planning::LinearMotionInstant(
rj_geometry::Point(initial_position_.x(), initial_position_.y() - kSideLength));
intent.motion_command =
planning::MotionCommand{"path_target", target, planning::FaceTarget{}, true};
return intent;
case RUN_FOURTH_SIDE:
target = planning::LinearMotionInstant(
rj_geometry::Point(initial_position_.x() + kSideLength, initial_position_.y()));
intent.motion_command =
planning::MotionCommand{"path_target", target, planning::FaceTarget{}, true};
return intent;
default:
return intent;
}
}

}
42 changes: 42 additions & 0 deletions soccer/src/soccer/strategy/agent/position/runner.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <rj_common/time.hpp>
#include <rj_geometry/geometry_conversions.hpp>
#include <rj_geometry/point.hpp>

#include "position.hpp"
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_action/rclcpp_action.hpp"
#include "rj_msgs/action/robot_move.hpp"

namespace strategy {

class Runner : public Position {
public:
Runner(int r_id);
~Runner() override = default;

private:
std::optional<RobotIntent> derived_get_task(RobotIntent intent) override;

//did not know this was also in C lol
enum State {
RUN_FIRST_SIDE,
RUN_SECOND_SIDE,
RUN_THIRD_SIDE,
RUN_FOURTH_SIDE,
IDLING,
};

State update_state();

std::optional<RobotIntent> state_to_task(RobotIntent intent);

rj_geometry::Point initial_position_;

State latest_state_ = IDLING;

constexpr static double kSideLength = 1.0;
};

}

0 comments on commit f12fee6

Please sign in to comment.