blob: 88a2358924defdf669f41f0a580bf59564c89cad [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:
Austin Schuh1bf8a212019-05-26 22:13:14 -070019 typedef ::aos::common::actions::TypedActionFactory<
Alex Perrycb7da4b2019-08-28 19:35:56 -070020 aos::common::actions::Goal>
Austin Schuh1bf8a212019-05-26 22:13:14 -070021 Factory;
22
23 explicit ShootActor(::aos::EventLoop *event_loop);
24
25 static Factory MakeFactory(::aos::EventLoop *event_loop) {
Alex Perrycb7da4b2019-08-28 19:35:56 -070026 return Factory(event_loop, "/shoot_action");
Austin Schuh1bf8a212019-05-26 22:13:14 -070027 }
Brian Silverman17f503e2015-08-02 18:17:18 -070028
29 // Actually execute the action of moving the claw and shooter into position
30 // and actually firing them.
Alex Perrycb7da4b2019-08-28 19:35:56 -070031 bool RunAction(const aos::common::actions::DoubleParam *params) override;
Brian Silverman17f503e2015-08-02 18:17:18 -070032 void InnerRunAction();
33
34 // calc an offset to our requested shot based on robot speed
35 double SpeedToAngleOffset(double speed);
36
37 static constexpr double kOffsetRadians = 0.4;
38 static constexpr double kClawShootingSeparation = 0.10;
39 static constexpr double kClawShootingSeparationGoal = 0.10;
40
41 protected:
42 // completed shot
43 bool DoneShot();
44 // ready for shot
45 bool DonePreShotOpen();
46 // in the right place
47 bool DoneSetupShot();
Austin Schuh493f7af2019-06-29 18:42:12 -070048 bool ShooterIsReady();
Brian Silverman17f503e2015-08-02 18:17:18 -070049
Austin Schuhb2461f42019-06-29 18:17:06 -070050 bool IntakeOff();
51 bool ClawIsReady();
52
53 private:
Alex Perrycb7da4b2019-08-28 19:35:56 -070054 ::aos::Fetcher<::y2014::control_loops::claw::Goal> claw_goal_fetcher_;
55 ::aos::Fetcher<::y2014::control_loops::claw::Status> claw_status_fetcher_;
56 ::aos::Sender<::y2014::control_loops::claw::Goal> claw_goal_sender_;
57 ::aos::Fetcher<::y2014::control_loops::shooter::Status>
Austin Schuh493f7af2019-06-29 18:42:12 -070058 shooter_status_fetcher_;
Alex Perrycb7da4b2019-08-28 19:35:56 -070059 ::aos::Fetcher<::y2014::control_loops::shooter::Goal> shooter_goal_fetcher_;
60 ::aos::Sender<::y2014::control_loops::shooter::Goal> shooter_goal_sender_;
Austin Schuhb2461f42019-06-29 18:17:06 -070061
Brian Silverman17f503e2015-08-02 18:17:18 -070062 // to track when shot is complete
63 int previous_shots_;
64};
65
Brian Silverman17f503e2015-08-02 18:17:18 -070066} // namespace actors
Brian Silvermanb601d892015-12-20 18:24:38 -050067} // namespace y2014
Brian Silverman17f503e2015-08-02 18:17:18 -070068
69#endif // Y2014_ACTORS_SHOOT_ACTOR_H_