Class: Phidgets::Stepper

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

Constant Summary collapse

CONTROL_MODE_STEP =
INT2NUM(CONTROL_MODE_STEP)
CONTROL_MODE_RUN =
INT2NUM(CONTROL_MODE_RUN)

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 Stepper object.



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

VALUE ph_stepper_init(VALUE self) {
  ph_data_t *ph = get_ph_data(self);
  ph_raise(PhidgetStepper_create((PhidgetStepperHandle *)(&(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 and target position. This is especially useful for zeroing position.



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

VALUE ph_stepper_add_position_offset(VALUE self, VALUE offset) {
  ph_raise(PhidgetStepper_addPositionOffset((PhidgetStepperHandle)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, Velocity, and Acceleration 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_stepper.c', line 16

VALUE ph_stepper_get_acceleration(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getAcceleration);
}

#getControlModeObject Also known as: control_mode

Use step mode when you want to set a TargetPosition for the Stepper motor. Use run mode when you simply want the Stepper motor to rotate continuously in a specific direction.



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

VALUE ph_stepper_get_control_mode(VALUE self) {
  return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetStepper_getControlMode);
}

#getCurrentLimitObject Also known as: current_limit

The current through the motor will be limited by the CurrentLimit. See your Stepper motor’s data sheet for more information about what value the CurrentLimit should be.



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

VALUE ph_stepper_get_current_limit(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getCurrentLimit);
}

#getDataIntervalObject Also known as: data_interval

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



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

VALUE ph_stepper_get_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetStepper_getDataInterval);
}

#getEngagedBoolean Also known as: engaged?

When this property is true, the controller will supply power to the motor coils. The controller must be Engaged in order to move the Stepper motor, or have it hold position.

Returns:

  • (Boolean)


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

VALUE ph_stepper_get_engaged(VALUE self) {
  return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetStepper_getEngaged);
}

#getHoldingCurrentLimitObject Also known as: holding_current_limit

The HoldingCurrentLimit will activate when the TargetPosition has been reached. It will limit current through the motor. When the motor is not stopped, the current through the motor is limited by the CurrentLimit. If no HoldingCurrentLimit is specified, the CurrentLimit value will persist when the motor is stopped. Reference your controller’s User Guide for more information about how the HoldingCurrentLimit and CurrentLimit can be used in your application.



85
86
87
# File 'ext/phidgets/phidgets_stepper.c', line 85

VALUE ph_stepper_get_holding_current_limit(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getHoldingCurrentLimit);
}

#getIsMovingBoolean Also known as: is_moving?

IsMoving returns true while the controller is sending commands to the motor. Note: there is no feedback to the controller, so it does not know whether the motor shaft is actually moving or not.

Returns:

  • (Boolean)


94
95
96
# File 'ext/phidgets/phidgets_stepper.c', line 94

VALUE ph_stepper_get_is_moving(VALUE self) {
  return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetStepper_getIsMoving);
}

#getMaxAccelerationObject Also known as: max_acceleration

The maximum value that Acceleration can be set to.



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

VALUE ph_stepper_get_max_acceleration(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getMaxAcceleration);
}

#getMaxCurrentLimitObject Also known as: max_current_limit

The maximum value that CurrentLimit and HoldingCurrentLimit can be set to. Reference your controller’s User Guide for more information about how the HoldingCurrentLimit and CurrentLimit can be used in your application.



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

VALUE ph_stepper_get_max_current_limit(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getMaxCurrentLimit);
}

#getMaxDataIntervalObject Also known as: max_data_interval

The maximum value that DataInterval can be set to.



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

VALUE ph_stepper_get_max_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetStepper_getMaxDataInterval);
}

#getMaxPositionObject Also known as: max_position

The maximum value that TargetPosition can be set to.



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

VALUE ph_stepper_get_max_position(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getMaxPosition);
}

#getMaxVelocityLimitObject Also known as: max_velocity_limit

The maximum value that VelocityLimit can be set to.



150
151
152
# File 'ext/phidgets/phidgets_stepper.c', line 150

VALUE ph_stepper_get_max_velocity_limit(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getMaxVelocityLimit);
}

#getMinAccelerationObject Also known as: min_acceleration

The minimum value that Acceleration can be set to.



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

VALUE ph_stepper_get_min_acceleration(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getMinAcceleration);
}

#getMinCurrentLimitObject Also known as: min_current_limit

The minimum value that CurrentLimit and HoldingCurrentLimit can be set to. Reference your controller’s User Guide for more information about how the HoldingCurrentLimit and CurrentLimit can be used in your application.



51
52
53
# File 'ext/phidgets/phidgets_stepper.c', line 51

VALUE ph_stepper_get_min_current_limit(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getMinCurrentLimit);
}

#getMinDataIntervalObject Also known as: min_data_interval

The minimum value that DataInterval can be set to.



68
69
70
# File 'ext/phidgets/phidgets_stepper.c', line 68

VALUE ph_stepper_get_min_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetStepper_getMinDataInterval);
}

#getMinPositionObject Also known as: min_position

The minimum value that TargetPosition can be set to.



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

VALUE ph_stepper_get_min_position(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getMinPosition);
}

#getMinVelocityLimitObject Also known as: min_velocity_limit

The minimum value that VelocityLimit can be set to.



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

VALUE ph_stepper_get_min_velocity_limit(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_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, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



98
99
100
# File 'ext/phidgets/phidgets_stepper.c', line 98

VALUE ph_stepper_get_position(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getPosition);
}

#getRescaleFactorObject Also known as: rescale_factor

Applies a factor to the [user units] per step to all movement parameters to make the units in your application is more intuitive. For example, starting from position 0 and setting a new position with a rescale factor, the stepper will move Position / RescaleFactor steps. In this way, units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



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

VALUE ph_stepper_get_rescale_factor(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getRescaleFactor);
}

#getTargetPositionObject Also known as: target_position

If the controller is configured and the TargetPosition is set, the Stepper motor will move towards the TargetPosition at the specified Acceleration and Velocity. TargetPosition is only used when the ControlMode is set to step mode. Units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



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

VALUE ph_stepper_get_target_position(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getTargetPosition);
}

#getVelocityObject Also known as: velocity

The most recent velocity value that the controller has reported. This value is bounded by MinVelocityLimit and MaxVelocityLimit. Units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



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

VALUE ph_stepper_get_velocity(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getVelocity);
}

#getVelocityLimitObject Also known as: velocity_limit

When moving, the Stepper motor velocity will be limited by this value. The VelocityLimit is bounded by MinVelocityLimit and MaxVelocityLimit. When in step mode, the MinVelocityLimit has a value of 0. This is because the sign (±) of the TargetPosition will indicate the direction. When in run mode, the MinVelocityLimit has a value of -MaxVelocityLimit. This is because there is no target position, so the direction is defined by the sign (±) of the VelocityLimit. Units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



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

VALUE ph_stepper_get_velocity_limit(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getVelocityLimit);
}

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

The rate at which the controller can change the motor’s Velocity. Units for Position, Velocity, and Acceleration 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_stepper.c', line 20

VALUE ph_stepper_set_acceleration(VALUE self, VALUE accel) {
  ph_raise(PhidgetStepper_setAcceleration((PhidgetStepperHandle)get_ph_handle(self), NUM2DBL(accel)));
  return Qnil;
}

#setControlMode(control_mode) ⇒ Object Also known as: control_mode=

Use step mode when you want to set a TargetPosition for the Stepper motor. Use run mode when you simply want the Stepper motor to rotate continuously in a specific direction.



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

VALUE ph_stepper_set_control_mode(VALUE self, VALUE mode) {
  ph_raise(PhidgetStepper_setControlMode((PhidgetStepperHandle)get_ph_handle(self), NUM2INT(mode)));
  return Qnil;
}

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

The current through the motor will be limited by the CurrentLimit. See your Stepper motor’s data sheet for more information about what value the CurrentLimit should be.



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

VALUE ph_stepper_set_current_limit(VALUE self, VALUE limit) {
  ph_raise(PhidgetStepper_setCurrentLimit((PhidgetStepperHandle)get_ph_handle(self), NUM2DBL(limit)));
  return Qnil;
}

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

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



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

VALUE ph_stepper_set_data_interval(VALUE self, VALUE interval) {
  ph_raise(PhidgetStepper_setDataInterval((PhidgetStepperHandle)get_ph_handle(self), NUM2UINT(interval)));
  return Qnil;
}

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

When this property is true, the controller will supply power to the motor coils. The controller must be Engaged in order to move the Stepper motor, or have it hold position.



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

VALUE ph_stepper_set_engaged(VALUE self, VALUE state) {
  ph_raise(PhidgetStepper_setEngaged((PhidgetStepperHandle)get_ph_handle(self), TYPE(state) == T_TRUE ? PTRUE : PFALSE));
  return Qnil;
}

#setHoldingCurrentLimit(holding_current_limit) ⇒ Object Also known as: holding_current_limit=

The HoldingCurrentLimit will activate when the TargetPosition has been reached. It will limit current through the motor. When the motor is not stopped, the current through the motor is limited by the CurrentLimit. If no HoldingCurrentLimit is specified, the CurrentLimit value will persist when the motor is stopped. Reference your controller’s User Guide for more information about how the HoldingCurrentLimit and CurrentLimit can be used in your application.



89
90
91
92
# File 'ext/phidgets/phidgets_stepper.c', line 89

VALUE ph_stepper_set_holding_current_limit(VALUE self, VALUE limit) {
  ph_raise(PhidgetStepper_setHoldingCurrentLimit((PhidgetStepperHandle)get_ph_handle(self), NUM2DBL(limit)));
  return Qnil;
}

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



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

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

#setOnStoppedHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_stopped

call-seq:

setOnStoppedHandler(proc=nil, &block)

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



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

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

#setOnVelocityChangeHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_velocity_change

call-seq:

setOnVelocityChangeHandler(proc=nil, &block)

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



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

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

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

Applies a factor to the [user units] per step to all movement parameters to make the units in your application is more intuitive. For example, starting from position 0 and setting a new position with a rescale factor, the stepper will move Position / RescaleFactor steps. In this way, units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



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

VALUE ph_stepper_set_rescale_factor(VALUE self, VALUE rescale_factor) {
  ph_raise(PhidgetStepper_setRescaleFactor((PhidgetStepperHandle)get_ph_handle(self), NUM2DBL(rescale_factor)));
  return Qnil;
}

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

If the controller is configured and the TargetPosition is set, the Stepper motor will move towards the TargetPosition at the specified Acceleration and Velocity. TargetPosition is only used when the ControlMode is set to step mode. Units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



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

VALUE ph_stepper_set_target_position(VALUE self, VALUE position) {
  ph_raise(PhidgetStepper_setTargetPosition((PhidgetStepperHandle)get_ph_handle(self), NUM2DBL(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 Stepper motor will move towards the TargetPosition at the specified Acceleration and Velocity. TargetPosition is only used when the ControlMode is set to step mode. Units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



46
47
48
49
50
# File 'lib/phidgets/stepper.rb', line 46

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 Stepper motor velocity will be limited by this value. The VelocityLimit is bounded by MinVelocityLimit and MaxVelocityLimit. When in step mode, the MinVelocityLimit has a value of 0. This is because the sign (±) of the TargetPosition will indicate the direction. When in run mode, the MinVelocityLimit has a value of -MaxVelocityLimit. This is because there is no target position, so the direction is defined by the sign (±) of the VelocityLimit. Units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.



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

VALUE ph_stepper_set_velocity_limit(VALUE self, VALUE limit) {
  ph_raise(PhidgetStepper_setVelocityLimit((PhidgetStepperHandle)get_ph_handle(self), NUM2DBL(limit)));
  return Qnil;
}