phidgets 0.1.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +3 -0
- data/README.rdoc +32 -43
- data/Rakefile +4 -2
- data/bin/phidget +18 -72
- data/ext/phidgets/extconf.rb +5 -8
- data/ext/phidgets/phidgets.c +708 -173
- data/ext/phidgets/phidgets.h +54 -35
- data/ext/phidgets/phidgets_accelerometer.c +193 -109
- data/ext/phidgets/phidgets_bldc_motor.c +529 -0
- data/ext/phidgets/phidgets_capacitive_touch.c +302 -0
- data/ext/phidgets/phidgets_common.c +570 -315
- data/ext/phidgets/phidgets_current_input.c +229 -0
- data/ext/phidgets/phidgets_dc_motor.c +562 -0
- data/ext/phidgets/phidgets_dictionary.c +154 -213
- data/ext/phidgets/phidgets_digital_input.c +127 -0
- data/ext/phidgets/phidgets_digital_output.c +288 -0
- data/ext/phidgets/phidgets_distance_sensor.c +295 -0
- data/ext/phidgets/phidgets_encoder.c +211 -192
- data/ext/phidgets/phidgets_frequency_counter.c +310 -177
- data/ext/phidgets/phidgets_gps.c +226 -164
- data/ext/phidgets/phidgets_gyroscope.c +195 -0
- data/ext/phidgets/phidgets_hub.c +39 -0
- data/ext/phidgets/phidgets_humidity_sensor.c +200 -0
- data/ext/phidgets/phidgets_ir.c +211 -171
- data/ext/phidgets/phidgets_lcd.c +512 -0
- data/ext/phidgets/phidgets_light_sensor.c +200 -0
- data/ext/phidgets/phidgets_log.c +263 -0
- data/ext/phidgets/phidgets_magnetometer.c +279 -0
- data/ext/phidgets/phidgets_manager.c +86 -297
- data/ext/phidgets/phidgets_motor_position_controller.c +787 -0
- data/ext/phidgets/phidgets_phsensor.c +200 -152
- data/ext/phidgets/phidgets_power_guard.c +144 -0
- data/ext/phidgets/phidgets_pressure_sensor.c +200 -0
- data/ext/phidgets/phidgets_rc_servo.c +672 -0
- data/ext/phidgets/phidgets_resistance_input.c +227 -0
- data/ext/phidgets/phidgets_rfid.c +107 -221
- data/ext/phidgets/phidgets_sound_sensor.c +284 -0
- data/ext/phidgets/phidgets_spatial.c +124 -318
- data/ext/phidgets/phidgets_stepper.c +457 -430
- data/ext/phidgets/phidgets_temp_sensor.c +223 -228
- data/ext/phidgets/phidgets_voltage_input.c +428 -0
- data/ext/phidgets/phidgets_voltage_output.c +167 -0
- data/ext/phidgets/phidgets_voltage_ratio_input.c +435 -0
- data/lib/phidgets.rb +21 -14
- data/lib/phidgets/accelerometer.rb +11 -15
- data/lib/phidgets/bldc_motor.rb +45 -0
- data/lib/phidgets/capacitive_touch.rb +33 -0
- data/lib/phidgets/common.rb +40 -69
- data/lib/phidgets/current_input.rb +21 -0
- data/lib/phidgets/dc_motor.rb +45 -0
- data/lib/phidgets/dictionary.rb +30 -39
- data/lib/phidgets/digital_input.rb +21 -0
- data/lib/phidgets/digital_output.rb +56 -0
- data/lib/phidgets/distance_sensor.rb +33 -0
- data/lib/phidgets/encoder.rb +1 -29
- data/lib/phidgets/frequency_counter.rb +23 -14
- data/lib/phidgets/gps.rb +34 -26
- data/lib/phidgets/gyroscope.rb +21 -0
- data/lib/phidgets/humidity_sensor.rb +21 -0
- data/lib/phidgets/ir.rb +34 -39
- data/lib/phidgets/light_sensor.rb +21 -0
- data/lib/phidgets/magnetometer.rb +21 -0
- data/lib/phidgets/manager.rb +18 -66
- data/lib/phidgets/motor_position_controller.rb +45 -0
- data/lib/phidgets/ph_sensor.rb +2 -6
- data/lib/phidgets/pressure_sensor.rb +21 -0
- data/lib/phidgets/rc_servo.rb +58 -0
- data/lib/phidgets/resistance_input.rb +21 -0
- data/lib/phidgets/rfid.rb +22 -38
- data/lib/phidgets/sound_sensor.rb +21 -0
- data/lib/phidgets/spatial.rb +11 -15
- data/lib/phidgets/stepper.rb +48 -50
- data/lib/phidgets/temperature_sensor.rb +11 -15
- data/lib/phidgets/version.rb +5 -0
- data/lib/phidgets/voltage_input.rb +34 -0
- data/lib/phidgets/voltage_output.rb +23 -0
- data/lib/phidgets/voltage_ratio_input.rb +34 -0
- data/phidgets.gemspec +3 -22
- data/test/test_accelerometer.rb +42 -23
- data/test/test_bldc_motor.rb +134 -0
- data/test/test_capacitive_touch.rb +82 -0
- data/test/test_common.rb +125 -108
- data/test/test_current_input.rb +62 -0
- data/test/test_dc_motor.rb +146 -0
- data/test/test_dictionary.rb +22 -54
- data/test/test_digital_input.rb +30 -0
- data/test/test_digital_output.rb +70 -0
- data/test/test_distance_sensor.rb +76 -0
- data/test/test_encoder.rb +45 -38
- data/test/test_frequency_counter.rb +71 -36
- data/test/test_gps.rb +29 -38
- data/test/test_gyroscope.rb +54 -0
- data/test/test_helper.rb +0 -1
- data/test/test_hub.rb +14 -0
- data/test/test_humidity_sensor.rb +58 -0
- data/test/test_ir.rb +34 -34
- data/test/test_lcd.rb +146 -0
- data/test/test_light_sensor.rb +58 -0
- data/test/test_magnetometer.rb +78 -0
- data/test/test_manager.rb +10 -79
- data/test/test_motor_control.rb +146 -108
- data/test/test_phidgets.rb +2 -14
- data/test/test_phsensor.rb +46 -34
- data/test/test_power_guard.rb +42 -0
- data/test/test_pressure_sensor.rb +58 -0
- data/test/test_rc_servo.rb +174 -0
- data/test/test_resistance_input.rb +66 -0
- data/test/test_rfid.rb +15 -54
- data/test/test_sound_sensor.rb +78 -0
- data/test/test_spatial.rb +19 -85
- data/test/test_stepper.rb +89 -98
- data/test/test_temp_sensor.rb +42 -47
- data/test/test_voltage_input.rb +102 -0
- data/test/test_voltage_output.rb +46 -0
- data/test/test_voltage_ratio_input.rb +102 -0
- metadata +72 -89
- data/ext/phidgets/phidgets_advanced_servo.c +0 -567
- data/ext/phidgets/phidgets_analog.c +0 -139
- data/ext/phidgets/phidgets_bridge.c +0 -263
- data/ext/phidgets/phidgets_interface_kit.c +0 -340
- data/ext/phidgets/phidgets_led.c +0 -178
- data/ext/phidgets/phidgets_motor_control.c +0 -642
- data/ext/phidgets/phidgets_servo.c +0 -276
- data/ext/phidgets/phidgets_text_lcd.c +0 -381
- data/ext/phidgets/phidgets_text_led.c +0 -107
- data/ext/phidgets/phidgets_weight_sensor.c +0 -113
- data/lib/phidgets/advanced_servo.rb +0 -49
- data/lib/phidgets/analog.rb +0 -8
- data/lib/phidgets/bridge.rb +0 -25
- data/lib/phidgets/interfacekit.rb +0 -49
- data/lib/phidgets/led.rb +0 -8
- data/lib/phidgets/motor_control.rb +0 -110
- data/lib/phidgets/servo.rb +0 -23
- data/lib/phidgets/text_lcd.rb +0 -8
- data/lib/phidgets/text_led.rb +0 -8
- data/lib/phidgets/weight_sensor.rb +0 -25
- data/test/test_advanced_servo.rb +0 -152
- data/test/test_analog.rb +0 -45
- data/test/test_bridge.rb +0 -77
- data/test/test_interfacekit.rb +0 -97
- data/test/test_led.rb +0 -55
- data/test/test_servo.rb +0 -67
- data/test/test_text_lcd.rb +0 -115
- data/test/test_text_led.rb +0 -35
- data/test/test_weight_sensor.rb +0 -32
@@ -0,0 +1,200 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
#define PRESSURE_SENSOR_PRESSURE_CHANGE_CALLBACK 0
|
5
|
+
|
6
|
+
|
7
|
+
VALUE ph_pressure_init(VALUE self) {
|
8
|
+
ph_data_t *ph = get_ph_data(self);
|
9
|
+
ph_raise(PhidgetPressureSensor_create((PhidgetPressureSensorHandle *)(&(ph->handle))));
|
10
|
+
return self;
|
11
|
+
}
|
12
|
+
|
13
|
+
VALUE ph_pressure_get_data_interval(VALUE self) {
|
14
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetPressureSensor_getDataInterval);
|
15
|
+
}
|
16
|
+
|
17
|
+
VALUE ph_pressure_set_data_interval(VALUE self, VALUE interval) {
|
18
|
+
ph_raise(PhidgetPressureSensor_setDataInterval((PhidgetPressureSensorHandle)get_ph_handle(self), NUM2UINT(interval)));
|
19
|
+
return Qnil;
|
20
|
+
}
|
21
|
+
|
22
|
+
VALUE ph_pressure_get_min_data_interval(VALUE self) {
|
23
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetPressureSensor_getMinDataInterval);
|
24
|
+
}
|
25
|
+
|
26
|
+
VALUE ph_pressure_get_max_data_interval(VALUE self) {
|
27
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetPressureSensor_getMaxDataInterval);
|
28
|
+
}
|
29
|
+
|
30
|
+
VALUE ph_pressure_get_pressure(VALUE self) {
|
31
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPressureSensor_getPressure);
|
32
|
+
}
|
33
|
+
|
34
|
+
VALUE ph_pressure_get_min_pressure(VALUE self) {
|
35
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPressureSensor_getMinPressure);
|
36
|
+
}
|
37
|
+
|
38
|
+
VALUE ph_pressure_get_max_pressure(VALUE self) {
|
39
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPressureSensor_getMaxPressure);
|
40
|
+
}
|
41
|
+
|
42
|
+
VALUE ph_pressure_get_pressure_change_trigger(VALUE self) {
|
43
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPressureSensor_getPressureChangeTrigger);
|
44
|
+
}
|
45
|
+
|
46
|
+
VALUE ph_pressure_set_pressure_change_trigger(VALUE self, VALUE change_trigger) {
|
47
|
+
ph_raise(PhidgetPressureSensor_setPressureChangeTrigger((PhidgetPressureSensorHandle)get_ph_handle(self), NUM2DBL(change_trigger)));
|
48
|
+
return Qnil;
|
49
|
+
}
|
50
|
+
|
51
|
+
VALUE ph_pressure_get_min_pressure_change_trigger(VALUE self) {
|
52
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPressureSensor_getMinPressureChangeTrigger);
|
53
|
+
}
|
54
|
+
|
55
|
+
VALUE ph_pressure_get_max_pressure_change_trigger(VALUE self) {
|
56
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPressureSensor_getMaxPressureChangeTrigger);
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
void CCONV ph_pressure_on_pressure_change(PhidgetPressureSensorHandle phid, void *userPtr, double pressure) {
|
61
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
62
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
63
|
+
callback_data->arg1 = DBL2NUM(pressure);
|
64
|
+
callback_data->arg2 = Qnil;
|
65
|
+
callback_data->arg3 = Qnil;
|
66
|
+
callback_data->arg4 = Qnil;
|
67
|
+
sem_post(&callback_data->callback_called);
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
VALUE ph_pressure_set_on_pressure_change_handler(VALUE self, VALUE handler) {
|
72
|
+
ph_data_t *ph = get_ph_data(self);
|
73
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[PRESSURE_SENSOR_PRESSURE_CHANGE_CALLBACK];
|
74
|
+
if( TYPE(handler) == T_NIL ) {
|
75
|
+
callback_data->callback = T_NIL;
|
76
|
+
callback_data->exit = true;
|
77
|
+
ph_raise(PhidgetPressureSensor_setOnPressureChangeHandler((PhidgetPressureSensorHandle)ph->handle, NULL, (void *)NULL));
|
78
|
+
sem_post(&callback_data->callback_called);
|
79
|
+
} else {
|
80
|
+
callback_data->exit = false;
|
81
|
+
callback_data->phidget = self;
|
82
|
+
callback_data->callback = handler;
|
83
|
+
ph_raise(PhidgetPressureSensor_setOnPressureChangeHandler((PhidgetPressureSensorHandle)ph->handle, ph_pressure_on_pressure_change, (void *)callback_data));
|
84
|
+
ph_callback_thread(callback_data);
|
85
|
+
}
|
86
|
+
return Qnil;
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
void Init_pressure() {
|
91
|
+
VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
|
92
|
+
VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
|
93
|
+
VALUE ph_pressure = rb_define_class_under(ph_module, "PressureSensor", ph_common);
|
94
|
+
|
95
|
+
/* Document-method: new
|
96
|
+
* call-seq: new
|
97
|
+
*
|
98
|
+
* Creates a Phidget PressureSensor object.
|
99
|
+
*/
|
100
|
+
rb_define_method(ph_pressure, "initialize", ph_pressure_init, 0);
|
101
|
+
|
102
|
+
/* Document-method: getDataInterval
|
103
|
+
* call-seq: getDataInterval -> interval
|
104
|
+
*
|
105
|
+
* The DataInterval is the time that must elapse before the channel will fire another PressureChange event.
|
106
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
107
|
+
* The timing between PressureChange events can also affected by the PressureChangeTrigger.
|
108
|
+
*/
|
109
|
+
rb_define_method(ph_pressure, "getDataInterval", ph_pressure_get_data_interval, 0);
|
110
|
+
rb_define_alias(ph_pressure, "data_interval", "getDataInterval");
|
111
|
+
|
112
|
+
/* Document-method: setDataInterval
|
113
|
+
* call-seq: setDataInterval(interval)
|
114
|
+
*
|
115
|
+
* The DataInterval is the time that must elapse before the channel will fire another PressureChange event.
|
116
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
117
|
+
* The timing between PressureChange events can also affected by the PressureChangeTrigger.
|
118
|
+
*/
|
119
|
+
rb_define_method(ph_pressure, "setDataInterval", ph_pressure_set_data_interval, 1);
|
120
|
+
rb_define_alias(ph_pressure, "data_interval=", "setDataInterval");
|
121
|
+
|
122
|
+
/* Document-method: getMinDataInterval
|
123
|
+
* call-seq: getMinDataInterval -> interval
|
124
|
+
*
|
125
|
+
* The minimum value that DataInterval can be set to.
|
126
|
+
*/
|
127
|
+
rb_define_method(ph_pressure, "getMinDataInterval", ph_pressure_get_min_data_interval, 0);
|
128
|
+
rb_define_alias(ph_pressure, "min_data_interval", "getMinDataInterval");
|
129
|
+
|
130
|
+
/* Document-method: getMaxDataInterval
|
131
|
+
* call-seq: getMaxDataInterval -> interval
|
132
|
+
*
|
133
|
+
* The maximum value that DataInterval can be set to.
|
134
|
+
*/
|
135
|
+
rb_define_method(ph_pressure, "getMaxDataInterval", ph_pressure_get_max_data_interval, 0);
|
136
|
+
rb_define_alias(ph_pressure, "max_data_interval", "getMaxDataInterval");
|
137
|
+
|
138
|
+
/* Document-method: getPressure
|
139
|
+
* call-seq: getPressure -> pressure
|
140
|
+
*
|
141
|
+
* The most recent pressure value that the channel has reported.
|
142
|
+
* This value will always be between MinPressure and MaxPressure.
|
143
|
+
*/
|
144
|
+
rb_define_method(ph_pressure, "getPressure", ph_pressure_get_pressure, 0);
|
145
|
+
rb_define_alias(ph_pressure, "pressure", "getPressure");
|
146
|
+
|
147
|
+
/* Document-method: getMinPressure
|
148
|
+
* call-seq: getMinPressure -> pressure
|
149
|
+
*
|
150
|
+
* The minimum value that the PressureChange event will report.
|
151
|
+
*/
|
152
|
+
rb_define_method(ph_pressure, "getMinPressure", ph_pressure_get_min_pressure, 0);
|
153
|
+
rb_define_alias(ph_pressure, "min_pressure", "getMinPressure");
|
154
|
+
|
155
|
+
/* Document-method: getMaxPressure
|
156
|
+
* call-seq: getMaxPressure -> pressure
|
157
|
+
*
|
158
|
+
* The maximum value that the PressureChange event will report.
|
159
|
+
*/
|
160
|
+
rb_define_method(ph_pressure, "getMaxPressure", ph_pressure_get_max_pressure, 0);
|
161
|
+
rb_define_alias(ph_pressure, "max_pressure", "getMaxPressure");
|
162
|
+
|
163
|
+
/* Document-method: getPressureChangeTrigger
|
164
|
+
* call-seq: getPressureChangeTrigger -> change_trigger
|
165
|
+
*
|
166
|
+
* The channel will not issue a PressureChange event until the pressure value has changed by the amount specified by the PressureChangeTrigger.
|
167
|
+
* Setting the PressureChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
|
168
|
+
*/
|
169
|
+
rb_define_method(ph_pressure, "getPressureChangeTrigger", ph_pressure_get_pressure_change_trigger, 0);
|
170
|
+
rb_define_alias(ph_pressure, "pressure_change_trigger", "getPressureChangeTrigger");
|
171
|
+
|
172
|
+
/* Document-method: setPressureChangeTrigger
|
173
|
+
* call-seq: setPressureChangeTrigger(change_trigger)
|
174
|
+
*
|
175
|
+
* The channel will not issue a PressureChange event until the pressure value has changed by the amount specified by the PressureChangeTrigger.
|
176
|
+
* Setting the PressureChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
|
177
|
+
*/
|
178
|
+
rb_define_method(ph_pressure, "setPressureChangeTrigger", ph_pressure_set_pressure_change_trigger, 1);
|
179
|
+
rb_define_alias(ph_pressure, "pressure_change_trigger=", "setPressureChangeTrigger");
|
180
|
+
|
181
|
+
/* Document-method: getMinPressureChangeTrigger
|
182
|
+
* call-seq: getMinPressureChangeTrigger -> change_trigger
|
183
|
+
*
|
184
|
+
* The minimum value that PressureChangeTrigger can be set to.
|
185
|
+
*/
|
186
|
+
rb_define_method(ph_pressure, "getMinPressureChangeTrigger", ph_pressure_get_min_pressure_change_trigger, 0);
|
187
|
+
rb_define_alias(ph_pressure, "min_pressure_change_trigger", "getMinPressureChangeTrigger");
|
188
|
+
|
189
|
+
/* Document-method: getMaxPressureChangeTrigger
|
190
|
+
* call-seq: getMaxPressureChangeTrigger -> change_trigger
|
191
|
+
*
|
192
|
+
* The maximum value that PressureChangeTrigger can be set to.
|
193
|
+
*/
|
194
|
+
rb_define_method(ph_pressure, "getMaxPressureChangeTrigger", ph_pressure_get_max_pressure_change_trigger, 0);
|
195
|
+
rb_define_alias(ph_pressure, "max_pressure_change_trigger", "getMaxPressureChangeTrigger");
|
196
|
+
|
197
|
+
|
198
|
+
rb_define_private_method(ph_pressure, "ext_setOnPressureChangeHandler", ph_pressure_set_on_pressure_change_handler, 1);
|
199
|
+
}
|
200
|
+
|
@@ -0,0 +1,672 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
#define RC_SERVO_POSITION_CHANGE_CALLBACK 0
|
5
|
+
#define RC_SERVO_TARGET_POSITION_REACHED_CALLBACK 1
|
6
|
+
#define RC_SERVO_VELOCITY_CHANGE_CALLBACK 2
|
7
|
+
#define RC_SERVO_TARGET_POSITION_ASYNC_CALLBACK 3
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
VALUE ph_rc_servo_init(VALUE self) {
|
12
|
+
ph_data_t *ph = get_ph_data(self);
|
13
|
+
ph_raise(PhidgetRCServo_create((PhidgetRCServoHandle *)(&(ph->handle))));
|
14
|
+
return self;
|
15
|
+
}
|
16
|
+
|
17
|
+
VALUE ph_rc_servo_get_acceleration(VALUE self) {
|
18
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getAcceleration);
|
19
|
+
}
|
20
|
+
|
21
|
+
VALUE ph_rc_servo_set_acceleration(VALUE self, VALUE acceleration) {
|
22
|
+
ph_raise(PhidgetRCServo_setAcceleration((PhidgetRCServoHandle)get_ph_handle(self), NUM2DBL(acceleration)));
|
23
|
+
return Qnil;
|
24
|
+
}
|
25
|
+
|
26
|
+
VALUE ph_rc_servo_get_min_acceleration(VALUE self) {
|
27
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getMinAcceleration);
|
28
|
+
}
|
29
|
+
|
30
|
+
VALUE ph_rc_servo_get_max_acceleration(VALUE self) {
|
31
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getMaxAcceleration);
|
32
|
+
}
|
33
|
+
|
34
|
+
VALUE ph_rc_servo_get_data_interval(VALUE self) {
|
35
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetRCServo_getDataInterval);
|
36
|
+
}
|
37
|
+
|
38
|
+
VALUE ph_rc_servo_set_data_interval(VALUE self, VALUE interval) {
|
39
|
+
ph_raise(PhidgetRCServo_setDataInterval((PhidgetRCServoHandle)get_ph_handle(self), NUM2UINT(interval)));
|
40
|
+
return Qnil;
|
41
|
+
}
|
42
|
+
|
43
|
+
VALUE ph_rc_servo_get_min_data_interval(VALUE self) {
|
44
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetRCServo_getMinDataInterval);
|
45
|
+
}
|
46
|
+
|
47
|
+
VALUE ph_rc_servo_get_max_data_interval(VALUE self) {
|
48
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetRCServo_getMaxDataInterval);
|
49
|
+
}
|
50
|
+
|
51
|
+
VALUE ph_rc_servo_get_engaged(VALUE self) {
|
52
|
+
return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetRCServo_getEngaged);
|
53
|
+
}
|
54
|
+
|
55
|
+
VALUE ph_rc_servo_set_engaged(VALUE self, VALUE engaged) {
|
56
|
+
ph_raise(PhidgetRCServo_setEngaged((PhidgetRCServoHandle)get_ph_handle(self), TYPE(engaged) == T_TRUE ? PTRUE : PFALSE));
|
57
|
+
return Qnil;
|
58
|
+
}
|
59
|
+
|
60
|
+
VALUE ph_rc_servo_get_is_moving(VALUE self) {
|
61
|
+
return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetRCServo_getIsMoving);
|
62
|
+
}
|
63
|
+
|
64
|
+
VALUE ph_rc_servo_get_position(VALUE self) {
|
65
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getPosition);
|
66
|
+
}
|
67
|
+
|
68
|
+
VALUE ph_rc_servo_get_min_position(VALUE self) {
|
69
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getMinPosition);
|
70
|
+
}
|
71
|
+
|
72
|
+
VALUE ph_rc_servo_set_min_position(VALUE self, VALUE position) {
|
73
|
+
ph_raise(PhidgetRCServo_setMinPosition((PhidgetRCServoHandle)get_ph_handle(self), NUM2DBL(position)));
|
74
|
+
return Qnil;
|
75
|
+
}
|
76
|
+
|
77
|
+
VALUE ph_rc_servo_get_max_position(VALUE self) {
|
78
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getMaxPosition);
|
79
|
+
}
|
80
|
+
|
81
|
+
VALUE ph_rc_servo_set_max_position(VALUE self, VALUE position) {
|
82
|
+
ph_raise(PhidgetRCServo_setMaxPosition((PhidgetRCServoHandle)get_ph_handle(self), NUM2DBL(position)));
|
83
|
+
return Qnil;
|
84
|
+
}
|
85
|
+
|
86
|
+
VALUE ph_rc_servo_get_min_pulse_width(VALUE self) {
|
87
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getMinPulseWidth);
|
88
|
+
}
|
89
|
+
|
90
|
+
VALUE ph_rc_servo_set_min_pulse_width(VALUE self, VALUE pulse_width) {
|
91
|
+
ph_raise(PhidgetRCServo_setMinPulseWidth((PhidgetRCServoHandle)get_ph_handle(self), NUM2DBL(pulse_width)));
|
92
|
+
return Qnil;
|
93
|
+
}
|
94
|
+
|
95
|
+
VALUE ph_rc_servo_get_max_pulse_width(VALUE self) {
|
96
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getMaxPulseWidth);
|
97
|
+
}
|
98
|
+
|
99
|
+
VALUE ph_rc_servo_set_max_pulse_width(VALUE self, VALUE pulse_width) {
|
100
|
+
ph_raise(PhidgetRCServo_setMaxPulseWidth((PhidgetRCServoHandle)get_ph_handle(self), NUM2DBL(pulse_width)));
|
101
|
+
return Qnil;
|
102
|
+
}
|
103
|
+
|
104
|
+
VALUE ph_rc_servo_get_min_pulse_width_limit(VALUE self) {
|
105
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getMinPulseWidthLimit);
|
106
|
+
}
|
107
|
+
|
108
|
+
VALUE ph_rc_servo_get_max_pulse_width_limit(VALUE self) {
|
109
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getMaxPulseWidthLimit);
|
110
|
+
}
|
111
|
+
|
112
|
+
VALUE ph_rc_servo_get_speed_ramping_state(VALUE self) {
|
113
|
+
return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetRCServo_getSpeedRampingState);
|
114
|
+
}
|
115
|
+
|
116
|
+
VALUE ph_rc_servo_set_speed_ramping_state(VALUE self, VALUE speed_ramping_state) {
|
117
|
+
ph_raise(PhidgetRCServo_setSpeedRampingState((PhidgetRCServoHandle)get_ph_handle(self), TYPE(speed_ramping_state) == T_TRUE ? PTRUE : PFALSE));
|
118
|
+
return Qnil;
|
119
|
+
}
|
120
|
+
|
121
|
+
VALUE ph_rc_servo_get_target_position(VALUE self) {
|
122
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getTargetPosition);
|
123
|
+
}
|
124
|
+
|
125
|
+
VALUE ph_rc_servo_set_target_position(VALUE self, VALUE position) {
|
126
|
+
ph_raise(PhidgetRCServo_setTargetPosition((PhidgetRCServoHandle)get_ph_handle(self), NUM2DBL(position)));
|
127
|
+
return Qnil;
|
128
|
+
}
|
129
|
+
|
130
|
+
VALUE ph_rc_servo_get_torque(VALUE self) {
|
131
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getTorque);
|
132
|
+
}
|
133
|
+
|
134
|
+
VALUE ph_rc_servo_set_torque(VALUE self, VALUE torque) {
|
135
|
+
ph_raise(PhidgetRCServo_setTorque((PhidgetRCServoHandle)get_ph_handle(self), NUM2DBL(torque)));
|
136
|
+
return Qnil;
|
137
|
+
}
|
138
|
+
|
139
|
+
VALUE ph_rc_servo_get_min_torque(VALUE self) {
|
140
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getMinTorque);
|
141
|
+
}
|
142
|
+
|
143
|
+
VALUE ph_rc_servo_get_max_torque(VALUE self) {
|
144
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getMaxTorque);
|
145
|
+
}
|
146
|
+
|
147
|
+
VALUE ph_rc_servo_get_velocity(VALUE self) {
|
148
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getVelocity);
|
149
|
+
}
|
150
|
+
|
151
|
+
VALUE ph_rc_servo_get_velocity_limit(VALUE self) {
|
152
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getVelocityLimit);
|
153
|
+
}
|
154
|
+
|
155
|
+
VALUE ph_rc_servo_set_velocity_limit(VALUE self, VALUE velocity_limit) {
|
156
|
+
ph_raise(PhidgetRCServo_setVelocityLimit((PhidgetRCServoHandle)get_ph_handle(self), NUM2DBL(velocity_limit)));
|
157
|
+
return Qnil;
|
158
|
+
}
|
159
|
+
|
160
|
+
VALUE ph_rc_servo_get_min_velocity_limit(VALUE self) {
|
161
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getMinVelocityLimit);
|
162
|
+
}
|
163
|
+
|
164
|
+
VALUE ph_rc_servo_get_max_velocity_limit(VALUE self) {
|
165
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getMaxVelocityLimit);
|
166
|
+
}
|
167
|
+
|
168
|
+
VALUE ph_rc_servo_get_voltage(VALUE self) {
|
169
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetRCServo_getVoltage);
|
170
|
+
}
|
171
|
+
|
172
|
+
VALUE ph_rc_servo_set_voltage(VALUE self, VALUE voltage) {
|
173
|
+
ph_raise(PhidgetRCServo_setVoltage((PhidgetRCServoHandle)get_ph_handle(self), NUM2DBL(voltage)));
|
174
|
+
return Qnil;
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
void CCONV ph_rc_servo_on_position_change(PhidgetRCServoHandle phid, void *userPtr, double position) {
|
179
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
180
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
181
|
+
callback_data->arg1 = DBL2NUM(position);
|
182
|
+
callback_data->arg2 = Qnil;
|
183
|
+
callback_data->arg3 = Qnil;
|
184
|
+
callback_data->arg4 = Qnil;
|
185
|
+
sem_post(&callback_data->callback_called);
|
186
|
+
}
|
187
|
+
|
188
|
+
|
189
|
+
VALUE ph_rc_servo_set_on_position_change_handler(VALUE self, VALUE handler) {
|
190
|
+
ph_data_t *ph = get_ph_data(self);
|
191
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[RC_SERVO_POSITION_CHANGE_CALLBACK];
|
192
|
+
if( TYPE(handler) == T_NIL ) {
|
193
|
+
callback_data->callback = T_NIL;
|
194
|
+
callback_data->exit = true;
|
195
|
+
ph_raise(PhidgetRCServo_setOnPositionChangeHandler((PhidgetRCServoHandle)ph->handle, NULL, (void *)NULL));
|
196
|
+
sem_post(&callback_data->callback_called);
|
197
|
+
} else {
|
198
|
+
callback_data->exit = false;
|
199
|
+
callback_data->phidget = self;
|
200
|
+
callback_data->callback = handler;
|
201
|
+
ph_raise(PhidgetRCServo_setOnPositionChangeHandler((PhidgetRCServoHandle)ph->handle, ph_rc_servo_on_position_change, (void *)callback_data));
|
202
|
+
ph_callback_thread(callback_data);
|
203
|
+
}
|
204
|
+
return Qnil;
|
205
|
+
}
|
206
|
+
|
207
|
+
|
208
|
+
void CCONV ph_rc_servo_on_target_position_reached(PhidgetRCServoHandle phid, void *userPtr, double position) {
|
209
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
210
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
211
|
+
callback_data->arg1 = DBL2NUM(position);
|
212
|
+
callback_data->arg2 = Qnil;
|
213
|
+
callback_data->arg3 = Qnil;
|
214
|
+
callback_data->arg4 = Qnil;
|
215
|
+
sem_post(&callback_data->callback_called);
|
216
|
+
}
|
217
|
+
|
218
|
+
|
219
|
+
VALUE ph_rc_servo_set_on_target_position_reached_handler(VALUE self, VALUE handler) {
|
220
|
+
ph_data_t *ph = get_ph_data(self);
|
221
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[RC_SERVO_TARGET_POSITION_REACHED_CALLBACK];
|
222
|
+
if( TYPE(handler) == T_NIL ) {
|
223
|
+
callback_data->callback = T_NIL;
|
224
|
+
callback_data->exit = true;
|
225
|
+
ph_raise(PhidgetRCServo_setOnTargetPositionReachedHandler((PhidgetRCServoHandle)ph->handle, NULL, (void *)NULL));
|
226
|
+
sem_post(&callback_data->callback_called);
|
227
|
+
} else {
|
228
|
+
callback_data->exit = false;
|
229
|
+
callback_data->phidget = self;
|
230
|
+
callback_data->callback = handler;
|
231
|
+
ph_raise(PhidgetRCServo_setOnTargetPositionReachedHandler((PhidgetRCServoHandle)ph->handle, ph_rc_servo_on_target_position_reached, (void *)callback_data));
|
232
|
+
ph_callback_thread(callback_data);
|
233
|
+
}
|
234
|
+
return Qnil;
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
void CCONV ph_rc_servo_on_velocity_change(PhidgetRCServoHandle phid, void *userPtr, double velocity) {
|
239
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
240
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
241
|
+
callback_data->arg1 = DBL2NUM(velocity);
|
242
|
+
callback_data->arg2 = Qnil;
|
243
|
+
callback_data->arg3 = Qnil;
|
244
|
+
callback_data->arg4 = Qnil;
|
245
|
+
sem_post(&callback_data->callback_called);
|
246
|
+
}
|
247
|
+
|
248
|
+
|
249
|
+
VALUE ph_rc_servo_set_on_velocity_change_handler(VALUE self, VALUE handler) {
|
250
|
+
ph_data_t *ph = get_ph_data(self);
|
251
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[RC_SERVO_VELOCITY_CHANGE_CALLBACK];
|
252
|
+
if( TYPE(handler) == T_NIL ) {
|
253
|
+
callback_data->callback = T_NIL;
|
254
|
+
callback_data->exit = true;
|
255
|
+
ph_raise(PhidgetRCServo_setOnVelocityChangeHandler((PhidgetRCServoHandle)ph->handle, NULL, (void *)NULL));
|
256
|
+
sem_post(&callback_data->callback_called);
|
257
|
+
} else {
|
258
|
+
callback_data->exit = false;
|
259
|
+
callback_data->phidget = self;
|
260
|
+
callback_data->callback = handler;
|
261
|
+
ph_raise(PhidgetRCServo_setOnVelocityChangeHandler((PhidgetRCServoHandle)ph->handle, ph_rc_servo_on_velocity_change, (void *)callback_data));
|
262
|
+
ph_callback_thread(callback_data);
|
263
|
+
}
|
264
|
+
return Qnil;
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
void CCONV ph_rc_servo_target_position_async(PhidgetHandle phid, void *userPtr, PhidgetReturnCode res) {
|
269
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
270
|
+
callback_data->exit = true;
|
271
|
+
callback_data->arg1 = INT2NUM(res);
|
272
|
+
callback_data->arg2 = Qnil;
|
273
|
+
callback_data->arg3 = Qnil;
|
274
|
+
callback_data->arg4 = Qnil;
|
275
|
+
sem_post(&callback_data->callback_called);
|
276
|
+
}
|
277
|
+
|
278
|
+
|
279
|
+
VALUE ph_rc_servo_set_target_position_async(VALUE self, VALUE position, VALUE handler) {
|
280
|
+
ph_data_t *ph = get_ph_data(self);
|
281
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[RC_SERVO_TARGET_POSITION_ASYNC_CALLBACK];
|
282
|
+
if( TYPE(handler) == T_NIL ) {
|
283
|
+
PhidgetRCServo_setTargetPosition_async((PhidgetRCServoHandle)ph->handle, NUM2DBL(position), NULL, (void *)NULL);
|
284
|
+
} else {
|
285
|
+
callback_data->exit = false;
|
286
|
+
callback_data->phidget = self;
|
287
|
+
callback_data->callback = handler;
|
288
|
+
PhidgetRCServo_setTargetPosition_async((PhidgetRCServoHandle)ph->handle, NUM2DBL(position), ph_rc_servo_target_position_async, (void *)callback_data);
|
289
|
+
ph_callback_thread(callback_data);
|
290
|
+
}
|
291
|
+
return Qnil;
|
292
|
+
}
|
293
|
+
|
294
|
+
|
295
|
+
void Init_rc_servo() {
|
296
|
+
VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
|
297
|
+
VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
|
298
|
+
VALUE ph_rc_servo = rb_define_class_under(ph_module, "RCServo", ph_common);
|
299
|
+
|
300
|
+
/* Document-method: new
|
301
|
+
* call-seq: new
|
302
|
+
*
|
303
|
+
* Creates a Phidget RCServo object.
|
304
|
+
*/
|
305
|
+
rb_define_method(ph_rc_servo, "initialize", ph_rc_servo_init, 0);
|
306
|
+
|
307
|
+
/* Document-method: getAcceleration
|
308
|
+
* call-seq: getAcceleration -> acceleration
|
309
|
+
*
|
310
|
+
* When changing velocity, the RC servo motor will accelerate/decelerate at this rate.
|
311
|
+
* The acceleration is bounded by MaxAcceleration and MinAcceleration.
|
312
|
+
* SpeedRampingState controls whether or not the acceleration value is actually applied when trying to reach a target position.
|
313
|
+
* There is a practical limit on how fast your RC servo motor can accelerate. This is based on the load and physical design of the motor.
|
314
|
+
* The units for Position,Velocity, and Acceleration are configured by scaling the internal timing (set with MinPulseWidth and MaxPulseWidth) to a user specified range with MinPosition and MaxPosition.
|
315
|
+
*/
|
316
|
+
rb_define_method(ph_rc_servo, "getAcceleration", ph_rc_servo_get_acceleration, 0);
|
317
|
+
rb_define_alias(ph_rc_servo, "acceleration", "getAcceleration");
|
318
|
+
|
319
|
+
/* Document-method: setAcceleration
|
320
|
+
* call-seq: setAcceleration(acceleration)
|
321
|
+
*
|
322
|
+
* When changing velocity, the RC servo motor will accelerate/decelerate at this rate.
|
323
|
+
* The acceleration is bounded by MaxAcceleration and MinAcceleration.
|
324
|
+
* SpeedRampingState controls whether or not the acceleration value is actually applied when trying to reach a target position.
|
325
|
+
* There is a practical limit on how fast your RC servo motor can accelerate. This is based on the load and physical design of the motor.
|
326
|
+
* The units for Position,Velocity, and Acceleration are configured by scaling the internal timing (set with MinPulseWidth and MaxPulseWidth) to a user specified range with MinPosition and MaxPosition.
|
327
|
+
*/
|
328
|
+
rb_define_method(ph_rc_servo, "setAcceleration", ph_rc_servo_set_acceleration, 1);
|
329
|
+
rb_define_alias(ph_rc_servo, "acceleration=", "setAcceleration");
|
330
|
+
|
331
|
+
/* Document-method: getMinAcceleration
|
332
|
+
* call-seq: getMinAcceleration -> acceleration
|
333
|
+
*
|
334
|
+
* The minimum value that Acceleration can be set to
|
335
|
+
* This value depends on MinPosition/MaxPosition and MinPulseWidth/MaxPulseWidth.
|
336
|
+
*/
|
337
|
+
rb_define_method(ph_rc_servo, "getMinAcceleration", ph_rc_servo_get_min_acceleration, 0);
|
338
|
+
rb_define_alias(ph_rc_servo, "min_acceleration", "getMinAcceleration");
|
339
|
+
|
340
|
+
/* Document-method: getMaxAcceleration
|
341
|
+
* call-seq: getMaxAcceleration -> acceleration
|
342
|
+
*
|
343
|
+
* The maximum acceleration that Acceleration can be set to.
|
344
|
+
* This value depends on MinPosition/MaxPosition and MinPulseWidth/MaxPulseWidth.
|
345
|
+
*/
|
346
|
+
rb_define_method(ph_rc_servo, "getMaxAcceleration", ph_rc_servo_get_max_acceleration, 0);
|
347
|
+
rb_define_alias(ph_rc_servo, "max_acceleration", "getMaxAcceleration");
|
348
|
+
|
349
|
+
/* Document-method: getDataInterval
|
350
|
+
* call-seq: getDataInterval -> data_interval
|
351
|
+
*
|
352
|
+
* The DataInterval is the time that must elapse before the controller will fire another PositionChange event.
|
353
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
354
|
+
*/
|
355
|
+
rb_define_method(ph_rc_servo, "getDataInterval", ph_rc_servo_get_data_interval, 0);
|
356
|
+
rb_define_alias(ph_rc_servo, "data_interval", "getDataInterval");
|
357
|
+
|
358
|
+
/* Document-method: setDataInterval
|
359
|
+
* call-seq: setDataInterval(data_interval)
|
360
|
+
*
|
361
|
+
* The DataInterval is the time that must elapse before the controller will fire another PositionChange event.
|
362
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
363
|
+
*/
|
364
|
+
rb_define_method(ph_rc_servo, "setDataInterval", ph_rc_servo_set_data_interval, 1);
|
365
|
+
rb_define_alias(ph_rc_servo, "data_interval=", "setDataInterval");
|
366
|
+
|
367
|
+
/* Document-method: getMinDataInterval
|
368
|
+
* call-seq: getMinDataInterval -> data_interval
|
369
|
+
*
|
370
|
+
* The DataInterval is the time that must elapse before the controller will fire another PositionChange event.
|
371
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
372
|
+
*/
|
373
|
+
rb_define_method(ph_rc_servo, "getMinDataInterval", ph_rc_servo_get_min_data_interval, 0);
|
374
|
+
rb_define_alias(ph_rc_servo, "min_data_interval", "getMinDataInterval");
|
375
|
+
|
376
|
+
/* Document-method: getMaxDataInterval
|
377
|
+
* call-seq: getMaxDataInterval -> data_interval
|
378
|
+
*
|
379
|
+
* The DataInterval is the time that must elapse before the controller will fire another PositionChange event.
|
380
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
381
|
+
*/
|
382
|
+
rb_define_method(ph_rc_servo, "getMaxDataInterval", ph_rc_servo_get_max_data_interval, 0);
|
383
|
+
rb_define_alias(ph_rc_servo, "max_data_interval", "getMaxDataInterval");
|
384
|
+
|
385
|
+
/* Document-method: getEngaged
|
386
|
+
* call-seq: getEngaged -> true or false
|
387
|
+
*
|
388
|
+
* When engaged, a RC servo motor has the ability to be positioned. When disengaged, no commands are sent to the RC servo motor.
|
389
|
+
* There is no position feedback to the controller, so the RC servo motor will immediately snap to the TargetPosition after being engaged from a disengaged state.
|
390
|
+
* This property is useful for relaxing a servo once it has reached a given position.
|
391
|
+
* If you are concerned about tracking position accurately, you should not disengage the motor while IsMoving is true.
|
392
|
+
*/
|
393
|
+
rb_define_method(ph_rc_servo, "getEngaged", ph_rc_servo_get_engaged, 0);
|
394
|
+
rb_define_alias(ph_rc_servo, "engaged?", "getEngaged");
|
395
|
+
|
396
|
+
/* Document-method: setEngaged
|
397
|
+
* call-seq: setEngaged(state)
|
398
|
+
*
|
399
|
+
* When engaged, a RC servo motor has the ability to be positioned. When disengaged, no commands are sent to the RC servo motor.
|
400
|
+
* There is no position feedback to the controller, so the RC servo motor will immediately snap to the TargetPosition after being engaged from a disengaged state.
|
401
|
+
* This property is useful for relaxing a servo once it has reached a given position.
|
402
|
+
* If you are concerned about tracking position accurately, you should not disengage the motor while IsMoving is true.
|
403
|
+
*/
|
404
|
+
rb_define_method(ph_rc_servo, "setEngaged", ph_rc_servo_set_engaged, 1);
|
405
|
+
rb_define_alias(ph_rc_servo, "engaged=", "setEngaged");
|
406
|
+
|
407
|
+
/* Document-method: getIsMoving
|
408
|
+
* call-seq: getIsMoving -> true or false
|
409
|
+
*
|
410
|
+
* IsMoving returns true if the RC servo motor is currently in motion.
|
411
|
+
* The controller cannot know if the RC servo motor is physically moving. When < code > IsMoving is false, it simply means there are no commands in the pipeline to the RC servo motor.
|
412
|
+
*/
|
413
|
+
rb_define_method(ph_rc_servo, "getIsMoving", ph_rc_servo_get_is_moving, 0);
|
414
|
+
rb_define_alias(ph_rc_servo, "is_moving?", "getIsMoving");
|
415
|
+
|
416
|
+
/* Document-method: getPosition
|
417
|
+
* call-seq: getPosition -> position
|
418
|
+
*
|
419
|
+
* The most recent position of the RC servo motor that the controller has reported.
|
420
|
+
* This value will always be between MinPosition and MaxPosition.
|
421
|
+
*/
|
422
|
+
rb_define_method(ph_rc_servo, "getPosition", ph_rc_servo_get_position, 0);
|
423
|
+
rb_define_alias(ph_rc_servo, "position", "getPosition");
|
424
|
+
|
425
|
+
/* Document-method: getMinPosition
|
426
|
+
* call-seq: getMinPosition -> position
|
427
|
+
*
|
428
|
+
* The minimum position that TargetPosition can be set to.
|
429
|
+
* The units for Position,Velocity, and Acceleration are configured by scaling the internal timing (set with MinPulseWidth and MaxPulseWidth) to a user specified range with MinPosition and MaxPosition.
|
430
|
+
*/
|
431
|
+
rb_define_method(ph_rc_servo, "getMinPosition", ph_rc_servo_get_min_position, 0);
|
432
|
+
rb_define_alias(ph_rc_servo, "min_position", "getMinPosition");
|
433
|
+
|
434
|
+
/* Document-method: setMinPosition
|
435
|
+
* call-seq: setMinPosition(position)
|
436
|
+
*
|
437
|
+
* The minimum position that TargetPosition can be set to.
|
438
|
+
* The units for Position,Velocity, and Acceleration are configured by scaling the internal timing (set with MinPulseWidth and MaxPulseWidth) to a user specified range with MinPosition and MaxPosition.
|
439
|
+
*/
|
440
|
+
rb_define_method(ph_rc_servo, "setMinPosition", ph_rc_servo_set_min_position, 1);
|
441
|
+
rb_define_alias(ph_rc_servo, "min_position=", "setMinPosition");
|
442
|
+
|
443
|
+
/* Document-method: getMaxPosition
|
444
|
+
* call-seq: getMaxPosition -> position
|
445
|
+
*
|
446
|
+
* The maximum position TargetPosition can be set to.
|
447
|
+
* The units for Position,Velocity, and Acceleration are configured by scaling the internal timing (set with MinPulseWidth and MaxPulseWidth) to a user specified range with MinPosition and MaxPosition.
|
448
|
+
*/
|
449
|
+
rb_define_method(ph_rc_servo, "getMaxPosition", ph_rc_servo_get_max_position, 0);
|
450
|
+
rb_define_alias(ph_rc_servo, "max_position", "getMaxPosition");
|
451
|
+
|
452
|
+
/* Document-method: setMaxPosition
|
453
|
+
* call-seq: setMaxPosition(position)
|
454
|
+
*
|
455
|
+
* The maximum position that TargetPosition can be set to.
|
456
|
+
* The units for Position,Velocity, and Acceleration are configured by scaling the internal timing (set with MinPulseWidth and MaxPulseWidth) to a user specified range with MinPosition and MaxPosition.
|
457
|
+
*/
|
458
|
+
rb_define_method(ph_rc_servo, "setMaxPosition", ph_rc_servo_set_max_position, 1);
|
459
|
+
rb_define_alias(ph_rc_servo, "max_position=", "setMaxPosition");
|
460
|
+
|
461
|
+
/* Document-method: getMinPulseWidth
|
462
|
+
* call-seq: getMinPulseWidth -> pulse_width
|
463
|
+
*
|
464
|
+
* The MinPulseWidth represents the minimum pulse width that your RC servo motor specifies.
|
465
|
+
* This value can be found in the data sheet of most RC servo motors.
|
466
|
+
* The units for Position,Velocity, and Acceleration are configured by scaling the internal timing (set with MinPulseWidth and MaxPulseWidth) to a user specified range with MinPosition and MaxPosition.
|
467
|
+
*/
|
468
|
+
rb_define_method(ph_rc_servo, "getMinPulseWidth", ph_rc_servo_get_min_pulse_width, 0);
|
469
|
+
rb_define_alias(ph_rc_servo, "min_pulse_width", "getMinPulseWidth");
|
470
|
+
|
471
|
+
/* Document-method: setMinPulseWidth
|
472
|
+
* call-seq: setMinPulseWidth(pulse_width)
|
473
|
+
*
|
474
|
+
* The MinPulseWidth represents the minimum pulse width that your RC servo motor specifies.
|
475
|
+
* This value can be found in the data sheet of most RC servo motors.
|
476
|
+
* The units for Position,Velocity, and Acceleration are configured by scaling the internal timing (set with MinPulseWidth and MaxPulseWidth) to a user specified range with MinPosition and MaxPosition.
|
477
|
+
*/
|
478
|
+
rb_define_method(ph_rc_servo, "setMinPulseWidth", ph_rc_servo_set_min_pulse_width, 1);
|
479
|
+
rb_define_alias(ph_rc_servo, "min_pulse_width=", "setMinPulseWidth");
|
480
|
+
|
481
|
+
/* Document-method: getMaxPulseWidth
|
482
|
+
* call-seq: getMaxPulseWidth -> pulse_width
|
483
|
+
*
|
484
|
+
* The MaxPulseWidth represents the maximum pulse width that your RC servo motor specifies.
|
485
|
+
* This value can be found in the data sheet of most RC servo motors.
|
486
|
+
* The units for Position,Velocity, and Acceleration are configured by scaling the internal timing (set with MinPulseWidth and MaxPulseWidth) to a user specified range with MinPosition and MaxPosition.
|
487
|
+
*/
|
488
|
+
rb_define_method(ph_rc_servo, "getMaxPulseWidth", ph_rc_servo_get_max_pulse_width, 0);
|
489
|
+
rb_define_alias(ph_rc_servo, "max_pulse_width", "getMaxPulseWidth");
|
490
|
+
|
491
|
+
/* Document-method: setMaxPulseWidth
|
492
|
+
* call-seq: setMaxPulseWidth(pulse_width)
|
493
|
+
*
|
494
|
+
* The MaxPulseWidth represents the maximum pulse width that your RC servo motor specifies.
|
495
|
+
* This value can be found in the data sheet of most RC servo motors.
|
496
|
+
* The units for Position,Velocity, and Acceleration are configured by scaling the internal timing (set with MinPulseWidth and MaxPulseWidth) to a user specified range with MinPosition and MaxPosition.
|
497
|
+
*/
|
498
|
+
rb_define_method(ph_rc_servo, "setMaxPulseWidth", ph_rc_servo_set_max_pulse_width, 1);
|
499
|
+
rb_define_alias(ph_rc_servo, "max_pulse_width=", "setMaxPulseWidth");
|
500
|
+
|
501
|
+
/* Document-method: getMinPulseWidthLimit
|
502
|
+
* call-seq: getMinPulseWidthLimit -> pulse_width
|
503
|
+
*
|
504
|
+
* The minimum pulse width that MinPulseWidth can be set to.
|
505
|
+
*/
|
506
|
+
rb_define_method(ph_rc_servo, "getMinPulseWidthLimit", ph_rc_servo_get_min_pulse_width_limit, 0);
|
507
|
+
rb_define_alias(ph_rc_servo, "min_pulse_width_limit", "getMinPulseWidthLimit");
|
508
|
+
|
509
|
+
/* Document-method: getMaxPulseWidthLimit
|
510
|
+
* call-seq: getMaxPulseWidthLimit -> pulse_width
|
511
|
+
*
|
512
|
+
* The maximum pulse width that MaxPulseWidth can be set to.
|
513
|
+
*/
|
514
|
+
rb_define_method(ph_rc_servo, "getMaxPulseWidthLimit", ph_rc_servo_get_max_pulse_width_limit, 0);
|
515
|
+
rb_define_alias(ph_rc_servo, "max_pulse_width_limit", "getMaxPulseWidthLimit");
|
516
|
+
|
517
|
+
/* Document-method: getSpeedRampingState
|
518
|
+
* call-seq: getSpeedRampingState -> ramping_state
|
519
|
+
*
|
520
|
+
* When speed ramping state is enabled, the controller will take the Acceleration and Velocity properties into account when moving the
|
521
|
+
* RC servo motor, usually resulting in smooth motion. If speed ramping state is not enabled, the controller will simply set the RC servo motor to the requested position.
|
522
|
+
*/
|
523
|
+
rb_define_method(ph_rc_servo, "getSpeedRampingState", ph_rc_servo_get_speed_ramping_state, 0);
|
524
|
+
rb_define_alias(ph_rc_servo, "speed_ramping_state", "getSpeedRampingState");
|
525
|
+
|
526
|
+
/* Document-method: setSpeedRampingState
|
527
|
+
* call-seq: setSpeedRampingState(ramping_state)
|
528
|
+
*
|
529
|
+
* When speed ramping state is enabled, the controller will take the Acceleration and Velocity properties into account when moving the
|
530
|
+
* RC servo motor, usually resulting in smooth motion. If speed ramping state is not enabled, the controller will simply set the RC servo motor to the requested position.
|
531
|
+
*/
|
532
|
+
rb_define_method(ph_rc_servo, "setSpeedRampingState", ph_rc_servo_set_speed_ramping_state, 1);
|
533
|
+
rb_define_alias(ph_rc_servo, "speed_ramping_state=", "setSpeedRampingState");
|
534
|
+
|
535
|
+
/* Document-method: getTargetPosition
|
536
|
+
* call-seq: getTargetPosition -> position
|
537
|
+
*
|
538
|
+
* If the RC servo motor is configured and TargetPosition is set, the controller will continuously try to reach targeted position.
|
539
|
+
* The target position is bounded by MinPosition and MaxPosition.
|
540
|
+
* If the RC servo motor is not engaged, then the position cannot be read.
|
541
|
+
* The position can still be set while the RC servo motor is not engaged. Once engaged, the RC servo motor will snap to position, assuming it is not there already.
|
542
|
+
* The units for Position,Velocity, and Acceleration are configured by scaling the internal timing (set with MinPulseWidth and MaxPulseWidth) to a user specified range with MinPosition and MaxPosition.
|
543
|
+
*/
|
544
|
+
rb_define_method(ph_rc_servo, "getTargetPosition", ph_rc_servo_get_target_position, 0);
|
545
|
+
rb_define_alias(ph_rc_servo, "target_position", "getTargetPosition");
|
546
|
+
|
547
|
+
/* Document-method: setTargetPosition
|
548
|
+
* call-seq: setTargetPosition(position)
|
549
|
+
*
|
550
|
+
* If the RC servo motor is configured and TargetPosition is set, the controller will continuously try to reach targeted position.
|
551
|
+
* The target position is bounded by MinPosition and MaxPosition.
|
552
|
+
* If the RC servo motor is not engaged, then the position cannot be read.
|
553
|
+
* The position can still be set while the RC servo motor is not engaged. Once engaged, the RC servo motor will snap to position, assuming it is not there already.
|
554
|
+
* The units for Position,Velocity, and Acceleration are configured by scaling the internal timing (set with MinPulseWidth and MaxPulseWidth) to a user specified range with MinPosition and MaxPosition.
|
555
|
+
*/
|
556
|
+
rb_define_method(ph_rc_servo, "setTargetPosition", ph_rc_servo_set_target_position, 1);
|
557
|
+
rb_define_alias(ph_rc_servo, "target_position=", "setTargetPosition");
|
558
|
+
|
559
|
+
/* Document-method: getTorque
|
560
|
+
* call-seq: getTorque -> torque
|
561
|
+
*
|
562
|
+
* The Torque is a ratio of the maximum available torque.
|
563
|
+
* The torque is bounded by MinTorque and MaxTorque
|
564
|
+
* Increasing the torque will increase the speed and power consumption of the RC servo motor.
|
565
|
+
*/
|
566
|
+
rb_define_method(ph_rc_servo, "getTorque", ph_rc_servo_get_torque, 0);
|
567
|
+
rb_define_alias(ph_rc_servo, "torque", "getTorque");
|
568
|
+
|
569
|
+
/* Document-method: setTorque
|
570
|
+
* call-seq: setTorque(torque)
|
571
|
+
*
|
572
|
+
* The Torque is a ratio of the maximum available torque.
|
573
|
+
* The torque is bounded by MinTorque and MaxTorque
|
574
|
+
* Increasing the torque will increase the speed and power consumption of the RC servo motor.
|
575
|
+
*/
|
576
|
+
rb_define_method(ph_rc_servo, "setTorque", ph_rc_servo_set_torque, 1);
|
577
|
+
rb_define_alias(ph_rc_servo, "torque=", "setTorque");
|
578
|
+
|
579
|
+
/* Document-method: getMinTorque
|
580
|
+
* call-seq: getMinTorque -> torque
|
581
|
+
*
|
582
|
+
* The minimum value that Torque can be set to.
|
583
|
+
* Torque is a ratio of the maximum available torque, therefore the minimum torque is a unitless constant.
|
584
|
+
*/
|
585
|
+
rb_define_method(ph_rc_servo, "getMinTorque", ph_rc_servo_get_min_torque, 0);
|
586
|
+
rb_define_alias(ph_rc_servo, "min_torque", "getMinTorque");
|
587
|
+
|
588
|
+
/* Document-method: getMaxTorque
|
589
|
+
* call-seq: getMaxTorque -> torque
|
590
|
+
*
|
591
|
+
* The maximum value that Torque can be set to.
|
592
|
+
* Torque is a ratio of the maximum available torque, therefore the minimum torque is a unitless constant.
|
593
|
+
*/
|
594
|
+
rb_define_method(ph_rc_servo, "getMaxTorque", ph_rc_servo_get_max_torque, 0);
|
595
|
+
rb_define_alias(ph_rc_servo, "max_torque", "getMaxTorque");
|
596
|
+
|
597
|
+
/* Document-method: getVelocity
|
598
|
+
* call-seq: getVelocity -> velocity
|
599
|
+
*
|
600
|
+
* The velocity that the RC servo motor is being driven at.
|
601
|
+
* A negative value means the RC servo motor is moving towards a lower position.
|
602
|
+
* The velocity range of the RC servo motor will be from -VelocityLimit to VelocityLimit, depending on direction.
|
603
|
+
* This is not the actual physical velocity of the RC servo motor.
|
604
|
+
*/
|
605
|
+
rb_define_method(ph_rc_servo, "getVelocity", ph_rc_servo_get_velocity, 0);
|
606
|
+
rb_define_alias(ph_rc_servo, "velocity", "getVelocity");
|
607
|
+
|
608
|
+
/* Document-method: getVelocityLimit
|
609
|
+
* call-seq: getVelocityLimit -> velocity
|
610
|
+
*
|
611
|
+
* When moving, the RC servo motor velocity will be limited by this value.
|
612
|
+
* The velocity limit is bounded by MinVelocityLimit and MaxVelocityLimit.
|
613
|
+
* SpeedRampingState controls whether or not the velocity limit value is actually applied when trying to reach a target position.
|
614
|
+
* The velocity range of the RC servo motor will be from -VelocityLimit to VelocityLimit, depending on direction.
|
615
|
+
* Note that when this value is set to 0, the RC servo motor will not move.
|
616
|
+
* There is a practical limit on how fast your servo can rotate, based on the physical design of the motor.
|
617
|
+
* The units for Position,Velocity, and Acceleration are configured by scaling the internal timing (set with MinPulseWidth and MaxPulseWidth) to a user specified range with MinPosition and MaxPosition.
|
618
|
+
*/
|
619
|
+
rb_define_method(ph_rc_servo, "getVelocityLimit", ph_rc_servo_get_velocity_limit, 0);
|
620
|
+
rb_define_alias(ph_rc_servo, "velocity_limit", "getVelocityLimit");
|
621
|
+
|
622
|
+
/* Document-method: setVelocityLimit
|
623
|
+
* call-seq: setVelocityLimit(velocity)
|
624
|
+
*
|
625
|
+
* When moving, the RC servo motor velocity will be limited by this value.
|
626
|
+
* The velocity limit is bounded by MinVelocityLimit and MaxVelocityLimit.
|
627
|
+
* SpeedRampingState controls whether or not the velocity limit value is actually applied when trying to reach a target position.
|
628
|
+
* The velocity range of the RC servo motor will be from -VelocityLimit to VelocityLimit, depending on direction.
|
629
|
+
* Note that when this value is set to 0, the RC servo motor will not move.
|
630
|
+
* There is a practical limit on how fast your servo can rotate, based on the physical design of the motor.
|
631
|
+
* The units for Position,Velocity, and Acceleration are configured by scaling the internal timing (set with MinPulseWidth and MaxPulseWidth) to a user specified range with MinPosition and MaxPosition.
|
632
|
+
*/
|
633
|
+
rb_define_method(ph_rc_servo, "setVelocityLimit", ph_rc_servo_set_velocity_limit, 1);
|
634
|
+
rb_define_alias(ph_rc_servo, "velocity_limit=", "setVelocityLimit");
|
635
|
+
|
636
|
+
/* Document-method: getMinVelocityLimit
|
637
|
+
* call-seq: getMinVelocityLimit -> velocity
|
638
|
+
*
|
639
|
+
* The minimum velocity VelocityLimit can be set to.
|
640
|
+
*/
|
641
|
+
rb_define_method(ph_rc_servo, "getMinVelocityLimit", ph_rc_servo_get_min_velocity_limit, 0);
|
642
|
+
rb_define_alias(ph_rc_servo, "min_velocity_limit", "getMinVelocityLimit");
|
643
|
+
|
644
|
+
/* Document-method: getMaxVelocityLimit
|
645
|
+
* call-seq: getMaxVelocityLimit -> velocity
|
646
|
+
*
|
647
|
+
* The maximum velocity VelocityLimit can be set to. This value depends on MinPosition/MaxPosition and MinPulseWidth/MaxPulseWidth.
|
648
|
+
*/
|
649
|
+
rb_define_method(ph_rc_servo, "getMaxVelocityLimit", ph_rc_servo_get_max_velocity_limit, 0);
|
650
|
+
rb_define_alias(ph_rc_servo, "max_velocity_limit", "getMaxVelocityLimit");
|
651
|
+
|
652
|
+
/* Document-method: getVoltage
|
653
|
+
* call-seq: getVoltage -> voltage
|
654
|
+
*
|
655
|
+
* The supply voltage for the RC servo motor.
|
656
|
+
* If your controller supports multiple RC servo motors, every motor will have the same supply voltage. It is not possible to set individual supply voltages.
|
657
|
+
*/
|
658
|
+
rb_define_method(ph_rc_servo, "getVoltage", ph_rc_servo_get_voltage, 0);
|
659
|
+
rb_define_alias(ph_rc_servo, "voltage", "getVoltage");
|
660
|
+
|
661
|
+
/* Document-method: setVoltage
|
662
|
+
* call-seq: setVoltage(voltage)
|
663
|
+
*
|
664
|
+
* The supply voltage for the RC servo motor.
|
665
|
+
* If your controller supports multiple RC servo motors, every motor will have the same supply voltage. It is not possible to set individual supply voltages.
|
666
|
+
*/
|
667
|
+
rb_define_method(ph_rc_servo, "setVoltage", ph_rc_servo_set_voltage, 1);
|
668
|
+
rb_define_alias(ph_rc_servo, "voltage=", "setVoltage");
|
669
|
+
|
670
|
+
rb_define_private_method(ph_rc_servo, "ext_setOnPositionChangeHandler", ph_rc_servo_set_on_position_change_handler, 1);
|
671
|
+
}
|
672
|
+
|