phidgets 0.1.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,529 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
#define BLDC_MOTOR_BRAKING_STRENGTH_CHANGE_CALLBACK 0
|
5
|
+
#define BLDC_MOTOR_POSITION_CHANGE_CALLBACK 1
|
6
|
+
#define BLDC_MOTOR_VELOCITY_UPDATE_CALLBACK 2
|
7
|
+
|
8
|
+
|
9
|
+
VALUE ph_bldc_motor_init(VALUE self) {
|
10
|
+
ph_data_t *ph = get_ph_data(self);
|
11
|
+
ph_raise(PhidgetBLDCMotor_create((PhidgetBLDCMotorHandle *)(&(ph->handle))));
|
12
|
+
return self;
|
13
|
+
}
|
14
|
+
|
15
|
+
VALUE ph_bldc_motor_get_acceleration(VALUE self) {
|
16
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getAcceleration);
|
17
|
+
}
|
18
|
+
|
19
|
+
VALUE ph_bldc_motor_set_acceleration(VALUE self, VALUE accel) {
|
20
|
+
ph_raise(PhidgetBLDCMotor_setAcceleration((PhidgetBLDCMotorHandle)get_ph_handle(self), NUM2DBL(accel)));
|
21
|
+
return Qnil;
|
22
|
+
}
|
23
|
+
|
24
|
+
VALUE ph_bldc_motor_get_min_acceleration(VALUE self) {
|
25
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMinAcceleration);
|
26
|
+
}
|
27
|
+
|
28
|
+
VALUE ph_bldc_motor_get_max_acceleration(VALUE self) {
|
29
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMaxAcceleration);
|
30
|
+
}
|
31
|
+
|
32
|
+
VALUE ph_bldc_motor_get_braking_strength(VALUE self) {
|
33
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getBrakingStrength);
|
34
|
+
}
|
35
|
+
|
36
|
+
VALUE ph_bldc_motor_get_min_braking_strength(VALUE self) {
|
37
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMinBrakingStrength);
|
38
|
+
}
|
39
|
+
|
40
|
+
VALUE ph_bldc_motor_get_max_braking_strength(VALUE self) {
|
41
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMaxBrakingStrength);
|
42
|
+
}
|
43
|
+
|
44
|
+
VALUE ph_bldc_motor_get_data_interval(VALUE self) {
|
45
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetBLDCMotor_getDataInterval);
|
46
|
+
}
|
47
|
+
|
48
|
+
VALUE ph_bldc_motor_set_data_interval(VALUE self, VALUE interval) {
|
49
|
+
ph_raise(PhidgetBLDCMotor_setDataInterval((PhidgetBLDCMotorHandle)get_ph_handle(self), NUM2UINT(interval)));
|
50
|
+
return Qnil;
|
51
|
+
}
|
52
|
+
|
53
|
+
VALUE ph_bldc_motor_get_min_data_interval(VALUE self) {
|
54
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetBLDCMotor_getMinDataInterval);
|
55
|
+
}
|
56
|
+
|
57
|
+
VALUE ph_bldc_motor_get_max_data_interval(VALUE self) {
|
58
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetBLDCMotor_getMaxDataInterval);
|
59
|
+
}
|
60
|
+
|
61
|
+
VALUE ph_bldc_motor_get_position(VALUE self) {
|
62
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getPosition);
|
63
|
+
}
|
64
|
+
|
65
|
+
VALUE ph_bldc_motor_get_min_position(VALUE self) {
|
66
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMinPosition);
|
67
|
+
}
|
68
|
+
|
69
|
+
VALUE ph_bldc_motor_get_max_position(VALUE self) {
|
70
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMaxPosition);
|
71
|
+
}
|
72
|
+
|
73
|
+
VALUE ph_bldc_motor_add_position_offset(VALUE self, VALUE offset) {
|
74
|
+
ph_raise(PhidgetBLDCMotor_addPositionOffset((PhidgetBLDCMotorHandle)get_ph_handle(self), NUM2DBL(offset)));
|
75
|
+
return Qnil;
|
76
|
+
}
|
77
|
+
|
78
|
+
VALUE ph_bldc_motor_get_rescale_factor(VALUE self) {
|
79
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getRescaleFactor);
|
80
|
+
}
|
81
|
+
|
82
|
+
VALUE ph_bldc_motor_set_rescale_factor(VALUE self, VALUE rescale_factor) {
|
83
|
+
ph_raise(PhidgetBLDCMotor_setRescaleFactor((PhidgetBLDCMotorHandle)get_ph_handle(self), NUM2DBL(rescale_factor)));
|
84
|
+
return Qnil;
|
85
|
+
}
|
86
|
+
|
87
|
+
VALUE ph_bldc_motor_get_stall_velocity(VALUE self) {
|
88
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getStallVelocity);
|
89
|
+
}
|
90
|
+
|
91
|
+
VALUE ph_bldc_motor_set_stall_velocity(VALUE self, VALUE stall_velocity) {
|
92
|
+
ph_raise(PhidgetBLDCMotor_setStallVelocity((PhidgetBLDCMotorHandle)get_ph_handle(self), NUM2DBL(stall_velocity)));
|
93
|
+
return Qnil;
|
94
|
+
}
|
95
|
+
|
96
|
+
VALUE ph_bldc_motor_get_min_stall_velocity(VALUE self) {
|
97
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMinStallVelocity);
|
98
|
+
}
|
99
|
+
|
100
|
+
VALUE ph_bldc_motor_get_max_stall_velocity(VALUE self) {
|
101
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMaxStallVelocity);
|
102
|
+
}
|
103
|
+
|
104
|
+
VALUE ph_bldc_motor_get_target_braking_strength(VALUE self) {
|
105
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getTargetBrakingStrength);
|
106
|
+
}
|
107
|
+
|
108
|
+
VALUE ph_bldc_motor_set_target_braking_strength(VALUE self, VALUE target_braking_strength) {
|
109
|
+
ph_raise(PhidgetBLDCMotor_setTargetBrakingStrength((PhidgetBLDCMotorHandle)get_ph_handle(self), NUM2DBL(target_braking_strength)));
|
110
|
+
return Qnil;
|
111
|
+
}
|
112
|
+
|
113
|
+
VALUE ph_bldc_motor_get_target_velocity(VALUE self) {
|
114
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getTargetVelocity);
|
115
|
+
}
|
116
|
+
|
117
|
+
VALUE ph_bldc_motor_set_target_velocity(VALUE self, VALUE target_velocity) {
|
118
|
+
ph_raise(PhidgetBLDCMotor_setTargetVelocity((PhidgetBLDCMotorHandle)get_ph_handle(self), NUM2DBL(target_velocity)));
|
119
|
+
return Qnil;
|
120
|
+
}
|
121
|
+
|
122
|
+
VALUE ph_bldc_motor_get_velocity(VALUE self) {
|
123
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getVelocity);
|
124
|
+
}
|
125
|
+
|
126
|
+
VALUE ph_bldc_motor_get_min_velocity(VALUE self) {
|
127
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMinVelocity);
|
128
|
+
}
|
129
|
+
|
130
|
+
VALUE ph_bldc_motor_get_max_velocity(VALUE self) {
|
131
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMaxVelocity);
|
132
|
+
}
|
133
|
+
|
134
|
+
|
135
|
+
void CCONV ph_bldc_motor_on_braking_strength_change(PhidgetBLDCMotorHandle phid, void *userPtr, double braking_strength) {
|
136
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
137
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
138
|
+
callback_data->arg1 = DBL2NUM(braking_strength);
|
139
|
+
callback_data->arg2 = Qnil;
|
140
|
+
callback_data->arg3 = Qnil;
|
141
|
+
callback_data->arg4 = Qnil;
|
142
|
+
sem_post(&callback_data->callback_called);
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
VALUE ph_bldc_motor_set_on_braking_strength_change_handler(VALUE self, VALUE handler) {
|
147
|
+
ph_data_t *ph = get_ph_data(self);
|
148
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[BLDC_MOTOR_BRAKING_STRENGTH_CHANGE_CALLBACK];
|
149
|
+
if( TYPE(handler) == T_NIL ) {
|
150
|
+
callback_data->callback = T_NIL;
|
151
|
+
callback_data->exit = true;
|
152
|
+
ph_raise(PhidgetBLDCMotor_setOnBrakingStrengthChangeHandler((PhidgetBLDCMotorHandle)ph->handle, NULL, (void *)NULL));
|
153
|
+
sem_post(&callback_data->callback_called);
|
154
|
+
} else {
|
155
|
+
callback_data->exit = false;
|
156
|
+
callback_data->phidget = self;
|
157
|
+
callback_data->callback = handler;
|
158
|
+
ph_raise(PhidgetBLDCMotor_setOnBrakingStrengthChangeHandler((PhidgetBLDCMotorHandle)ph->handle, ph_bldc_motor_on_braking_strength_change, (void *)callback_data));
|
159
|
+
ph_callback_thread(callback_data);
|
160
|
+
}
|
161
|
+
return Qnil;
|
162
|
+
}
|
163
|
+
|
164
|
+
|
165
|
+
void CCONV ph_bldc_motor_on_position_change(PhidgetBLDCMotorHandle phid, void *userPtr, double position) {
|
166
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
167
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
168
|
+
callback_data->arg1 = DBL2NUM(position);
|
169
|
+
callback_data->arg2 = Qnil;
|
170
|
+
callback_data->arg3 = Qnil;
|
171
|
+
callback_data->arg4 = Qnil;
|
172
|
+
sem_post(&callback_data->callback_called);
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
VALUE ph_bldc_motor_set_on_position_change_handler(VALUE self, VALUE handler) {
|
177
|
+
ph_data_t *ph = get_ph_data(self);
|
178
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[BLDC_MOTOR_POSITION_CHANGE_CALLBACK];
|
179
|
+
if( TYPE(handler) == T_NIL ) {
|
180
|
+
callback_data->callback = T_NIL;
|
181
|
+
callback_data->exit = true;
|
182
|
+
ph_raise(PhidgetBLDCMotor_setOnPositionChangeHandler((PhidgetBLDCMotorHandle)ph->handle, NULL, (void *)NULL));
|
183
|
+
sem_post(&callback_data->callback_called);
|
184
|
+
} else {
|
185
|
+
callback_data->exit = false;
|
186
|
+
callback_data->phidget = self;
|
187
|
+
callback_data->callback = handler;
|
188
|
+
ph_raise(PhidgetBLDCMotor_setOnPositionChangeHandler((PhidgetBLDCMotorHandle)ph->handle, ph_bldc_motor_on_position_change, (void *)callback_data));
|
189
|
+
ph_callback_thread(callback_data);
|
190
|
+
}
|
191
|
+
return Qnil;
|
192
|
+
}
|
193
|
+
|
194
|
+
|
195
|
+
void CCONV ph_bldc_motor_on_velocity_update(PhidgetBLDCMotorHandle phid, void *userPtr, double velocity) {
|
196
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
197
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
198
|
+
callback_data->arg1 = DBL2NUM(velocity);
|
199
|
+
callback_data->arg2 = Qnil;
|
200
|
+
callback_data->arg3 = Qnil;
|
201
|
+
callback_data->arg4 = Qnil;
|
202
|
+
sem_post(&callback_data->callback_called);
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
VALUE ph_bldc_motor_set_on_velocity_update_handler(VALUE self, VALUE handler) {
|
207
|
+
ph_data_t *ph = get_ph_data(self);
|
208
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[BLDC_MOTOR_VELOCITY_UPDATE_CALLBACK];
|
209
|
+
if( TYPE(handler) == T_NIL ) {
|
210
|
+
callback_data->callback = T_NIL;
|
211
|
+
callback_data->exit = true;
|
212
|
+
ph_raise(PhidgetBLDCMotor_setOnVelocityUpdateHandler((PhidgetBLDCMotorHandle)ph->handle, NULL, (void *)NULL));
|
213
|
+
sem_post(&callback_data->callback_called);
|
214
|
+
} else {
|
215
|
+
callback_data->exit = false;
|
216
|
+
callback_data->phidget = self;
|
217
|
+
callback_data->callback = handler;
|
218
|
+
ph_raise(PhidgetBLDCMotor_setOnVelocityUpdateHandler((PhidgetBLDCMotorHandle)ph->handle, ph_bldc_motor_on_velocity_update, (void *)callback_data));
|
219
|
+
ph_callback_thread(callback_data);
|
220
|
+
}
|
221
|
+
return Qnil;
|
222
|
+
}
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
void Init_bldc_motor() {
|
227
|
+
VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
|
228
|
+
VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
|
229
|
+
VALUE ph_bldc_motor = rb_define_class_under(ph_module, "BLDCMotor", ph_common);
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
/* Document-method: new
|
234
|
+
* call-seq: new
|
235
|
+
*
|
236
|
+
* Creates a Phidget BLDCMotor object.
|
237
|
+
*/
|
238
|
+
rb_define_method(ph_bldc_motor, "initialize", ph_bldc_motor_init, 0);
|
239
|
+
|
240
|
+
/* Document-method: getAcceleration
|
241
|
+
* call-seq: getAcceleration -> acceleration
|
242
|
+
*
|
243
|
+
* The rate at which the controller can change the motor's Velocity.
|
244
|
+
* The acceleration is bounded by MinAccleration and MaxAcceleration.
|
245
|
+
*/
|
246
|
+
rb_define_method(ph_bldc_motor, "getAcceleration", ph_bldc_motor_get_acceleration, 0);
|
247
|
+
rb_define_alias(ph_bldc_motor, "acceleration", "getAcceleration");
|
248
|
+
|
249
|
+
/* Document-method: setAcceleration
|
250
|
+
* call-seq: setAcceleration(acceleration)
|
251
|
+
*
|
252
|
+
* The rate at which the controller can change the motor's Velocity.
|
253
|
+
* The acceleration is bounded by MinAccleration and MaxAcceleration.
|
254
|
+
*/
|
255
|
+
rb_define_method(ph_bldc_motor, "setAcceleration", ph_bldc_motor_set_acceleration, 1);
|
256
|
+
rb_define_alias(ph_bldc_motor, "acceleration=", "setAcceleration");
|
257
|
+
|
258
|
+
/* Document-method: getMinAcceleration
|
259
|
+
* call-seq: getMinAcceleration -> acceleration
|
260
|
+
*
|
261
|
+
* The minimum value that Acceleration can be set to.
|
262
|
+
*/
|
263
|
+
rb_define_method(ph_bldc_motor, "getMinAcceleration", ph_bldc_motor_get_min_acceleration, 0);
|
264
|
+
rb_define_alias(ph_bldc_motor, "min_acceleration", "getMinAcceleration");
|
265
|
+
|
266
|
+
/* Document-method: getMaxAcceleration
|
267
|
+
* call-seq: getMaxAcceleration -> acceleration
|
268
|
+
*
|
269
|
+
* The maximum value that Acceleration can be set to.
|
270
|
+
*/
|
271
|
+
rb_define_method(ph_bldc_motor, "getMaxAcceleration", ph_bldc_motor_get_max_acceleration, 0);
|
272
|
+
rb_define_alias(ph_bldc_motor, "max_acceleration", "getMaxAcceleration");
|
273
|
+
|
274
|
+
/* Document-method: getBrakingStrength
|
275
|
+
* call-seq: getBrakingStrength -> braking_strength
|
276
|
+
*
|
277
|
+
* The most recent braking strength value that the controller has reported.
|
278
|
+
*/
|
279
|
+
rb_define_method(ph_bldc_motor, "getBrakingStrength", ph_bldc_motor_get_braking_strength, 0);
|
280
|
+
rb_define_alias(ph_bldc_motor, "braking_strength", "getBrakingStrength");
|
281
|
+
|
282
|
+
/* Document-method: getMinBrakingStrength
|
283
|
+
* call-seq: getMinBrakingStrength -> braking_strength
|
284
|
+
*
|
285
|
+
* The minimum value that TargetBrakingStrength can be set to.
|
286
|
+
*/
|
287
|
+
rb_define_method(ph_bldc_motor, "getMinBrakingStrength", ph_bldc_motor_get_min_braking_strength, 0);
|
288
|
+
rb_define_alias(ph_bldc_motor, "min_braking_strength", "getMinBrakingStrength");
|
289
|
+
|
290
|
+
/* Document-method: getMaxBrakingStrength
|
291
|
+
* call-seq: getMaxBrakingStrength -> braking_strength
|
292
|
+
*
|
293
|
+
* The maximum value that TargetBrakingStrength can be set to.
|
294
|
+
*/
|
295
|
+
rb_define_method(ph_bldc_motor, "getMaxBrakingStrength", ph_bldc_motor_get_max_braking_strength, 0);
|
296
|
+
rb_define_alias(ph_bldc_motor, "max_braking_strength", "getMaxBrakingStrength");
|
297
|
+
|
298
|
+
/* Document-method: getDataInterval
|
299
|
+
* call-seq: getDataInterval -> interval
|
300
|
+
*
|
301
|
+
* The DataInterval is the time that must elapse before the controller will fire another update event.
|
302
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
303
|
+
*/
|
304
|
+
rb_define_method(ph_bldc_motor, "getDataInterval", ph_bldc_motor_get_data_interval, 0);
|
305
|
+
rb_define_alias(ph_bldc_motor, "data_interval", "getDataInterval");
|
306
|
+
|
307
|
+
/* Document-method: setDataInterval
|
308
|
+
* call-seq: setDataInterval(interval)
|
309
|
+
*
|
310
|
+
* The DataInterval is the time that must elapse before the controller will fire another update event.
|
311
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
312
|
+
*/
|
313
|
+
rb_define_method(ph_bldc_motor, "setDataInterval", ph_bldc_motor_set_data_interval, 1);
|
314
|
+
rb_define_alias(ph_bldc_motor, "data_interval=", "setDataInterval");
|
315
|
+
|
316
|
+
/* Document-method: getMinDataInterval
|
317
|
+
* call-seq: getMinDataInterval -> interval
|
318
|
+
*
|
319
|
+
* The minimum value that DataInterval can be set to.
|
320
|
+
*/
|
321
|
+
rb_define_method(ph_bldc_motor, "getMinDataInterval", ph_bldc_motor_get_min_data_interval, 0);
|
322
|
+
rb_define_alias(ph_bldc_motor, "min_data_interval", "getMinDataInterval");
|
323
|
+
|
324
|
+
/* Document-method: getMaxDataInterval
|
325
|
+
* call-seq: getMaxDataInterval -> interval
|
326
|
+
*
|
327
|
+
* The maximum value that DataInterval can be set to.
|
328
|
+
*/
|
329
|
+
rb_define_method(ph_bldc_motor, "getMaxDataInterval", ph_bldc_motor_get_max_data_interval, 0);
|
330
|
+
rb_define_alias(ph_bldc_motor, "max_data_interval", "getMaxDataInterval");
|
331
|
+
|
332
|
+
/* Document-method: getPosition
|
333
|
+
* call-seq: getPosition -> position
|
334
|
+
*
|
335
|
+
* The most recent position value that the controller has reported.
|
336
|
+
* Position values are calculated using Hall Effect sensors mounted on the motor, therefore, the resolution of position depends on the motor you are using.
|
337
|
+
* Units for Position can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.
|
338
|
+
* For more information on how to apply the RescaleFactor to your application, see your controller's User Guide.
|
339
|
+
*/
|
340
|
+
rb_define_method(ph_bldc_motor, "getPosition", ph_bldc_motor_get_position, 0);
|
341
|
+
rb_define_alias(ph_bldc_motor, "position", "getPosition");
|
342
|
+
|
343
|
+
/* Document-method: getMinPosition
|
344
|
+
* call-seq: getMinPosition -> position
|
345
|
+
*
|
346
|
+
* The lower bound of Position.
|
347
|
+
*/
|
348
|
+
rb_define_method(ph_bldc_motor, "getMinPosition", ph_bldc_motor_get_min_position, 0);
|
349
|
+
rb_define_alias(ph_bldc_motor, "min_position", "getMinPosition");
|
350
|
+
|
351
|
+
/* Document-method: getMaxPosition
|
352
|
+
* call-seq: getMaxPosition -> position
|
353
|
+
*
|
354
|
+
* The upper bound of Position.
|
355
|
+
*/
|
356
|
+
rb_define_method(ph_bldc_motor, "getMaxPosition", ph_bldc_motor_get_max_position, 0);
|
357
|
+
rb_define_alias(ph_bldc_motor, "max_position", "getMaxPosition");
|
358
|
+
|
359
|
+
/* Document-method: addPositionOffset
|
360
|
+
* call-seq: addPositionOffset(position_offset)
|
361
|
+
*
|
362
|
+
* Adds an offset (positive or negative) to the current position.
|
363
|
+
* This can be especially useful for zeroing position.
|
364
|
+
*/
|
365
|
+
rb_define_method(ph_bldc_motor, "addPositionOffset", ph_bldc_motor_add_position_offset, 1);
|
366
|
+
rb_define_alias(ph_bldc_motor, "add_position_offset", "addPositionOffset");
|
367
|
+
|
368
|
+
/* Document-method: getRescaleFactor
|
369
|
+
* call-seq: getRescaleFactor -> rescale_factor
|
370
|
+
*
|
371
|
+
* Change the units of your parameters so that your application is more intuitive.
|
372
|
+
* Units for Position can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.
|
373
|
+
* For more information on how to apply the RescaleFactor to your application, see your controller's User Guide.
|
374
|
+
*/
|
375
|
+
rb_define_method(ph_bldc_motor, "getRescaleFactor", ph_bldc_motor_get_rescale_factor, 0);
|
376
|
+
rb_define_alias(ph_bldc_motor, "rescale_factor", "getRescaleFactor");
|
377
|
+
|
378
|
+
/* Document-method: setRescaleFactor
|
379
|
+
* call-seq: setRescaleFactor(rescale_factor)
|
380
|
+
*
|
381
|
+
* Change the units of your parameters so that your application is more intuitive.
|
382
|
+
* Units for Position can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.
|
383
|
+
* For more information on how to apply the RescaleFactor to your application, see your controller's User Guide.
|
384
|
+
*/
|
385
|
+
rb_define_method(ph_bldc_motor, "setRescaleFactor", ph_bldc_motor_set_rescale_factor, 1);
|
386
|
+
rb_define_alias(ph_bldc_motor, "rescale_factor=", "setRescaleFactor");
|
387
|
+
|
388
|
+
/* Document-method: getStallVelocity
|
389
|
+
* call-seq: getStallVelocity -> stall_velocity
|
390
|
+
*
|
391
|
+
* Before reading this description, it is important to note the difference between the units of StallVelocity and Velocity.
|
392
|
+
* Velocity is a number between -1 and 1 with units of 'duty cycle'. It simply represents the average voltage across the motor.
|
393
|
+
* StallVelocity represents a real velocity (e.g. m/s, RPM, etc.) and the units are determined by the RescaleFactor.
|
394
|
+
* With a RescaleFactor of 1, the default units would be in commutations per second.
|
395
|
+
* If the load on your motor is large, your motor may begin rotating more slowly, or even fully stall. Depending on the voltage across your motor,
|
396
|
+
* this may result in a large amount of current through both the controller and the motor. In order to prevent damage in these situations, you can use the StallVelocity property.
|
397
|
+
|
398
|
+
* The StallVelocity should be set to the lowest velocity you would expect from your motor. The controller will then monitor the motor's velocity,
|
399
|
+
* as well as the Velocity, and prevent a 'dangerous stall' from occuring. If the controller detects a dangerous stall, it will immediately reduce the
|
400
|
+
* Velocity (i.e. average voltage) to 0 and an error will be reported to your program.
|
401
|
+
* A 'dangerous stall' will occur faster when the Velocity is higher (i.e. when the average voltage across the motor is higher)
|
402
|
+
* A 'dangerous stall' will occur faster as (StallVelocity - motor velocity) becomes larger .
|
403
|
+
* Setting StallVelocity to 0 will turn off stall protection functionality.
|
404
|
+
*/
|
405
|
+
rb_define_method(ph_bldc_motor, "getStallVelocity", ph_bldc_motor_get_stall_velocity, 0);
|
406
|
+
rb_define_alias(ph_bldc_motor, "stall_velocity", "getStallVelocity");
|
407
|
+
|
408
|
+
/* Document-method: setStallVelocity
|
409
|
+
* call-seq: setStallVelocity(stall_velocity)
|
410
|
+
*
|
411
|
+
* Before reading this description, it is important to note the difference between the units of StallVelocity and Velocity.
|
412
|
+
* Velocity is a number between -1 and 1 with units of 'duty cycle'. It simply represents the average voltage across the motor.
|
413
|
+
* StallVelocity represents a real velocity (e.g. m/s, RPM, etc.) and the units are determined by the RescaleFactor.
|
414
|
+
* With a RescaleFactor of 1, the default units would be in commutations per second.
|
415
|
+
* If the load on your motor is large, your motor may begin rotating more slowly, or even fully stall. Depending on the voltage across your motor,
|
416
|
+
* this may result in a large amount of current through both the controller and the motor. In order to prevent damage in these situations, you can use the StallVelocity property.
|
417
|
+
|
418
|
+
* The StallVelocity should be set to the lowest velocity you would expect from your motor. The controller will then monitor the motor's velocity,
|
419
|
+
* as well as the Velocity, and prevent a 'dangerous stall' from occuring. If the controller detects a dangerous stall, it will immediately reduce the
|
420
|
+
* Velocity (i.e. average voltage) to 0 and an error will be reported to your program.
|
421
|
+
* A 'dangerous stall' will occur faster when the Velocity is higher (i.e. when the average voltage across the motor is higher)
|
422
|
+
* A 'dangerous stall' will occur faster as (StallVelocity - motor velocity) becomes larger .
|
423
|
+
* Setting StallVelocity to 0 will turn off stall protection functionality.
|
424
|
+
*/
|
425
|
+
rb_define_method(ph_bldc_motor, "setStallVelocity", ph_bldc_motor_set_stall_velocity, 1);
|
426
|
+
rb_define_alias(ph_bldc_motor, "stall_velocity=", "setStallVelocity");
|
427
|
+
|
428
|
+
/* Document-method: getMinStallVelocity
|
429
|
+
* call-seq: getMinStallVelocity -> stall_velocity
|
430
|
+
*
|
431
|
+
* The lower bound of StallVelocity.
|
432
|
+
*/
|
433
|
+
rb_define_method(ph_bldc_motor, "getMinStallVelocity", ph_bldc_motor_get_min_stall_velocity, 0);
|
434
|
+
rb_define_alias(ph_bldc_motor, "min_stall_velocity", "getMinStallVelocity");
|
435
|
+
|
436
|
+
/* Document-method: getMaxStallVelocity
|
437
|
+
* call-seq: getMaxStallVelocity -> stall_velocity
|
438
|
+
*
|
439
|
+
* The upper bound of StallVelocity.
|
440
|
+
*/
|
441
|
+
rb_define_method(ph_bldc_motor, "getMaxStallVelocity", ph_bldc_motor_get_max_stall_velocity, 0);
|
442
|
+
rb_define_alias(ph_bldc_motor, "max_stall_velocity", "getMaxStallVelocity");
|
443
|
+
|
444
|
+
/* Document-method: getTargetBrakingStrength
|
445
|
+
* call-seq: getTargetBrakingStrength -> braking_strength
|
446
|
+
*
|
447
|
+
* When a motor is not being actively driven forward or reverse, you can choose if the motor will be allowed to freely turn, or will resist being turned.
|
448
|
+
* A low TargetBrakingStrength value corresponds to free wheeling, this will have the following effects:
|
449
|
+
* The motor will continue to rotate after the controller is no longer driving the motor (i.e. Velocity is 0), due to inertia.
|
450
|
+
* The motor shaft will provide little resistance to being turned when it is stopped.
|
451
|
+
* A higher TargetBrakingStrength value will resist being turned, this will have the following effects:
|
452
|
+
* The motor will more stop more quickly if it is in motion and braking has been requested. It will fight against the rotation of the shaft.
|
453
|
+
* Braking mode is enabled by setting the Velocity to MinVelocity.
|
454
|
+
*/
|
455
|
+
rb_define_method(ph_bldc_motor, "getTargetBrakingStrength", ph_bldc_motor_get_target_braking_strength, 0);
|
456
|
+
rb_define_alias(ph_bldc_motor, "target_braking_strength", "getTargetBrakingStrength");
|
457
|
+
|
458
|
+
/* Document-method: setTargetBrakingStrength
|
459
|
+
* call-seq: setTargetBrakingStrength(braking_strength)
|
460
|
+
*
|
461
|
+
* When a motor is not being actively driven forward or reverse, you can choose if the motor will be allowed to freely turn, or will resist being turned.
|
462
|
+
* A low TargetBrakingStrength value corresponds to free wheeling, this will have the following effects:
|
463
|
+
* The motor will continue to rotate after the controller is no longer driving the motor (i.e. Velocity is 0), due to inertia.
|
464
|
+
* The motor shaft will provide little resistance to being turned when it is stopped.
|
465
|
+
* A higher TargetBrakingStrength value will resist being turned, this will have the following effects:
|
466
|
+
* The motor will more stop more quickly if it is in motion and braking has been requested. It will fight against the rotation of the shaft.
|
467
|
+
* Braking mode is enabled by setting the Velocity to MinVelocity.
|
468
|
+
*/
|
469
|
+
rb_define_method(ph_bldc_motor, "setTargetBrakingStrength", ph_bldc_motor_set_target_braking_strength, 1);
|
470
|
+
rb_define_alias(ph_bldc_motor, "target_braking_strength=", "setTargetBrakingStrength");
|
471
|
+
|
472
|
+
/* Document-method: getTargetVelocity
|
473
|
+
* call-seq: getTargetVelocity -> velocity
|
474
|
+
*
|
475
|
+
* The average voltage across the motor is based on the TargetVelocity value.
|
476
|
+
* At a constant load, increasing the target velocity will increase the speed of the motor.
|
477
|
+
* TargetVelocity is bounded by -1×MaxVelocity and MaxVelocity, where a sign change (±) is indicitave of a direction change.
|
478
|
+
* Setting TargetVelocity to MinVelocity will stop the motor. See TargetBrakingStrength for more information on stopping the motor.
|
479
|
+
* The units of TargetVelocity and Acceleration refer to 'duty cycle'. This is because the controller must rapidly switch the power
|
480
|
+
* on/off (i.e. change the duty cycle) in order to manipulate the voltage across the motor.
|
481
|
+
*/
|
482
|
+
rb_define_method(ph_bldc_motor, "getTargetVelocity", ph_bldc_motor_get_target_velocity, 0);
|
483
|
+
rb_define_alias(ph_bldc_motor, "target_velocity", "getTargetVelocity");
|
484
|
+
|
485
|
+
/* Document-method: setTargetVelocity
|
486
|
+
* call-seq: setTargetVelocity(velocity)
|
487
|
+
*
|
488
|
+
* The average voltage across the motor is based on the TargetVelocity value.
|
489
|
+
* At a constant load, increasing the target velocity will increase the speed of the motor.
|
490
|
+
* TargetVelocity is bounded by -1×MaxVelocity and MaxVelocity, where a sign change (±) is indicitave of a direction change.
|
491
|
+
* Setting TargetVelocity to MinVelocity will stop the motor. See TargetBrakingStrength for more information on stopping the motor.
|
492
|
+
* The units of TargetVelocity and Acceleration refer to 'duty cycle'. This is because the controller must rapidly switch the power
|
493
|
+
* on/off (i.e. change the duty cycle) in order to manipulate the voltage across the motor.
|
494
|
+
*/
|
495
|
+
rb_define_method(ph_bldc_motor, "setTargetVelocity", ph_bldc_motor_set_target_velocity, 1);
|
496
|
+
rb_define_alias(ph_bldc_motor, "target_velocity=", "setTargetVelocity");
|
497
|
+
|
498
|
+
/* Document-method: getVelocity
|
499
|
+
* call-seq: getVelocity -> velocity
|
500
|
+
*
|
501
|
+
* The most recent velocity value that the controller has reported.
|
502
|
+
*/
|
503
|
+
rb_define_method(ph_bldc_motor, "getVelocity", ph_bldc_motor_get_velocity, 0);
|
504
|
+
rb_define_alias(ph_bldc_motor, "velocity", "getVelocity");
|
505
|
+
|
506
|
+
/* Document-method: getMinVelocity
|
507
|
+
* call-seq: getMinVelocity -> velocity
|
508
|
+
*
|
509
|
+
* The minimum value that TargetVelocity can be set to
|
510
|
+
* Set the TargetVelocity to MinVelocity to stop the motor. See TargetBrakingStrength for more information on stopping the motor.
|
511
|
+
* TargetVelocity is bounded by -1×MaxVelocity and MaxVelocity, where a sign change (±) is indicitave of a direction change.
|
512
|
+
*/
|
513
|
+
rb_define_method(ph_bldc_motor, "getMinVelocity", ph_bldc_motor_get_min_velocity, 0);
|
514
|
+
rb_define_alias(ph_bldc_motor, "min_velocity", "getMinVelocity");
|
515
|
+
|
516
|
+
/* Document-method: getMaxVelocity
|
517
|
+
* call-seq: getMaxVelocity -> velocity
|
518
|
+
*
|
519
|
+
* The maximum value that TargetVelocity can be set to.
|
520
|
+
* TargetVelocity is bounded by -1×MaxVelocity and MaxVelocity, where a sign change (±) is indicitave of a direction change.
|
521
|
+
*/
|
522
|
+
rb_define_method(ph_bldc_motor, "getMaxVelocity", ph_bldc_motor_get_max_velocity, 0);
|
523
|
+
rb_define_alias(ph_bldc_motor, "max_velocity", "getMaxVelocity");
|
524
|
+
|
525
|
+
rb_define_private_method(ph_bldc_motor, "ext_setOnBrakingStrengthChangeHandler", ph_bldc_motor_set_on_braking_strength_change_handler, 1);
|
526
|
+
rb_define_private_method(ph_bldc_motor, "ext_setOnPositionChangeHandler", ph_bldc_motor_set_on_position_change_handler, 1);
|
527
|
+
rb_define_private_method(ph_bldc_motor, "ext_setOnVelocityUpdateHandler", ph_bldc_motor_set_on_velocity_update_handler, 1);
|
528
|
+
}
|
529
|
+
|