blob: 37dc0c7d81c700cb39b9753f860b4fbfa3e485cd [file] [log] [blame]
Brian Silverman17f503e2015-08-02 18:17:18 -07001#ifndef Y2014_ACTORS_SHOOT_ACTOR_H_
2#define Y2014_ACTORS_SHOOT_ACTOR_H_
3
4#include <memory>
5
John Park33858a32018-09-28 23:05:48 -07006#include "aos/actions/actions.h"
Austin Schuhb2461f42019-06-29 18:17:06 -07007#include "aos/actions/actor.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -07008#include "y2014/control_loops/claw/claw_goal_generated.h"
9#include "y2014/control_loops/claw/claw_status_generated.h"
10#include "y2014/control_loops/shooter/shooter_goal_generated.h"
11#include "y2014/control_loops/shooter/shooter_status_generated.h"
Brian Silverman17f503e2015-08-02 18:17:18 -070012
Brian Silvermanb601d892015-12-20 18:24:38 -050013namespace y2014 {
Brian Silverman17f503e2015-08-02 18:17:18 -070014namespace actors {
15
16class ShootActor
Alex Perrycb7da4b2019-08-28 19:35:56 -070017 : public ::aos::common::actions::ActorBase<aos::common::actions::Goal> {
Brian Silverman17f503e2015-08-02 18:17:18 -070018 public:
Philipp Schrader790cb542023-07-05 21:06:52 -070019 typedef ::aos::common::actions::TypedActionFactory<aos::common::actions::Goal>
Austin Schuh1bf8a212019-05-26 22:13:14 -070020 Factory;
21
22 explicit ShootActor(::aos::EventLoop *event_loop);
23
24 static Factory MakeFactory(::aos::EventLoop *event_loop) {
Alex Perrycb7da4b2019-08-28 19:35:56 -070025 return Factory(event_loop, "/shoot_action");
Austin Schuh1bf8a212019-05-26 22:13:14 -070026 }
Brian Silverman17f503e2015-08-02 18:17:18 -070027
28 // Actually execute the action of moving the claw and shooter into position
29 // and actually firing them.
Alex Perrycb7da4b2019-08-28 19:35:56 -070030 bool RunAction(const aos::common::actions::DoubleParam *params) override;
Brian Silverman17f503e2015-08-02 18:17:18 -070031 void InnerRunAction();
32
33 // calc an offset to our requested shot based on robot speed
34 double SpeedToAngleOffset(double speed);
35
36 static constexpr double kOffsetRadians = 0.4;
37 static constexpr double kClawShootingSeparation = 0.10;
38 static constexpr double kClawShootingSeparationGoal = 0.10;
39
40 protected:
41 // completed shot
42 bool DoneShot();
43 // ready for shot
44 bool DonePreShotOpen();
45 // in the right place
46 bool DoneSetupShot();
Austin Schuh493f7af2019-06-29 18:42:12 -070047 bool ShooterIsReady();
Brian Silverman17f503e2015-08-02 18:17:18 -070048
Austin Schuhb2461f42019-06-29 18:17:06 -070049 bool IntakeOff();
50 bool ClawIsReady();
51
52 private:
Alex Perrycb7da4b2019-08-28 19:35:56 -070053 ::aos::Fetcher<::y2014::control_loops::claw::Goal> claw_goal_fetcher_;
54 ::aos::Fetcher<::y2014::control_loops::claw::Status> claw_status_fetcher_;
55 ::aos::Sender<::y2014::control_loops::claw::Goal> claw_goal_sender_;
56 ::aos::Fetcher<::y2014::control_loops::shooter::Status>
Austin Schuh493f7af2019-06-29 18:42:12 -070057 shooter_status_fetcher_;
Alex Perrycb7da4b2019-08-28 19:35:56 -070058 ::aos::Fetcher<::y2014::control_loops::shooter::Goal> shooter_goal_fetcher_;
59 ::aos::Sender<::y2014::control_loops::shooter::Goal> shooter_goal_sender_;
Austin Schuhb2461f42019-06-29 18:17:06 -070060
Brian Silverman17f503e2015-08-02 18:17:18 -070061 // to track when shot is complete
62 int previous_shots_;
63};
64
Brian Silverman17f503e2015-08-02 18:17:18 -070065} // namespace actors
Brian Silvermanb601d892015-12-20 18:24:38 -050066} // namespace y2014
Brian Silverman17f503e2015-08-02 18:17:18 -070067
68#endif // Y2014_ACTORS_SHOOT_ACTOR_H_