Class: Phidgets::BLDCMotor

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



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

VALUE ph_bldc_motor_init(VALUE self) {
  ph_data_t *ph = get_ph_data(self);
  ph_raise(PhidgetBLDCMotor_create((PhidgetBLDCMotorHandle *)(&(ph->handle))));
  return self;
}

Instance Method Details

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

Adds an offset (positive or negative) to the current position. This can be especially useful for zeroing position.



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

VALUE ph_bldc_motor_add_position_offset(VALUE self, VALUE offset) {
  ph_raise(PhidgetBLDCMotor_addPositionOffset((PhidgetBLDCMotorHandle)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. The acceleration is bounded by MinAccleration and MaxAcceleration.



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

VALUE ph_bldc_motor_get_acceleration(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getAcceleration);
}

#getBrakingStrengthObject Also known as: braking_strength

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



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

VALUE ph_bldc_motor_get_braking_strength(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getBrakingStrength);
}

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



44
45
46
# File 'ext/phidgets/phidgets_bldc_motor.c', line 44

VALUE ph_bldc_motor_get_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetBLDCMotor_getDataInterval);
}

#getMaxAccelerationObject Also known as: max_acceleration

The maximum value that Acceleration can be set to.



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

VALUE ph_bldc_motor_get_max_acceleration(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMaxAcceleration);
}

#getMaxBrakingStrengthObject Also known as: max_braking_strength

The maximum value that TargetBrakingStrength can be set to.



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

VALUE ph_bldc_motor_get_max_braking_strength(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMaxBrakingStrength);
}

#getMaxDataIntervalObject Also known as: max_data_interval

The maximum value that DataInterval can be set to.



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

VALUE ph_bldc_motor_get_max_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetBLDCMotor_getMaxDataInterval);
}

#getMaxPositionObject Also known as: max_position

The upper bound of Position.



69
70
71
# File 'ext/phidgets/phidgets_bldc_motor.c', line 69

VALUE ph_bldc_motor_get_max_position(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMaxPosition);
}

#getMaxStallVelocityObject Also known as: max_stall_velocity

The upper bound of StallVelocity.



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

VALUE ph_bldc_motor_get_max_stall_velocity(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMaxStallVelocity);
}

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



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

VALUE ph_bldc_motor_get_max_velocity(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMaxVelocity);
}

#getMinAccelerationObject Also known as: min_acceleration

The minimum value that Acceleration can be set to.



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

VALUE ph_bldc_motor_get_min_acceleration(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMinAcceleration);
}

#getMinBrakingStrengthObject Also known as: min_braking_strength

The minimum value that TargetBrakingStrength can be set to.



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

VALUE ph_bldc_motor_get_min_braking_strength(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMinBrakingStrength);
}

#getMinDataIntervalObject Also known as: min_data_interval

The minimum value that DataInterval can be set to.



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

VALUE ph_bldc_motor_get_min_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetBLDCMotor_getMinDataInterval);
}

#getMinPositionObject Also known as: min_position

The lower bound of Position.



65
66
67
# File 'ext/phidgets/phidgets_bldc_motor.c', line 65

VALUE ph_bldc_motor_get_min_position(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMinPosition);
}

#getMinStallVelocityObject Also known as: min_stall_velocity

The lower bound of StallVelocity.



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

VALUE ph_bldc_motor_get_min_stall_velocity(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMinStallVelocity);
}

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



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

VALUE ph_bldc_motor_get_min_velocity(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getMinVelocity);
}

#getPositionObject Also known as: position

The most recent position value that the controller has reported. Position values are calculated using Hall Effect sensors mounted on the motor, therefore, the resolution of position depends on the motor you are using. 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. For more information on how to apply the RescaleFactor to your application, see your controller’s User Guide.



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

VALUE ph_bldc_motor_get_position(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getPosition);
}

#getRescaleFactorObject Also known as: rescale_factor

Change the units of your parameters so that your application is more intuitive. 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. For more information on how to apply the RescaleFactor to your application, see your controller’s User Guide.



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

VALUE ph_bldc_motor_get_rescale_factor(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_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 reduce the Velocity (i.e. average voltage) to 0 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.



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

VALUE ph_bldc_motor_get_stall_velocity(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getStallVelocity);
}

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



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

VALUE ph_bldc_motor_get_target_braking_strength(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_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.



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

VALUE ph_bldc_motor_get_target_velocity(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_getTargetVelocity);
}

#getVelocityObject Also known as: velocity

The most recent velocity value that the controller has reported.



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

VALUE ph_bldc_motor_get_velocity(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetBLDCMotor_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_bldc_motor.c', line 19

VALUE ph_bldc_motor_set_acceleration(VALUE self, VALUE accel) {
  ph_raise(PhidgetBLDCMotor_setAcceleration((PhidgetBLDCMotorHandle)get_ph_handle(self), NUM2DBL(accel)));
  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.



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

VALUE ph_bldc_motor_set_data_interval(VALUE self, VALUE interval) {
  ph_raise(PhidgetBLDCMotor_setDataInterval((PhidgetBLDCMotorHandle)get_ph_handle(self), NUM2UINT(interval)));
  return Qnil;
}

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



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

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

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

#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/bldc_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

#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 can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees. For more information on how to apply the RescaleFactor to your application, see your controller’s User Guide.



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

VALUE ph_bldc_motor_set_rescale_factor(VALUE self, VALUE rescale_factor) {
  ph_raise(PhidgetBLDCMotor_setRescaleFactor((PhidgetBLDCMotorHandle)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 reduce the Velocity (i.e. average voltage) to 0 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.



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

VALUE ph_bldc_motor_set_stall_velocity(VALUE self, VALUE stall_velocity) {
  ph_raise(PhidgetBLDCMotor_setStallVelocity((PhidgetBLDCMotorHandle)get_ph_handle(self), NUM2DBL(stall_velocity)));
  return Qnil;
}

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



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

VALUE ph_bldc_motor_set_target_braking_strength(VALUE self, VALUE target_braking_strength) {
  ph_raise(PhidgetBLDCMotor_setTargetBrakingStrength((PhidgetBLDCMotorHandle)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.



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

VALUE ph_bldc_motor_set_target_velocity(VALUE self, VALUE target_velocity) {
  ph_raise(PhidgetBLDCMotor_setTargetVelocity((PhidgetBLDCMotorHandle)get_ph_handle(self), NUM2DBL(target_velocity)));
  return Qnil;
}