vrpn  07.33
Virtual Reality Peripheral Network
vrpn_IDEA.h
Go to the documentation of this file.
1 #ifndef VRPN_IDEA_H
2 #define VRPN_IDEA_H
3 
4 //------------------------------------------------------------------------------
5 // Driver for the Haydon-Kerk IDEA PCM4806X motor controller.
6 // This assumes that the operating system has provided a virtual COM port
7 // for the device, so that it can be opened as a serial device. Both
8 // Windows 7 and Ubuntu Linux provided this by default as of 8/6/2012.
9 // This driver does not support the daisy-chained configuration of the
10 // devices (which is available for RS-485 devices). If you do not find
11 // the serial device, you may need to install the device driver for the FTDI
12 // chipset it uses under Windows.
13 
14 // See http://www.haydonkerk.com/LinkClick.aspx?fileticket=LEcwYeRmKVg%3d&tabid=331
15 // for the software manual for this device.
16 
17 #include "vrpn_Analog.h" // for vrpn_Serial_Analog
18 #include "vrpn_Button.h" // for vrpn_Button_Filter
19 #include "vrpn_Analog_Output.h" // for vrpn_Analog_Output
20 #include "vrpn_Configure.h" // for VRPN_CALLBACK, VRPN_API
21 #include "vrpn_Connection.h" // for vrpn_CONNECTION_RELIABLE, etc
22 #include "vrpn_Shared.h" // for timeval
23 #include "vrpn_Types.h" // for vrpn_float64, vrpn_uint32
24 
25 // XXX Add two buttons to the device, to report limit-switch state.
26 
28  public vrpn_Button_Filter
29 {
30 public:
31  vrpn_IDEA (const char * name, vrpn_Connection * c, const char * port
32  , int run_speed_tics_sec = 3200
33  , int start_speed_tics_sec = 1200
34  , int end_speed_tics_sec = 2000
35  , int accel_rate_tics_sec_sec = 40000
36  , int decel_rate_tics_sec_sec = 100000
37  , int run_current = 290
38  , int hold_current = 0
39  , int accel_current = 290
40  , int decel_current = 290
41  , int delay = 50
42  , int step = 8 // Microstepping to do; 1/step steps
43  , int high_limit_index = -1 // Input index for high limits switch (-1 for none)
44  , int low_limit_index = -1 // Input index fro low limit switch (-1 for none)
45  , int output_1_setting = -1
46  , int output_2_setting = -1
47  , int output_3_setting = -1
48  , int output_4_setting = -1
49  , double initial_move = 0 // Move to one end of travel when reset
50  , double fractional_c_a = 1.0 // Use lower accel and current during this move
51  , double reset_location = 0.0 // Where to set the value to after reset
52  );
53  ~vrpn_IDEA () {};
54 
56  virtual void mainloop ();
57 
58  protected:
59  unsigned char d_buffer[512]; //< Buffer of characters in report
60  unsigned d_bufcount; //< How many characters we have so far
61 
62  struct timeval d_timestamp; //< Time of the last report from the device
63 
73  int d_delay;
74  int d_step;
84  struct timeval d_last_poll;
85 
86  virtual int reset(void); //< Set device back to starting config
87  virtual int get_report(void); //< Try to read a report from the device
88 
90  // Returns true if all characters could be sent. Returns false
91  // on failure.
92  bool send_command(const char *cmd);
93 
95  // Scale the acceleration and current values for the move by the
96  // specified fraction between 0 and 1. This lets us execute
97  // "gentler" moves for doing things like jamming against the rails,
98  // so we don't get stuck.
99  bool send_move_request(vrpn_float64 location_in_steps, double scale = 1.0);
100 
102  // the command asking the motor to move until it says that we are no
103  // longer moving.
104  bool move_until_done_or_error(vrpn_float64 location_in_steps, double scale = 1.0);
105 
107  // found, and 1 on value found. Store the result into our analog channel 0.
108  int convert_report_to_position(unsigned char *buf);
109 
111  // found, and 1 on value found. Store the results of our input reads into
112  // buttons 0-3.
113  int convert_report_to_buttons(unsigned char *buf);
114 
116  virtual void report_changes
117  (vrpn_uint32 class_of_service = vrpn_CONNECTION_RELIABLE);
119  virtual void report
120  (vrpn_uint32 class_of_service = vrpn_CONNECTION_RELIABLE);
121 
124  static int VRPN_CALLBACK handle_request_message(void *userdata, vrpn_HANDLERPARAM p);
125 
127  static int VRPN_CALLBACK handle_request_channels_message(void *userdata, vrpn_HANDLERPARAM p);
128 
130  static int VRPN_CALLBACK handle_connect_message(void *userdata, vrpn_HANDLERPARAM p);
131 };
132 
133 #endif
vrpn_Serial_Analog
Definition: vrpn_Analog.h:63
vrpn_IDEA
Definition: vrpn_IDEA.h:29
vrpn_Button_Filter::report_changes
virtual void report_changes(void)
Definition: vrpn_Button.C:382
vrpn_IDEA::d_output_2_setting
int d_output_2_setting
Definition: vrpn_IDEA.h:78
vrpn_Types.h
vrpn_IDEA::d_output_3_setting
int d_output_3_setting
Definition: vrpn_IDEA.h:79
vrpn_Analog_Output.h
vrpn_Analog::report
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Send a report whether something has changed or not (for servers) Optionally, tell what time to stamp ...
Definition: vrpn_Analog.C:94
vrpn_IDEA::d_run_speed_tics_sec
int d_run_speed_tics_sec
Definition: vrpn_IDEA.h:64
vrpn_Analog_Output
Definition: vrpn_Analog_Output.h:26
vrpn_IDEA::d_output_4_setting
int d_output_4_setting
Definition: vrpn_IDEA.h:80
vrpn_IDEA::d_fractional_c_a
double d_fractional_c_a
Definition: vrpn_IDEA.h:82
vrpn_CONNECTION_RELIABLE
const vrpn_uint32 vrpn_CONNECTION_RELIABLE
Classes of service for messages, specify multiple by ORing them together Priority of satisfying these...
Definition: vrpn_Connection.h:120
vrpn_IDEA::d_step
int d_step
Definition: vrpn_IDEA.h:74
vrpn_HANDLERPARAM
This structure is what is passed to a vrpn_Connection message callback.
Definition: vrpn_Connection.h:44
vrpn_Shared.h
vrpn_IDEA::~vrpn_IDEA
~vrpn_IDEA()
Definition: vrpn_IDEA.h:53
vrpn_Button.h
vrpn_IDEA::d_high_limit_index
int d_high_limit_index
Definition: vrpn_IDEA.h:75
vrpn_BaseClass::mainloop
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_IDEA::d_run_current
int d_run_current
Definition: vrpn_IDEA.h:69
vrpn_Connection
Generic connection class not specific to the transport mechanism.
Definition: vrpn_Connection.h:510
vrpn_Connection.h
vrpn_IDEA::d_end_speed_tics_sec
int d_end_speed_tics_sec
Definition: vrpn_IDEA.h:66
vrpn_IDEA::d_hold_current
int d_hold_current
Definition: vrpn_IDEA.h:70
vrpn_IDEA::d_output_1_setting
int d_output_1_setting
Definition: vrpn_IDEA.h:77
vrpn_IDEA::d_initial_move
double d_initial_move
Definition: vrpn_IDEA.h:81
vrpn_Analog.h
VRPN_CALLBACK
#define VRPN_CALLBACK
Definition: vrpn_Configure.h:647
vrpn_IDEA::d_start_speed_tics_sec
int d_start_speed_tics_sec
Definition: vrpn_IDEA.h:65
vrpn_IDEA::d_low_limit_index
int d_low_limit_index
Definition: vrpn_IDEA.h:76
vrpn_IDEA::d_accel_current
int d_accel_current
Definition: vrpn_IDEA.h:71
vrpn_IDEA::d_decel_rate_tics_sec_sec
int d_decel_rate_tics_sec_sec
Definition: vrpn_IDEA.h:68
vrpn_IDEA::d_decel_current
int d_decel_current
Definition: vrpn_IDEA.h:72
vrpn_Configure.h
vrpn_IDEA::d_accel_rate_tics_sec_sec
int d_accel_rate_tics_sec_sec
Definition: vrpn_IDEA.h:67
vrpn_IDEA::d_delay
int d_delay
Definition: vrpn_IDEA.h:73
VRPN_API
#define VRPN_API
Definition: vrpn_Configure.h:646
vrpn_IDEA::d_reset_location
double d_reset_location
Definition: vrpn_IDEA.h:83
vrpn_Button_Filter
All button servers should derive from this class, which provides the ability to turn any of the butto...
Definition: vrpn_Button.h:65