-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from ibis-ssl/feature/kickoff
Kickoff動作を作る
- Loading branch information
Showing
11 changed files
with
252 additions
and
15 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: code amount | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
|
||
jobs: | ||
spell-check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: install cloc | ||
run: sudo apt-get install -y cloc | ||
|
||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run cloc | ||
run: cloc . --vcs=git |
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
76 changes: 76 additions & 0 deletions
76
crane_robot_skills/include/crane_robot_skills/kickoff_attack.hpp
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,76 @@ | ||
// Copyright (c) 2024 ibis-ssl | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
#ifndef CRANE_ROBOT_SKILLS__KICKOFF_ATTACK_HPP_ | ||
#define CRANE_ROBOT_SKILLS__KICKOFF_ATTACK_HPP_ | ||
|
||
#include <crane_geometry/eigen_adapter.hpp> | ||
#include <crane_robot_skills/go_over_ball.hpp> | ||
#include <crane_robot_skills/skill_base.hpp> | ||
|
||
namespace crane::skills | ||
{ | ||
enum class KickoffAttackState { | ||
PREPARE_KICKOFF, | ||
KICKOFF, | ||
}; | ||
class KickoffAttack : public SkillBase<KickoffAttackState> | ||
{ | ||
public: | ||
explicit KickoffAttack(uint8_t id, const std::shared_ptr<WorldModelWrapper> & world_model) | ||
: SkillBase<KickoffAttackState>( | ||
"KickoffAttack", id, world_model, KickoffAttackState::PREPARE_KICKOFF) | ||
{ | ||
setParameter("target_x", 0.0f); | ||
setParameter("target_y", 1.0f); | ||
setParameter("kick_power", 0.5); | ||
addStateFunction( | ||
KickoffAttackState::PREPARE_KICKOFF, | ||
[this]( | ||
const std::shared_ptr<WorldModelWrapper> & world_model, | ||
const std::shared_ptr<RobotInfo> & robot, crane::RobotCommandWrapper & command, | ||
ConsaiVisualizerWrapper::SharedPtr visualizer) -> Status { | ||
if (not go_over_ball) { | ||
go_over_ball = std::make_shared<GoOverBall>(robot->id, world_model); | ||
go_over_ball->setParameter("next_target_x", getParameter<double>("target_x")); | ||
go_over_ball->setParameter("next_target_y", getParameter<double>("target_y")); | ||
go_over_ball->setParameter("margin", 0.3); | ||
command.setMaxVelocity(0.5); | ||
} | ||
go_over_ball_status = go_over_ball->run(command, visualizer); | ||
return Status::RUNNING; | ||
}); | ||
addTransition( | ||
KickoffAttackState::PREPARE_KICKOFF, KickoffAttackState::KICKOFF, | ||
[this]() -> bool { return go_over_ball_status == Status::SUCCESS; }); | ||
|
||
addStateFunction( | ||
KickoffAttackState::KICKOFF, | ||
[this]( | ||
const std::shared_ptr<WorldModelWrapper> & world_model, | ||
const std::shared_ptr<RobotInfo> & robot, crane::RobotCommandWrapper & command, | ||
ConsaiVisualizerWrapper::SharedPtr visualizer) -> Status { | ||
command.setMaxVelocity(0.5); | ||
command.kickStraight(getParameter<double>("kick_power")); | ||
command.setTargetPosition(world_model->ball.pos); | ||
command.setTerminalVelocity(0.5); | ||
if (world_model->ball.vel.norm() > 0.3) { | ||
return Status::SUCCESS; | ||
} else { | ||
return Status::RUNNING; | ||
} | ||
}); | ||
} | ||
|
||
void print(std::ostream & os) const override { os << "[KickoffAttack]"; } | ||
|
||
private: | ||
std::shared_ptr<GoOverBall> go_over_ball = nullptr; | ||
|
||
Status go_over_ball_status = Status::RUNNING; | ||
}; | ||
} // namespace crane::skills | ||
#endif // CRANE_ROBOT_SKILLS__KICKOFF_ATTACK_HPP_ |
39 changes: 39 additions & 0 deletions
39
crane_robot_skills/include/crane_robot_skills/kickoff_support.hpp
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,39 @@ | ||
// Copyright (c) 2024 ibis-ssl | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
#ifndef CRANE_ROBOT_SKILLS__KICKOFF_SUPPORT_HPP_ | ||
#define CRANE_ROBOT_SKILLS__KICKOFF_SUPPORT_HPP_ | ||
|
||
#include <crane_geometry/eigen_adapter.hpp> | ||
#include <crane_robot_skills/skill_base.hpp> | ||
|
||
namespace crane::skills | ||
{ | ||
class KickoffSupport : public SkillBase<> | ||
{ | ||
public: | ||
explicit KickoffSupport(uint8_t id, const std::shared_ptr<WorldModelWrapper> & world_model) | ||
: SkillBase<>("KickoffSupport", id, world_model, DefaultStates::DEFAULT) | ||
{ | ||
setParameter("target_x", 0.0f); | ||
setParameter("target_y", 1.0f); | ||
addStateFunction( | ||
DefaultStates::DEFAULT, | ||
[this]( | ||
const std::shared_ptr<WorldModelWrapper> & world_model, | ||
const std::shared_ptr<RobotInfo> & robot, RobotCommandWrapper & command, | ||
ConsaiVisualizerWrapper::SharedPtr visualizer) -> Status { | ||
Point target(getParameter<double>("target_x"), getParameter<double>("target_y")); | ||
command.setTargetPosition(target); | ||
command.lookAtBallFrom(target); | ||
return Status::RUNNING; | ||
}); | ||
} | ||
|
||
void print(std::ostream & os) const override { os << "[KickoffSupport]"; } | ||
}; | ||
} // namespace crane::skills | ||
#endif // CRANE_ROBOT_SKILLS__KICKOFF_SUPPORT_HPP_ |
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
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
93 changes: 93 additions & 0 deletions
93
session/crane_planner_plugins/include/crane_planner_plugins/our_kickoff_planner.hpp
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,93 @@ | ||
// Copyright (c) 2024 ibis-ssl | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
#ifndef CRANE_PLANNER_PLUGINS__OUR_KICKOFF_PLANNER_HPP_ | ||
#define CRANE_PLANNER_PLUGINS__OUR_KICKOFF_PLANNER_HPP_ | ||
|
||
#include <crane_geometry/boost_geometry.hpp> | ||
#include <crane_msg_wrappers/world_model_wrapper.hpp> | ||
#include <crane_msgs/srv/robot_select.hpp> | ||
#include <crane_planner_base/planner_base.hpp> | ||
#include <crane_robot_skills/kickoff_attack.hpp> | ||
#include <crane_robot_skills/kickoff_support.hpp> | ||
#include <functional> | ||
#include <memory> | ||
#include <rclcpp/rclcpp.hpp> | ||
|
||
#include "visibility_control.h" | ||
|
||
namespace crane | ||
{ | ||
class OurKickOffPlanner : public PlannerBase | ||
{ | ||
private: | ||
std::shared_ptr<skills::KickoffAttack> kickoff_attack; | ||
std::shared_ptr<RobotCommandWrapper> attacker_command; | ||
|
||
std::shared_ptr<skills::KickoffSupport> kickoff_support; | ||
std::shared_ptr<RobotCommandWrapper> supporter_command; | ||
|
||
// std::shared_ptr<ConsaiVisualizerWrapper> visualizer; | ||
|
||
public: | ||
COMPOSITION_PUBLIC explicit OurKickOffPlanner( | ||
WorldModelWrapper::SharedPtr & world_model, ConsaiVisualizerWrapper::SharedPtr visualizer) | ||
: PlannerBase("our_kickoff_planner", world_model, visualizer) | ||
{ | ||
} | ||
|
||
std::pair<Status, std::vector<crane_msgs::msg::RobotCommand>> calculateRobotCommand( | ||
const std::vector<RobotIdentifier> & robots) override | ||
{ | ||
std::vector<crane_msgs::msg::RobotCommand> robot_commands; | ||
|
||
kickoff_attack->run(*attacker_command, visualizer); | ||
kickoff_support->run(*supporter_command, visualizer); | ||
|
||
robot_commands.emplace_back(attacker_command->getMsg()); | ||
robot_commands.emplace_back(supporter_command->getMsg()); | ||
|
||
// いい感じにSUCCESSも返す | ||
return {PlannerBase::Status::RUNNING, robot_commands}; | ||
} | ||
|
||
auto getSelectedRobots( | ||
uint8_t selectable_robots_num, const std::vector<uint8_t> & selectable_robots) | ||
-> std::vector<uint8_t> override | ||
{ | ||
// 一番ボールに近いロボットをkickoff attack | ||
auto best_attacker = std::max_element( | ||
selectable_robots.begin(), selectable_robots.end(), [this](const auto & a, const auto & b) { | ||
return world_model->getOurRobot(a)->getDistance(world_model->ball.pos) < | ||
world_model->getOurRobot(b)->getDistance(world_model->ball.pos); | ||
}); | ||
Point supporter_pos{0.0, 2.0}; | ||
auto best_supporter = std::max_element( | ||
selectable_robots.begin(), selectable_robots.end(), | ||
[this, supporter_pos, best_attacker](const auto & a, const auto & b) { | ||
if (a == *best_attacker) { | ||
// bの方大きい => best_attackerであるaが除外される | ||
return true; | ||
} else if (b == *best_attacker) { | ||
// bの方大きくない => best_attackerであるbが除外される | ||
return false; | ||
} else { | ||
return world_model->getOurRobot(a)->getDistance(supporter_pos) < | ||
world_model->getOurRobot(b)->getDistance(supporter_pos); | ||
} | ||
}); | ||
|
||
kickoff_attack = std::make_shared<skills::KickoffAttack>(*best_attacker, world_model); | ||
attacker_command = std::make_shared<RobotCommandWrapper>(*best_attacker, world_model); | ||
kickoff_support = std::make_shared<skills::KickoffSupport>(*best_supporter, world_model); | ||
supporter_command = std::make_shared<RobotCommandWrapper>(*best_supporter, world_model); | ||
|
||
return {*best_attacker, *best_supporter}; | ||
} | ||
}; | ||
|
||
} // namespace crane | ||
#endif // CRANE_PLANNER_PLUGINS__OUR_KICKOFF_PLANNER_HPP_ |
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
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