QP  0.7-SNAPSHOT
Control software for the ??SRT telescope
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
activities.h
1 #ifndef ACTIVITIES_H_LOADED
2 #define ACTIVITIES_H_LOADED 1
3 
4 #include "types.h"
5 #include "state.h"
6 #include "qp.h"
7 
16 class Activity {
17  friend class ActivityQueue;
18 
19  public:
26  enum ActivityTypes { BaseActivity,
27  CalibrationActivity,
28  ScheduleFollowingActivity,
29  DriveAzAltActivity,
30  TrackSiderealActivity,
31  TrackAzimuthActivity, };
32 
33  private:
34  const ActivityTypes type_;
35  Activity* next_;
36 
37  protected:
39  State* const state; // const pointer to non-const State
40 
45  TelescopeController* const controller; // const pointer to non-const controller
46 
55 #define ACTIVITY_STATUS_COMPLETE 1
56 #define ACTIVITY_STATUS_INVALID 1<<1
57  // /**
58  // * Set to true by a derived class when its work is done.
59  // * @see is_complete
60  // */
61  // bool complete_p;
62 
64  void mark_as_complete(void) { activity_status |= ACTIVITY_STATUS_COMPLETE; }
66  void mark_as_invalid(void) {
67  activity_status |= (ACTIVITY_STATUS_COMPLETE | ACTIVITY_STATUS_INVALID);
68  }
69 
71 
72  public:
80  virtual void az_click(ms_t t, double azimuth);
81 
89  virtual void alt_click(ms_t t, double altitude);
90 
98  virtual void at_endstop(ms_t t, int az_click_count, int alt_click_count) = 0;
99 
101  bool is_complete(void) const { return activity_status & ACTIVITY_STATUS_COMPLETE; }
102 
104  bool is_valid(void) const { return ! (activity_status & ACTIVITY_STATUS_INVALID); }
105 
107  virtual void cancel(void);
108 
109  // The following is necessary because on the Arduino, there is no RTTI, so no dynamic_cast.
111  ActivityTypes type(void) { return type_; }
112 
121  virtual ms_t start(ms_t now) { return TIME_NEVER; }
122 
131  virtual ms_t poke(ms_t t) { return TIME_NEVER; };
132 
133  static void* operator new (size_t size);
134  static void operator delete (void *p);
135  // overriding delete requires (I think) that we define destructors
136  virtual ~Activity();
137 
138  static int max_activities(void);
139  static int n_activities(void);
140  static void delete_all_allocations(void);
141 };
142 
146 class Calibration : public Activity {
147  private:
148  ms_t reftime;
149  ms_t time_az1, time_az2, time_alt1, time_alt2;
150  signed int cal_count;
151  enum {ph_position,
152  ph_az_forward, ph_az_backward,
153  ph_alt_upward, ph_alt_downward} phase;
154 
155 
156  public:
159  ~Calibration();
160 
161  ms_t start(ms_t);
162  void az_click(ms_t t, double);
163  void alt_click(ms_t t, double);
164  void at_endstop(ms_t t, int az_click_count, int alt_click_count);
165  double clicks_per_sec_az(void);
166  double clicks_per_sec_alt(void);
167 };
168 
173 class ScheduleFollowing : public Activity {
174  protected:
177  virtual ~ScheduleFollowing() = 0;
178 
179  public:
180  virtual ms_t start(ms_t);
181  virtual void cancel(void);
182  virtual ms_t poke(ms_t t);
183  //virtual void az_click(ms_t t, double);
184  //virtual void alt_click(ms_t t, double);
185  virtual void at_endstop(ms_t t, int az_click_count, int alt_click_count);
186 };
187 
192  private:
193  SlewSchedule schedule;
194 
195  public:
196  DriveAzAlt(TelescopeController*, State*, double phi, double theta);
197  ~DriveAzAlt();
198  ms_t start(ms_t);
199 };
200 
205  private:
206  TrackingSchedule schedule;
207 
208  public:
209  TrackSidereal(TelescopeController*, State*, Position obs, double speed=0.0);
210  ~TrackSidereal();
211  ms_t start(ms_t);
212 };
213 
219  private:
220  TrackingSchedule schedule;
221 
222  public:
223  TrackAzimuth(TelescopeController*, State*, double speed);
224  ~TrackAzimuth();
225  ms_t start(ms_t);
226 };
227 
232  private:
233  Activity* head_;
234 
235  public:
236  ActivityQueue();
237  Activity* current() const;
238  Activity* next();
239  void append(Activity*);
240  void replace(Activity*);
241  void cancel(void);
242 };
243 
244 #endif /* ACTIVITIES_H_LOADED */
void at_endstop(ms_t t, int az_click_count, int alt_click_count)
The method called when the system detects a timeout, at the limit of an axis's travel.
Definition: activities.cpp:184
Activity: track a point on the celestial sphere through a sidereal rotation.
Definition: activities.h:204
virtual void az_click(ms_t t, double azimuth)
The method called when the system detects an azimuthal click.
Definition: activities.cpp:64
The State class holds the state of the system while it is slewing or tracking.
Definition: state.h:131
void replace(Activity *)
Replace any activities in the queue.
Definition: activities.cpp:675
State *const state
The state which we are to manipulate.
Definition: activities.h:39
void cancel(void)
Cancel all the activities in the queue.
Definition: activities.cpp:661
Calibrating.
Definition: activities.h:146
TelescopeController *const controller
The controller object provides methods for physically moving the telescope.
Definition: activities.h:45
Calibration(TelescopeController *, State *)
Create a calibration instance.
Definition: activities.cpp:74
static int n_activities(void)
Return the number of currently allocated activities.
Definition: activities.cpp:495
ScheduleFollowing(TelescopeController *, State *, ActivityTypes)
Create an instance of the activity.
Definition: activities.cpp:262
virtual void cancel(void)
Cancel the activity.
Definition: activities.cpp:268
byte activity_status
The internal status of the object: complete / invalid.
Definition: activities.h:54
double clicks_per_sec_az(void)
Return the relationship between applied motor power and angular speed, for the azimuthal motor...
Definition: activities.cpp:247
Activity: Driving the telescope to a given AzAlt location.
Definition: activities.h:191
virtual ms_t poke(ms_t t)
From time to time, the main loop will 'poke' this activity, by calling this function.
Definition: activities.h:131
ms_t start(ms_t)
The activity will be started by the main loop calling the start function.
Definition: activities.cpp:451
virtual void cancel(void)
Cancel the activity.
Definition: activities.cpp:56
ActivityTypes type(void)
Return the type of Activity.
Definition: activities.h:111
virtual void at_endstop(ms_t t, int az_click_count, int alt_click_count)=0
The method called when the system detects a timeout, at the limit of an axis's travel.
virtual ms_t start(ms_t)
The activity will be started by the main loop calling the start function.
Definition: activities.cpp:273
TrackAzimuth(TelescopeController *, State *, double speed)
Create a new activity which tracks across the sky in azimuth.
Definition: activities.cpp:435
void append(Activity *)
Appends the given activity to the end of the queue.
Definition: activities.cpp:685
void mark_as_invalid(void)
Mark the activity as invalid.
Definition: activities.h:66
The Activity abstract class encapsulates the state for extended projects, such as calibrations...
Definition: activities.h:16
ActivityTypes
The activity types here correspond to the this class and its subclasses.
Definition: activities.h:26
ActivityQueue()
Maintain a queue of upcoming activities.
Definition: activities.cpp:621
bool is_complete(void) const
Return true if the activity is complete.
Definition: activities.h:101
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
void mark_as_complete(void)
Set to true by a derived class when its work is done.
Definition: activities.h:64
Provides the schedule for a slew to a particular point on the celestial sphere.
Definition: state.h:72
virtual ms_t start(ms_t now)
The activity will be started by the main loop calling the start function.
Definition: activities.h:121
A class for controlling the telescope.
Definition: qp.h:11
bool is_valid(void) const
Return true if the activity is valid.
Definition: activities.h:104
static int max_activities(void)
Return the maximum number of activities it's possible to have allocated at one time.
Definition: activities.cpp:485
Activity(TelescopeController *, State *, ActivityTypes)
Construct an activity base-class.
Definition: activities.cpp:45
static void delete_all_allocations(void)
Delete all activity allocations.
Definition: activities.cpp:605
Maintain a queue of Activity instances.
Definition: activities.h:231
ms_t start(ms_t)
The activity will be started by the main loop calling the start function.
Definition: activities.cpp:422
Activity * next()
Return the next activity.
Definition: activities.cpp:645
TrackSidereal(TelescopeController *, State *, Position obs, double speed=0.0)
Create a tracking activity.
Definition: activities.cpp:398
Track across the sky in azimuth.
Definition: activities.h:218
double clicks_per_sec_alt(void)
Return the relationship between applied motor power and angular speed, for the azimuthal motor...
Definition: activities.cpp:257
void alt_click(ms_t t, double)
The method called when the system detects an altitude click.
Definition: activities.cpp:151
ms_t start(ms_t)
The activity will be started by the main loop calling the start function.
Definition: activities.cpp:108
ms_t start(ms_t)
The activity will be started by the main loop calling the start function.
Definition: activities.cpp:369
virtual ms_t poke(ms_t t)
From time to time, the main loop will 'poke' this activity, by calling this function.
Definition: activities.cpp:278
Activity * current() const
Return the current activity.
Definition: activities.cpp:632
void az_click(ms_t t, double)
The method called when the system detects an azimuthal click.
Definition: activities.cpp:117
The base of a couple of classes where the activity consists of following a schedle of rotations...
Definition: activities.h:173
virtual void at_endstop(ms_t t, int az_click_count, int alt_click_count)
The method called when the system detects a timeout, at the limit of an axis's travel.
Definition: activities.cpp:340
virtual void alt_click(ms_t t, double altitude)
The method called when the system detects an altitude click.
Definition: activities.cpp:69
DriveAzAlt(TelescopeController *, State *, double phi, double theta)
Provide the target to drive to.
Definition: activities.cpp:358