-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
|
||
} |