Class: Phidgets::DCMotor

Inherits:
Common
  • Object
show all
Defined in:
lib/phidgets/dc_motor.rb,
ext/phidgets/phidgets_dc_motor.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 DCMotor object.



9
10
11
12
13
# File 'ext/phidgets/phidgets_dc_motor.c', line 9

VALUE ph_dc_motor_init(VALUE self) {
  ph_data_t *ph = get_ph_data(self);
  ph_raise(PhidgetDCMotor_create((PhidgetDCMotorHandle *)(&(ph->handle))));
  return self;
}

Instance Method Details

#getAccelerationObject Also known as: acceleration

The rate at which the controller can change the motor’s Velocity. The acceleration is bounded by MinAccleration and MaxAcceleration.



15
16
17
# File 'ext/phidgets/phidgets_dc_motor.c', line 15

VALUE ph_dc_motor_get_acceleration(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getAcceleration);
}

#getBackEMFObject Also known as: back_emf

The most recent BackEMF value that the controller has reported.



32
33
34
# File 'ext/phidgets/phidgets_dc_motor.c', line 32

VALUE ph_dc_motor_get_back_emf(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getBackEMF);
}

#getBackEMFSensingStateObject Also known as: back_emf_sensing_state

When BackEMFSensingState is enabled, the controller will measure and report the BackEMF. The motor will coast (freewheel) 5% of the time while the back EMF is being measured (800μs every 16ms). Therefore, at a DutyCycle of 100%, the motor will only be driven for 95% of the time.



36
37
38
# File 'ext/phidgets/phidgets_dc_motor.c', line 36

VALUE ph_dc_motor_get_back_emf_sensing_state(VALUE self) {
  return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetDCMotor_getBackEMFSensingState);
}

#getBrakingStrengthObject Also known as: braking_strength

The most recent braking strength value that the controller has reported.



45
46
47
# File 'ext/phidgets/phidgets_dc_motor.c', line 45

VALUE ph_dc_motor_get_braking_strength(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getBrakingStrength);
}

#getCurrentLimitObject Also known as: current_limit

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



57
58
59
# File 'ext/phidgets/phidgets_dc_motor.c', line 57

VALUE ph_dc_motor_get_current_limit(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_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. Each DC Motor we sell specifies a suitable current regulator gain.



74
75
76
# File 'ext/phidgets/phidgets_dc_motor.c', line 74

VALUE ph_dc_motor_get_current_regulator_gain(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getCurrentRegulatorGain);
}

#getDataIntervalObject Also known as: data_interval

The DataInterval is the time that must elapse before the controller will fire another update event. The data interval is bounded by MinDataInterval and MaxDataInterval.



91
92
93
# File 'ext/phidgets/phidgets_dc_motor.c', line 91

VALUE ph_dc_motor_get_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetDCMotor_getDataInterval);
}

#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.



108
109
110
# File 'ext/phidgets/phidgets_dc_motor.c', line 108

VALUE ph_dc_motor_get_fan_mode(VALUE self) {
  return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetDCMotor_getFanMode);
}

#getMaxAccelerationObject Also known as: max_acceleration

The maximum value that Acceleration can be set to.



28
29
30
# File 'ext/phidgets/phidgets_dc_motor.c', line 28

VALUE ph_dc_motor_get_max_acceleration(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMaxAcceleration);
}

#getMaxBrakingStrengthObject Also known as: max_braking_strength

The maximum value that TargetBrakingStrength can be set to.



53
54
55
# File 'ext/phidgets/phidgets_dc_motor.c', line 53

VALUE ph_dc_motor_get_max_braking_strength(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMaxBrakingStrength);
}

#getMaxCurrentLimitObject Also known as: max_current_limit

The maximum value that CurrentLimit can be set to.



70
71
72
# File 'ext/phidgets/phidgets_dc_motor.c', line 70

VALUE ph_dc_motor_get_max_current_limit(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMaxCurrentLimit);
}

#getMaxCurrentRegulatorGainObject Also known as: max_current_regulator_gain

The maximum value that CurrentRegulatorGain can be set to.



87
88
89
# File 'ext/phidgets/phidgets_dc_motor.c', line 87

VALUE ph_dc_motor_get_max_current_regulator_gain(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMaxCurrentRegulatorGain);
}

#getMaxDataIntervalObject Also known as: max_data_interval

The maximum value that DataInterval can be set to.



104
105
106
# File 'ext/phidgets/phidgets_dc_motor.c', line 104

VALUE ph_dc_motor_get_max_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetDCMotor_getMaxDataInterval);
}

#getMaxVelocityObject Also known as: max_velocity

The maximum value that TargetVelocity can be set to. TargetVelocity is bounded by -1×MaxVelocity and MaxVelocity, where a sign change (±) is indicitave of a direction change.



143
144
145
# File 'ext/phidgets/phidgets_dc_motor.c', line 143

VALUE ph_dc_motor_get_max_velocity(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMaxVelocity);
}

#getMinAccelerationObject Also known as: min_acceleration

The minimum value that Acceleration can be set to.



24
25
26
# File 'ext/phidgets/phidgets_dc_motor.c', line 24

VALUE ph_dc_motor_get_min_acceleration(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMinAcceleration);
}

#getMinBrakingStrengthObject Also known as: min_braking_strength

The minimum value that TargetBrakingStrength can be set to.



49
50
51
# File 'ext/phidgets/phidgets_dc_motor.c', line 49

VALUE ph_dc_motor_get_min_braking_strength(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMinBrakingStrength);
}

#getMinCurrentLimitObject Also known as: min_current_limit

The minimum value that CurrentLimit can be set to.



66
67
68
# File 'ext/phidgets/phidgets_dc_motor.c', line 66

VALUE ph_dc_motor_get_min_current_limit(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMinCurrentLimit);
}

#getMinCurrentRegulatorGainObject Also known as: min_current_regulator_gain

The minimum value that CurrentRegulatorGain can be set to.



83
84
85
# File 'ext/phidgets/phidgets_dc_motor.c', line 83

VALUE ph_dc_motor_get_min_current_regulator_gain(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMinCurrentRegulatorGain);
}

#getMinDataIntervalObject Also known as: min_data_interval

The minimum value that DataInterval can be set to.



100
101
102
# File 'ext/phidgets/phidgets_dc_motor.c', line 100

VALUE ph_dc_motor_get_min_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetDCMotor_getMinDataInterval);
}

#getMinVelocityObject Also known as: min_velocity

The minimum value that TargetVelocity can be set to Set the TargetVelocity to MinVelocity to stop the motor. See TargetBrakingStrength for more information on stopping the motor. TargetVelocity is bounded by -1×MaxVelocity and MaxVelocity, where a sign change (±) is indicitave of a direction change.



139
140
141
# File 'ext/phidgets/phidgets_dc_motor.c', line 139

VALUE ph_dc_motor_get_min_velocity(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMinVelocity);
}

#getTargetBrakingStrengthObject Also known as: target_braking_strength

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. A low TargetBrakingStrength value corresponds to free wheeling, this will have the following effects: The motor will continue to rotate after the controller is no longer driving the motor (i.e. Velocity is 0), due to inertia. The motor shaft will provide little resistance to being turned when it is stopped. A higher TargetBrakingStrength value will resist being turned, this will have the following effects: 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. Braking mode is enabled by setting the Velocity to MinVelocity.



117
118
119
# File 'ext/phidgets/phidgets_dc_motor.c', line 117

VALUE ph_dc_motor_get_target_braking_strength(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getTargetBrakingStrength);
}

#getTargetVelocityObject Also known as: target_velocity

The average voltage across the motor is based on the TargetVelocity value. At a constant load, increasing the target velocity will increase the speed of the motor. TargetVelocity is bounded by -1×MaxVelocity and MaxVelocity, where a sign change (±) is indicitave of a direction change. Setting TargetVelocity to MinVelocity will stop the motor. See TargetBrakingStrength for more information on stopping the motor. The units of TargetVelocity and Acceleration 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.



126
127
128
# File 'ext/phidgets/phidgets_dc_motor.c', line 126

VALUE ph_dc_motor_get_target_velocity(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getTargetVelocity);
}

#getVelocityObject Also known as: velocity

The most recent velocity value that the controller has reported.



135
136
137
# File 'ext/phidgets/phidgets_dc_motor.c', line 135

VALUE ph_dc_motor_get_velocity(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getVelocity);
}

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

The rate at which the controller can change the motor’s Velocity. The acceleration is bounded by MinAccleration and MaxAcceleration.



19
20
21
22
# File 'ext/phidgets/phidgets_dc_motor.c', line 19

VALUE ph_dc_motor_set_acceleration(VALUE self, VALUE accel) {
  ph_raise(PhidgetDCMotor_setAcceleration((PhidgetDCMotorHandle)get_ph_handle(self), NUM2DBL(accel)));
  return Qnil;
}

#setBackEMFSensingState(sensing_state) ⇒ Object Also known as: back_emf_sensing_state=

When BackEMFSensingState is enabled, the controller will measure and report the BackEMF. The motor will coast (freewheel) 5% of the time while the back EMF is being measured (800μs every 16ms). Therefore, at a DutyCycle of 100%, the motor will only be driven for 95% of the time.



40
41
42
43
# File 'ext/phidgets/phidgets_dc_motor.c', line 40

VALUE ph_dc_motor_set_back_emf_sensing_state(VALUE self, VALUE sensing_state) {
  ph_raise(PhidgetDCMotor_setBackEMFSensingState((PhidgetDCMotorHandle)get_ph_handle(self), TYPE(sensing_state) == T_TRUE ? PTRUE : PFALSE));
  return Qnil;
}

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

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



61
62
63
64
# File 'ext/phidgets/phidgets_dc_motor.c', line 61

VALUE ph_dc_motor_set_current_limit(VALUE self, VALUE current_limit) {
  ph_raise(PhidgetDCMotor_setCurrentLimit((PhidgetDCMotorHandle)get_ph_handle(self), NUM2DBL(current_limit)));
  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. Each DC Motor we sell specifies a suitable current regulator gain.



78
79
80
81
# File 'ext/phidgets/phidgets_dc_motor.c', line 78

VALUE ph_dc_motor_set_current_regulator_gain(VALUE self, VALUE gain) {
  ph_raise(PhidgetDCMotor_setCurrentRegulatorGain((PhidgetDCMotorHandle)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 update event. The data interval is bounded by MinDataInterval and MaxDataInterval.



95
96
97
98
# File 'ext/phidgets/phidgets_dc_motor.c', line 95

VALUE ph_dc_motor_set_data_interval(VALUE self, VALUE interval) {
  ph_raise(PhidgetDCMotor_setDataInterval((PhidgetDCMotorHandle)get_ph_handle(self), NUM2UINT(interval)));
  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.



112
113
114
115
# File 'ext/phidgets/phidgets_dc_motor.c', line 112

VALUE ph_dc_motor_set_fan_mode(VALUE self, VALUE fan_mode) {
  ph_raise(PhidgetDCMotor_setFanMode((PhidgetDCMotorHandle)get_ph_handle(self), NUM2INT(fan_mode)));
  return Qnil;
}

#setOnBackEMFChangeHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_back_emf_change

call-seq:

setOnBackEMFChangeHandler(proc=nil, &block)

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



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

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

#setOnBrakingStrengthChangeHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_braking_strength_change

call-seq:

setOnBrakingStrengthChangeHandler(proc=nil, &block)

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



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

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

#setOnVelocityUpdateHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_velocity_update

call-seq:

setOnVelocityUpdateHandler(proc=nil, &block)

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



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

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

#setTargetBrakingStrength(braking_strength) ⇒ Object Also known as: target_braking_strength=

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. A low TargetBrakingStrength value corresponds to free wheeling, this will have the following effects: The motor will continue to rotate after the controller is no longer driving the motor (i.e. Velocity is 0), due to inertia. The motor shaft will provide little resistance to being turned when it is stopped. A higher TargetBrakingStrength value will resist being turned, this will have the following effects: 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. Braking mode is enabled by setting the Velocity to MinVelocity.



121
122
123
124
# File 'ext/phidgets/phidgets_dc_motor.c', line 121

VALUE ph_dc_motor_set_target_braking_strength(VALUE self, VALUE target_braking_strength) {
  ph_raise(PhidgetDCMotor_setTargetBrakingStrength((PhidgetDCMotorHandle)get_ph_handle(self), NUM2DBL(target_braking_strength)));
  return Qnil;
}

#setTargetVelocity(velocity) ⇒ Object Also known as: target_velocity=

The average voltage across the motor is based on the TargetVelocity value. At a constant load, increasing the target velocity will increase the speed of the motor. TargetVelocity is bounded by -1×MaxVelocity and MaxVelocity, where a sign change (±) is indicitave of a direction change. Setting TargetVelocity to MinVelocity will stop the motor. See TargetBrakingStrength for more information on stopping the motor. The units of TargetVelocity and Acceleration 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.



130
131
132
133
# File 'ext/phidgets/phidgets_dc_motor.c', line 130

VALUE ph_dc_motor_set_target_velocity(VALUE self, VALUE target_velocity) {
  ph_raise(PhidgetDCMotor_setTargetVelocity((PhidgetDCMotorHandle)get_ph_handle(self), NUM2DBL(target_velocity)));
  return Qnil;
}