QP  0.7-SNAPSHOT
Control software for the ??SRT telescope
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
state.h
1 #ifndef STATE_H_LOADED
2 #define STATE_H_LOADED 1
3 
4 #include "quaternion.h"
5 #include "kalman.h"
6 #include "qp.h"
7 #include "types.h"
8 
9 // Angular speeds in this the Schedule subclasses are in rad/s; speeds
10 // in the State class are either in rad/s or in 'fractional' speeds,
11 // which are speeds expressed as a fraction of the drive's maximum
12 // speed. This maximum speed is discovered (starting with an initial
13 // estimate) by the Kalman filters within the State object.
14 
15 class State;
16 
24 class Schedule {
25  protected:
27  double phidot_;
30  double thetadot_;
31 
32  Schedule();
33 
34  public:
44  virtual ms_t step(double current_phi, double current_theta, ms_t t) = 0;
45 
51  double phidot(void) const { return phidot_; }
52 
58  double thetadot(void) const { return thetadot_; }
59 
60 #if PROVARINO
61  virtual std::ostream& tostream(std::ostream& strm) const = 0;
62 #endif
63 };
64 
72 class SlewSchedule : public Schedule
73 {
74 private:
75  float target_phi_; // the longitude we're aiming for
76  // (+ve eastwards, rad, may be outside of [0,2pi])
77  float target_theta_; // altitude (rad, less than pi/2)
78  ms_t full_speed_time_; // time we aim to be at full speed
79  bool route_planned_p_; // have we worked out the route?
80  bool schedule_ok_p_; // is this a feasible schedule?
81 
82  double calculate_angdot(double remaining_angle, ms_t current_time);
83 
84  public:
85  SlewSchedule(const Position& target);
86  ms_t step(double current_phi, double current_theta, ms_t t);
89  bool schedule_ok() const { return schedule_ok_p_; };
90 
91 #if PROVARINO
92  std::ostream& tostream(std::ostream& strm) const;
93 #endif
94 };
95 
100 class TrackingSchedule : public Schedule {
101  private:
102  // initial_ and initial_step_ are 'almost' const, but they're not
103  // initialised until the first call to step(), so can't be
104  // labelled const
105  Quaternion initial_; // where the rotation is from
106  ms_t initial_step_; // the time of the first step
107  double maximum_angle_; // the maximum angle we may move before encountering a stop
108 
109  Quaternion axis_; // the axis being rotated about
110  double hdot_; // the intended rotation speed in rad/ms
111 
112  public:
113  TrackingSchedule(const Quaternion& axis,
114  double hdot,
115  Position observatory);
116 
117  ms_t step(double current_phi, double current_theta, ms_t t);
118  double speed(void);
119 
120  float limit_tracking(Quaternion& actual, const TelescopeController*);
121 
122 #if PROVARINO
123  std::ostream& tostream(std::ostream& strm) const;
124 #endif
125 };
126 
131 class State {
132 private:
137  Schedule* schedule;
138  // schedule is not const, because we will occasionally
139  // (in set_schedule()) update a current state with a new schedule/goal
140 
141  Quaternion to_observatory;
142 
143 public:
144  State(// const Quaternion& initial,
145  // const Position& initial_max_speed,
146  Schedule* schedule,
147  const ms_t current_time,
148  const Position* obs=NULL);
149 
150  State();
151 
152  ms_t step(ms_t t);
153  void alt_click(ms_t t, double current_speed, double angle);
154  void az_click(ms_t t, double current_speed, double angle);
155  double suggested_phidot_frac(void);
156  double suggested_thetadot_frac(void);
157 
158  void set_schedule(Schedule*);
159 
166  //Kalman* kalman_phi() { return φ }
171  //Kalman* kalman_theta() { return θ }
172 
173  // Quaternion T(void) const;
174  // Position position(Position::System);
175 };
176 
177 #if PROVARINO
178 std::ostream& operator<<(std::ostream& strm, const State& s);
179 std::ostream& operator<<(std::ostream& strm, const Schedule& s);
180 #endif
181 #endif /* STATE_H_LOADED */
double suggested_thetadot_frac(void)
Return the suggested rate of change in altitude, in units of fractional speed.
Definition: state.cpp:630
double suggested_phidot_frac(void)
Return the suggested rate of change in longitude, in units of fractional speed.
Definition: state.cpp:612
The State class holds the state of the system while it is slewing or tracking.
Definition: state.h:131
double phidot_
Suggested rate of change of phi (azimuthal coordinate, rad/s)
Definition: state.h:27
The Quaternion class encapsulates quaternions (quelle surprise!), and provides a small set of operati...
Definition: quaternion.h:29
ms_t step(ms_t t)
Retrospectively update the state by incrementally rotating the pointing.
Definition: state.cpp:575
virtual ms_t step(double current_phi, double current_theta, ms_t t)=0
Update the schedule with the current position of the system.
Provides the schedule for tracking a point across the celestial sphere, typically at a speed of one s...
Definition: state.h:100
The Position class allows us to represent positions on the celestial sphere (or on Earth...
Definition: position.h:15
float limit_tracking(Quaternion &actual, const TelescopeController *)
Establish the bounds of the permitted movement of the telescope.
Definition: state.cpp:368
SlewSchedule(const Position &target)
Construct an instance of this schedule.
Definition: state.cpp:36
void az_click(ms_t t, double current_speed, double angle)
Return the current pointing of the state, as a vector in AzAlt coordinates.
Definition: state.cpp:542
Provides the schedule for a slew to a particular point on the celestial sphere.
Definition: state.h:72
A class for controlling the telescope.
Definition: qp.h:11
double phidot(void) const
Obtain the suggested azimuthal angular speed.
Definition: state.h:51
double thetadot_
Suggested rate of change of theta (altitude coordinate, rad/s).
Definition: state.h:30
double speed(void)
Returns the rotation speed of the schedule, in rad/s.
Definition: state.cpp:360
double thetadot(void) const
Obtain the suggested altitudinal angular speed.
Definition: state.h:58
void alt_click(ms_t t, double current_speed, double angle)
Report a click in altitude.
Definition: state.cpp:555
bool schedule_ok() const
Is this a feasible schedule? Return false if it would end up in the empty sector. ...
Definition: state.h:89
ms_t step(double current_phi, double current_theta, ms_t t)
Update the schedule with the current position of the system.
Definition: state.cpp:273
The Schedule class represents a planned rotation of the telescope.
Definition: state.h:24
State()
No-arg constructor.
Definition: state.cpp:472
TrackingSchedule(const Quaternion &axis, double hdot, Position observatory)
Initialise a schedule which tracks a point in a rotation about a given axis.
Definition: state.cpp:250
void set_schedule(Schedule *)
Sets the schedule which the state is to follow.
Definition: state.cpp:482
ms_t step(double current_phi, double current_theta, ms_t t)
Take a step on the slewing path.
Definition: state.cpp:161