RflySimSDK v3.05
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_IDEA.h
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
27class VRPN_API vrpn_IDEA: public vrpn_Serial_Analog, public vrpn_Analog_Output,
29{
30public:
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
64 int d_run_speed_tics_sec;
65 int d_start_speed_tics_sec;
66 int d_end_speed_tics_sec;
67 int d_accel_rate_tics_sec_sec;
68 int d_decel_rate_tics_sec_sec;
69 int d_run_current;
70 int d_hold_current;
71 int d_accel_current;
72 int d_decel_current;
73 int d_delay;
74 int d_step;
75 int d_high_limit_index;
76 int d_low_limit_index;
77 int d_output_1_setting;
78 int d_output_2_setting;
79 int d_output_3_setting;
80 int d_output_4_setting;
81 double d_initial_move;
82 double d_fractional_c_a;
83 double d_reset_location;
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_Analog_Output.h:26
定义 vrpn_Button.h:66
Generic connection class not specific to the transport mechanism.
定义 vrpn_Connection.h:562
定义 vrpn_IDEA.h:29
bool send_move_request(vrpn_float64 location_in_steps, double scale=1.0)
Request a move from the motor to the specified location.
static int VRPN_CALLBACK handle_request_message(void *userdata, vrpn_HANDLERPARAM p)
virtual void mainloop()
Called once through each main loop iteration to handle updates.
int convert_report_to_position(unsigned char *buf)
Parses a position report. Returns -1 on failure, 0 on no value
int convert_report_to_buttons(unsigned char *buf)
Parses an input/output report. Returns -1 on failure, 0 on no value
bool send_command(const char *cmd)
Appends carriage-return and then sends the command.
virtual void report_changes(vrpn_uint32 class_of_service=vrpn_CONNECTION_RELIABLE)
send report iff changed
static int VRPN_CALLBACK handle_request_channels_message(void *userdata, vrpn_HANDLERPARAM p)
Responds to a request to change multiple channels at once.
bool move_until_done_or_error(vrpn_float64 location_in_steps, double scale=1.0)
Send a move request and then wait for the move to complete. Repeat
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_RELIABLE)
send report whether or not changed
static int VRPN_CALLBACK handle_connect_message(void *userdata, vrpn_HANDLERPARAM p)
Responds to a connection request with a report of the values
定义 vrpn_Analog.h:63
This structure is what is passed to a vrpn_Connection message callback.
定义 vrpn_Connection.h:41