Class: Phidgets::MotorPositionController

Inherits:
Common
  • Object
show all
Defined in:
lib/phidgets/motor_position_controller.rb,
ext/phidgets/phidgets_motor_position_controller.c

Instance Method Summary collapse

Methods inherited from Common

#close, #getAttached, #getChannel, #getChannelClass, #getChannelClassName, #getChannelName, #getChannelSubclass, #getDeviceChannelCount, #getDeviceClass, #getDeviceClassName, #getDeviceID, #getDeviceLabel, #getDeviceName, #getDeviceSKU, #getDeviceSerialNumber, #getDeviceVersion, #getHubPort, #getHubPortCount, #getIsChannel, #getIsHubPortDevice, #getIsLocal, #getIsRemote, #getServerHostname, #getServerName, #getServerPeerName, #getServerUniqueName, #open, #openWaitForAttachment, #setChannel, #setDeviceLabel, #setDeviceSerialNumber, #setHubPort, #setIsHubPortDevice, #setIsLocal, #setIsRemote, #setOnAttachHandler, #setOnDetachHandler, #setOnErrorHandler, #setOnPropertyChangeHandler, #setServerName, #writeDeviceLabel

Constructor Details

#newObject

Creates a Phidget MotorPositionController object.



10
11
12
13
14
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 10

VALUE ph_motor_init(VALUE self) {
  ph_data_t *ph = get_ph_data(self);
  ph_raise(PhidgetMotorPositionController_create((PhidgetMotorPositionControllerHandle *)(&(ph->handle))));
  return self;
}

Instance Method Details

#addPositionOffset(offset) ⇒ Object Also known as: add_position_offset

Adds an offset (positive or negative) to the current position. Useful for zeroing position.



163
164
165
166
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 163

VALUE ph_motor_add_position_offset(VALUE self, VALUE offset) {
  ph_raise(PhidgetMotorPositionController_addPositionOffset((PhidgetMotorPositionControllerHandle)get_ph_handle(self), NUM2DBL(offset)));
  return Qnil;
}

#getAccelerationObject Also known as: acceleration

The rate at which the controller can change the motor’s velocity. Units for Position, VelocityLimit, Acceleration, and DeadBand can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



16
17
18
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 16

VALUE ph_motor_get_acceleration(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getAcceleration);
}

#getCurrentLimitObject Also known as: current_limit

The controller will limit the current through the motor to this value.



33
34
35
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 33

VALUE ph_motor_get_current_limit(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getCurrentLimit);
}

#getCurrentRegulatorGainObject Also known as: current_regulator_gain

Depending on power supply voltage and motor coil inductance, current through the motor can change relatively slowly or extremely rapidly. A physically larger DC Motor will typically have a lower inductance, requiring a higher current regulator gain. A higher power supply voltage will result in motor current changing more rapidly, requiring a higher current regulator gain. If the current regulator gain is too small, spikes in current will occur, causing large variations in torque, and possibly damaging the motor controller. If the current regulator gain is too high, the current will jitter, causing the motor to sound ‘rough’, especially when changing directions.



50
51
52
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 50

VALUE ph_motor_get_current_regulator_gain(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getCurrentRegulatorGain);
}

#getDataIntervalObject Also known as: data_interval

The DataInterval is the time that must elapse before the controller will fire another CurrentChange event. The data interval is bounded by MinDataInterval and MaxDataInterval. The timing between CurrentChange events can also affected by the CurrentChangeTrigger.



67
68
69
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 67

VALUE ph_motor_get_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetMotorPositionController_getDataInterval);
}

#getDeadBandObject Also known as: dead_band

Depending on your system, it may not be possible to bring the position error (TargetPosition - Position) to zero. A small error can lead to the motor continually ‘hunting’ for a target position, which can cause unwanted effects. By setting a non-zero DeadBand, the position controller will relax control of the motor within the deadband, preventing the ‘hunting’ behavior. Units for Position, VelocityLimit, Acceleration, and DeadBand can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



84
85
86
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 84

VALUE ph_motor_get_dead_band(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getDeadBand);
}

#getDutyCycleObject Also known as: duty_cycle

The most recent duty cycle value that the controller has reported. This value will be between -1 and 1 where a sign change (±) is indicitave of a direction change. Note that DutyCycle is merely an indication of the average voltage across the motor. At a constant load, an increase in DutyCycle indicates an increase in motor speed. The units of DutyCycle refer to ‘duty cycle’. This is because the controller must rapidly switch the power on/off (i.e. change the duty cycle) in order to manipulate the voltage across the motor.



93
94
95
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 93

VALUE ph_motor_get_duty_cycle(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getDutyCycle);
}

#getEngagedObject Also known as: engaged?

When engaged, a motor has the ability to be positioned. When disengaged, no commands are sent to the motor. This function is useful for completely relaxing a motor once it has reached the target position.



97
98
99
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 97

VALUE ph_motor_get_engaged(VALUE self) {
  return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetMotorPositionController_getEngaged);
}

#getFanModeObject Also known as: fan_mode

The FanMode dictates the operating condition of the fan. Choose between on, off, or automatic (based on temperature). If the FanMode is set to automatic, the fan will turn on when the temperature reaches 70°C and it will remain on until the temperature falls below 55°C. If the FanMode is off, the controller will still turn on the fan if the temperature reaches 85°C and it will remain on until it falls below 70°C.



106
107
108
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 106

VALUE ph_motor_get_fan_mode(VALUE self) {
  return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetMotorPositionController_getFanMode);
}

#getIOModeObject Also known as: io_mode

The encoder interface mode. Match the mode to the type of encoder you have attached. It is recommended to only change this when the encoder is disabled in order to avoid unexpected results.



115
116
117
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 115

VALUE ph_motor_get_io_mode(VALUE self) {
  return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetMotorPositionController_getIOMode);
}

#getKdObject Also known as: kd

Derivative gain constant. A higher Kd will help reduce oscillations.



124
125
126
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 124

VALUE ph_motor_get_kd(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getKd);
}

#getKiObject Also known as: ki

Integral gain constant. The integral term will help eliminate steady-state error.



133
134
135
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 133

VALUE ph_motor_get_ki(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getKi);
}

#getKpObject Also known as: kp

Proportional gain constant. A small Kp value will result in a less responsive controller, however, if Kp is too high, the system can become unstable.



142
143
144
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 142

VALUE ph_motor_get_kp(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getKp);
}

#getMaxAccelerationObject Also known as: max_acceleration

The maximum value that Acceleration can be set to. Units for Position, VelocityLimit, Acceleration, and DeadBand can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



29
30
31
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 29

VALUE ph_motor_get_max_acceleration(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getMaxAcceleration);
}

#getMaxCurrentLimitObject Also known as: max_current_limit

The maximum current limit that can be set for the device.



46
47
48
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 46

VALUE ph_motor_get_max_current_limit(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getMaxCurrentLimit);
}

#getMaxCurrentRegulatorGainObject Also known as: max_current_regulator_gain

The maximum current regulator gain for the device.



63
64
65
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 63

VALUE ph_motor_get_max_current_regulator_gain(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getMaxCurrentRegulatorGain);
}

#getMaxDataIntervalObject Also known as: max_data_interval

The maximum value that DataInterval can be set to.



80
81
82
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 80

VALUE ph_motor_get_max_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetMotorPositionController_getMaxDataInterval);
}

#getMaxPositionObject Also known as: max_position

The maximum value that TargetPosition can be set to.



159
160
161
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 159

VALUE ph_motor_get_max_position(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getMaxPosition);
}

#getMaxStallVelocityObject Also known as: max_stall_velocity

The upper bound of StallVelocity.



190
191
192
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 190

VALUE ph_motor_get_max_stall_velocity(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getMaxStallVelocity);
}

#getMaxVelocityLimitObject Also known as: max_velocity_limit

The maximum value that VelocityLimit can be set to.



216
217
218
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 216

VALUE ph_motor_get_max_velocity_limit(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getMaxVelocityLimit);
}

#getMinAccelerationObject Also known as: min_acceleration

The minimum value that Acceleration can be set to. Units for Position, VelocityLimit, Acceleration, and DeadBand can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



25
26
27
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 25

VALUE ph_motor_get_min_acceleration(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getMinAcceleration);
}

#getMinCurrentLimitObject Also known as: min_current_limit

The minimum current limit that can be set for the device.



42
43
44
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 42

VALUE ph_motor_get_min_current_limit(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getMinCurrentLimit);
}

#getMinCurrentRegulatorGainObject Also known as: min_current_regulator_gain

The minimum current regulator gain for the device.



59
60
61
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 59

VALUE ph_motor_get_min_current_regulator_gain(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getMinCurrentRegulatorGain);
}

#getMinDataIntervalObject Also known as: min_data_interval

The minimum value that DataInterval can be set to.



76
77
78
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 76

VALUE ph_motor_get_min_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetMotorPositionController_getMinDataInterval);
}

#getMinPositionObject Also known as: min_position

The minimum value that TargetPosition can be set to.



155
156
157
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 155

VALUE ph_motor_get_min_position(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getMinPosition);
}

#getMinStallVelocityObject Also known as: min_stall_velocity

The lower bound of StallVelocity.



186
187
188
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 186

VALUE ph_motor_get_min_stall_velocity(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getMinStallVelocity);
}

#getMinVelocityLimitObject Also known as: min_velocity_limit

The minimum value that VelocityLimit can be set to.



212
213
214
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 212

VALUE ph_motor_get_min_velocity_limit(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getMinVelocityLimit);
}

#getPositionObject Also known as: position

The most recent position value that the controller has reported. This value will always be between MinPosition and MaxPosition. Units for Position, VelocityLimit, Acceleration, and DeadBand can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



151
152
153
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 151

VALUE ph_motor_get_position(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getPosition);
}

#getRescaleFactorObject Also known as: rescale_factor

Change the units of your parameters so that your application is more intuitive. Units for Position, VelocityLimit, Acceleration, and DeadBand can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



168
169
170
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 168

VALUE ph_motor_get_rescale_factor(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getRescaleFactor);
}

#getStallVelocityObject Also known as: stall_velocity

Before reading this description, it is important to note the difference between the units of StallVelocity and Velocity. Velocity is a number between -1 and 1 with units of ‘duty cycle’. It simply represents the average voltage across the motor. StallVelocity represents a real velocity (e.g. m/s, RPM, etc.) and the units are determined by the RescaleFactor. With a RescaleFactor of 1, the default units would be in commutations per second. 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, 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.

The StallVelocity should be set to the lowest velocity you would expect from your motor. The controller will then monitor the motor’s velocity, as well as the Velocity, and prevent a ‘dangerous stall’ from occuring. If the controller detects a dangerous stall, it will immediately disengage the motor (i.e. Engaged will be set to false) and an error will be reported to your program. A ‘dangerous stall’ will occur faster when the Velocity is higher (i.e. when the average voltage across the motor is higher) A ‘dangerous stall’ will occur faster as (StallVelocity - motor velocity) becomes larger . Setting StallVelocity to 0 will turn off stall protection functionality.



177
178
179
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 177

VALUE ph_motor_get_stall_velocity(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getStallVelocity);
}

#getTargetPositionObject Also known as: target_position

If the controller is configured and the TargetPosition is set, the motor will try to reach the TargetPosition. If the DeadBand is non-zero, the final position of the motor may not match the TargetPosition Units for Position, VelocityLimit, Acceleration, and DeadBand can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



194
195
196
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 194

VALUE ph_motor_get_target_position(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getTargetPosition);
}

#getVelocityLimitObject Also known as: velocity_limit

When moving, the motor velocity will be limited by this value. VelocityLimit is bounded by MinVelocityLimit and MaxVelocityLimit. Units for Position, VelocityLimit, Acceleration, and DeadBand can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



203
204
205
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 203

VALUE ph_motor_get_velocity_limit(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMotorPositionController_getVelocityLimit);
}

#setAcceleration(acceleration) ⇒ Object Also known as: acceleration=

The rate at which the controller can change the motor’s velocity. Units for Position, VelocityLimit, Acceleration, and DeadBand can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



20
21
22
23
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 20

VALUE ph_motor_set_acceleration(VALUE self, VALUE accel) {
  ph_raise(PhidgetMotorPositionController_setAcceleration((PhidgetMotorPositionControllerHandle)get_ph_handle(self), NUM2DBL(accel)));
  return Qnil;
}

#setCurrentLimit(current_limit) ⇒ Object Also known as: current_limit=

The controller will limit the current through the motor to this value.



37
38
39
40
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 37

VALUE ph_motor_set_current_limit(VALUE self, VALUE current) {
  ph_raise(PhidgetMotorPositionController_setCurrentLimit((PhidgetMotorPositionControllerHandle)get_ph_handle(self), NUM2DBL(current)));
  return Qnil;
}

#setCurrentRegulatorGain(regulator_gain) ⇒ Object Also known as: current_regulator_gain=

Depending on power supply voltage and motor coil inductance, current through the motor can change relatively slowly or extremely rapidly. A physically larger DC Motor will typically have a lower inductance, requiring a higher current regulator gain. A higher power supply voltage will result in motor current changing more rapidly, requiring a higher current regulator gain. If the current regulator gain is too small, spikes in current will occur, causing large variations in torque, and possibly damaging the motor controller. If the current regulator gain is too high, the current will jitter, causing the motor to sound ‘rough’, especially when changing directions.



54
55
56
57
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 54

VALUE ph_motor_set_current_regulator_gain(VALUE self, VALUE gain) {
  ph_raise(PhidgetMotorPositionController_setCurrentRegulatorGain((PhidgetMotorPositionControllerHandle)get_ph_handle(self), NUM2DBL(gain)));
  return Qnil;
}

#setDataInterval(interval) ⇒ Object Also known as: data_interval=

The DataInterval is the time that must elapse before the controller will fire another CurrentChange event. The data interval is bounded by MinDataInterval and MaxDataInterval. The timing between CurrentChange events can also affected by the CurrentChangeTrigger.



71
72
73
74
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 71

VALUE ph_motor_set_data_interval(VALUE self, VALUE interval) {
  ph_raise(PhidgetMotorPositionController_setDataInterval((PhidgetMotorPositionControllerHandle)get_ph_handle(self), NUM2UINT(interval)));
  return Qnil;
}

#setDeadBand(dead_band) ⇒ Object Also known as: dead_band=

Depending on your system, it may not be possible to bring the position error (TargetPosition - Position) to zero. A small error can lead to the motor continually ‘hunting’ for a target position, which can cause unwanted effects. By setting a non-zero DeadBand, the position controller will relax control of the motor within the deadband, preventing the ‘hunting’ behavior. Units for Position, VelocityLimit, Acceleration, and DeadBand can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



88
89
90
91
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 88

VALUE ph_motor_set_dead_band(VALUE self, VALUE dead_band) {
  ph_raise(PhidgetMotorPositionController_setDeadBand((PhidgetMotorPositionControllerHandle)get_ph_handle(self), NUM2DBL(dead_band)));
  return Qnil;
}

#setEngaged(engaged) ⇒ Object Also known as: engaged=

When engaged, a motor has the ability to be positioned. When disengaged, no commands are sent to the motor. This function is useful for completely relaxing a motor once it has reached the target position.



101
102
103
104
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 101

VALUE ph_motor_set_engaged(VALUE self, VALUE engaged) {
  ph_raise(PhidgetMotorPositionController_setEngaged((PhidgetMotorPositionControllerHandle)get_ph_handle(self), TYPE(engaged) == T_TRUE ? PTRUE : PFALSE));
  return Qnil;
}

#setFanMode(fan_mode) ⇒ Object Also known as: fan_mode=

The FanMode dictates the operating condition of the fan. Choose between on, off, or automatic (based on temperature). If the FanMode is set to automatic, the fan will turn on when the temperature reaches 70°C and it will remain on until the temperature falls below 55°C. If the FanMode is off, the controller will still turn on the fan if the temperature reaches 85°C and it will remain on until it falls below 70°C.



110
111
112
113
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 110

VALUE ph_motor_set_fan_mode(VALUE self, VALUE fan_mode) {
  ph_raise(PhidgetMotorPositionController_setFanMode((PhidgetMotorPositionControllerHandle)get_ph_handle(self), NUM2INT(fan_mode)));
  return Qnil;
}

#setIOMode(io_mode) ⇒ Object Also known as: io_mode=

The encoder interface mode. Match the mode to the type of encoder you have attached. It is recommended to only change this when the encoder is disabled in order to avoid unexpected results.



119
120
121
122
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 119

VALUE ph_motor_set_io_mode(VALUE self, VALUE io_mode) {
  ph_raise(PhidgetMotorPositionController_setIOMode((PhidgetMotorPositionControllerHandle)get_ph_handle(self), NUM2INT(io_mode)));
  return Qnil;
}

#setKd(kd) ⇒ Object Also known as: kd=

Derivative gain constant. A higher Kd will help reduce oscillations.



128
129
130
131
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 128

VALUE ph_motor_set_kd(VALUE self, VALUE kd) {
  ph_raise(PhidgetMotorPositionController_setKd((PhidgetMotorPositionControllerHandle)get_ph_handle(self), NUM2DBL(kd)));
  return Qnil;
}

#setKi(ki) ⇒ Object Also known as: ki=

Integral gain constant. The integral term will help eliminate steady-state error.



137
138
139
140
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 137

VALUE ph_motor_set_ki(VALUE self, VALUE ki) {
  ph_raise(PhidgetMotorPositionController_setKi((PhidgetMotorPositionControllerHandle)get_ph_handle(self), NUM2DBL(ki)));
  return Qnil;
}

#setKp(kp) ⇒ Object Also known as: kp=

Proportional gain constant. A small Kp value will result in a less responsive controller, however, if Kp is too high, the system can become unstable.



146
147
148
149
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 146

VALUE ph_motor_set_kp(VALUE self, VALUE kp) {
  ph_raise(PhidgetMotorPositionController_setKp((PhidgetMotorPositionControllerHandle)get_ph_handle(self), NUM2DBL(kp)));
  return Qnil;
}

#setOnDutyCycleUpdateHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_duty_cycle_update

call-seq:

setOnDutyCycleUpdateHandler(proc=nil, &block)

Assigns a handler that will be called when the DutyCycleUpdate event occurs.



11
12
13
14
15
# File 'lib/phidgets/motor_position_controller.rb', line 11

def setOnDutyCycleUpdateHandler(cb_proc = nil, &cb_block)
  @on_duty_cycle_update_thread.kill if defined? @on_duty_cycle_update_thread and @on_duty_cycle_update_thread.alive?
  callback = cb_proc || cb_block
  @on_duty_cycle_update_thread = Thread.new {ext_setOnDutyCycleUpdateHandler(callback)}
end

#setOnPositionChangeHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_position_change

call-seq:

setOnPositionChangeHandler(proc=nil, &block)

Assigns a handler that will be called when the PositionChange event occurs.



22
23
24
25
26
# File 'lib/phidgets/motor_position_controller.rb', line 22

def setOnPositionChangeHandler(cb_proc = nil, &cb_block)
  @on_position_change_thread.kill if defined? @on_position_change_thread and @on_position_change_thread.alive?
  callback = cb_proc || cb_block
  @on_position_change_thread = Thread.new {ext_setOnPositionChangeHandler(callback)}
end

#setRescaleFactor(rescale_factor) ⇒ Object Also known as: rescale_factor=

Change the units of your parameters so that your application is more intuitive. Units for Position, VelocityLimit, Acceleration, and DeadBand can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



172
173
174
175
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 172

VALUE ph_motor_set_rescale_factor(VALUE self, VALUE rescale_factor) {
  ph_raise(PhidgetMotorPositionController_setRescaleFactor((PhidgetMotorPositionControllerHandle)get_ph_handle(self), NUM2DBL(rescale_factor)));
  return Qnil;
}

#setStallVelocity(stall_velocity) ⇒ Object Also known as: stall_velocity=

Before reading this description, it is important to note the difference between the units of StallVelocity and Velocity. Velocity is a number between -1 and 1 with units of ‘duty cycle’. It simply represents the average voltage across the motor. StallVelocity represents a real velocity (e.g. m/s, RPM, etc.) and the units are determined by the RescaleFactor. With a RescaleFactor of 1, the default units would be in commutations per second. 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, 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.

The StallVelocity should be set to the lowest velocity you would expect from your motor. The controller will then monitor the motor’s velocity, as well as the Velocity, and prevent a ‘dangerous stall’ from occuring. If the controller detects a dangerous stall, it will immediately disengage the motor (i.e. Engaged will be set to false) and an error will be reported to your program. A ‘dangerous stall’ will occur faster when the Velocity is higher (i.e. when the average voltage across the motor is higher) A ‘dangerous stall’ will occur faster as (StallVelocity - motor velocity) becomes larger . Setting StallVelocity to 0 will turn off stall protection functionality.



181
182
183
184
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 181

VALUE ph_motor_set_stall_velocity(VALUE self, VALUE stall_velocity) {
  ph_raise(PhidgetMotorPositionController_setStallVelocity((PhidgetMotorPositionControllerHandle)get_ph_handle(self), NUM2DBL(stall_velocity)));
  return Qnil;
}

#setTargetPosition(target_position) ⇒ Object Also known as: target_position=

If the controller is configured and the TargetPosition is set, the motor will try to reach the TargetPosition. If the DeadBand is non-zero, the final position of the motor may not match the TargetPosition Units for Position, VelocityLimit, Acceleration, and DeadBand can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



198
199
200
201
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 198

VALUE ph_motor_set_target_position(VALUE self, VALUE target_position) {
  ph_raise(PhidgetMotorPositionController_setTargetPosition((PhidgetMotorPositionControllerHandle)get_ph_handle(self), NUM2DBL(target_position)));
  return Qnil;
}

#setTargetPosition_async(position, cb_proc = nil, &cb_block) ⇒ Object Also known as: set_target_position_async

call-seq:

setTargetPosition_async(proc=nil, &block)

If the controller is configured and the TargetPosition is set, the motor will try to reach the TargetPostiion.



33
34
35
36
37
# File 'lib/phidgets/motor_position_controller.rb', line 33

def setTargetPosition_async(position, cb_proc = nil, &cb_block)
  @target_position_async_thread.kill if defined? @target_position_async_thread and @target_position_async_thread.alive?
  callback = cb_proc || cb_block
  @target_position_async_thread = Thread.new {ext_setTargetPosition_async(position, callback)}
end

#setVelocityLimit(velocity_limit) ⇒ Object Also known as: velocity_limit=

When moving, the motor velocity will be limited by this value. VelocityLimit is bounded by MinVelocityLimit and MaxVelocityLimit. Units for Position, VelocityLimit, Acceleration, and DeadBand can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



207
208
209
210
# File 'ext/phidgets/phidgets_motor_position_controller.c', line 207

VALUE ph_motor_set_velocity_limit(VALUE self, VALUE velocity) {
  ph_raise(PhidgetMotorPositionController_setVelocityLimit((PhidgetMotorPositionControllerHandle)get_ph_handle(self), NUM2DBL(velocity)));
  return Qnil;
}