Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sgeigers committed Dec 19, 2021
1 parent 2c56bcd commit a5775c8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 29 deletions.
27 changes: 15 additions & 12 deletions examples/Basic/Stepper_Motor_Basic/Stepper_Motor_Basic.pde
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,47 @@ void draw() {
}

/*
A stepper motor can be controlled in 2 modes: either setting its position ("STEP" mode - default) or setting its speed ("RUN" mode).
All functions for stepper channel:
setTargetPosition(float) - most basic way to use the channel. Rotates the motor the selected position in 1/16 of steps.
setTargetPosition(float) - most basic way to use the channel in "STEP" mode. Rotates the motor the selected position in 1/16 of steps.
getTargetPosition() - get target position as set in setTargetPosition().
getMinPosition() - the minimum value that TargetPosition can be set to.
getMaxPosition() - the maximum value that TargetPosition can be set to.
getPosition() - the most recent position value that the controller has reported.
addPositionOffset(int) - adds an offset (positive or negative) to the current position and target position. This is especially useful for zeroing position.
setVelocityLimit(float) - when moving, the stepper motor velocity will be limited by this value (units per second)
setVelocityLimit(float) - when moving, the stepper motor velocity will be limited by this value. In "RUN" mode, this value sets motor's velocity and direction,
and may be set to either positive or negative number (units per second)
getMinVelocityLimit() - minimum value for VelosityLimit.
getMaxVelocityLimit() - maximum value for VelosityLimit.
getVelocity() - get the most recent velocity value that the controller has reported.
getVelocityLimit() - as set in setVelocityLimit().
getAcceleration() - get the rate at which the controller can change the motor's velocity
setControlMode(String) - "STEP" = controlling the motor with target position. "RUN" = controlling with speed (continueous run)
getControlMode() - returns current control mode (String)
setAcceleration(float) - set the rate at which the controller can change the motor's velocity
getAcceleration() - get the rate at which the controller can change the motor's velocity
getMinAcceleration() - get the minimum value that acceleration can be set to.
getMaxAcceleration() - get the maximum value that Acceleration can be set to.
getIsMoving() - true if the controller is sending steps to the motor (it can't indicate a stalled motor)
getControlMode() - "STEP" = controlling the motor with target position. "RUN" = controlling with speed (continueous run)
setControlMode(String) - set to "STEP" or "RUN"
getCurrentLimit() - current limit to the motor (in Amperes)
setCurrentLimit(float) - the current through the motor will be limited by the set value
getCurrentLimit() - current limit to the motor (in Amperes)
getMinCurrentLimit() - get minimum current imit to the motor
getMaxCurrentLimit() - get maximum current limit to the motor
getEngaged() - when this property is true, the controller will supply power to the motor coils.
setEngaged(boolean) - this is automatically set to true when calling setTargetPosition
getEngaged() - when this property is true, the controller will supply power to the motor coils.
getRescaleFactor() - get rescaler factor (see bellow)
setRescaleFactor(float) - applies a factor to the units used by all movement parameters to make the units in your sketch more intuitive.
For example: if your motor is 400 steps per revolution, after applying a factor of 1/(16*400) - because the basic unit is 1/16th step - setting target
position to 1.0 will result in exactly one revolution of the motor.
getRescaleFactor() - get rescaler factor (float)
Event functions:
Expand All @@ -70,8 +73,8 @@ void draw() {
for newer stepper boards (VINT stepper controllers), these functions are also available:
getHoldingCurrentLimit() - this value will activate when the TargetPosition has been reached. It will limit current through the motor.
setHoldingCurrentLimit(float) - sets the holding current limit to the motor.
setHoldingCurrentLimit(float) - this value will activate when the TargetPosition has been reached. It will limit current through the motor to given value in Amperes.
getHoldingCurrentLimit() - returns the holding current limit to the motor (float, Amperes).
enableFailsafe(int) - enable the fail-safe mode with the given fail-safe time.
getMinFailsafeTime() - returns min fale-safe time
Expand Down
6 changes: 3 additions & 3 deletions resources/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ source.repository=https://github.com/sgeigers/SimplePhidgets.git
# This is used to compare different versions of the same Library, and check if
# an update is available.

library.version=12
library.version=13


# The version as the user will see it.

library.prettyVersion=1.0.11
library.prettyVersion=1.0.12


# The min and max revision of Processing compatible with your Library.
Expand Down Expand Up @@ -169,4 +169,4 @@ library.keywords=Phidgets, Phidget22

#javadoc.java.href=http://docs.oracle.com/javase/7/docs/api/
javadoc.java.href=http://docs.oracle.com/javase/8/docs/api/
javadoc.processing.href=http://processing.github.io/processing-javadocs/core/
javadoc.processing.href=http://processing.github.io/processing-javadocs/core/
50 changes: 39 additions & 11 deletions src/shenkar/SimplePhidgets/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import processing.core.*;

/* ToDos:
* - Left: IR, BLDCMotor, HumiditySensor, PHSensor, PowerGuard, PressureSensor, ResistenceInput, VoltageOutput
* - Check real-time event of encoder. seems like double and even triple calls to it when in changeTrigger = 0. (Maybe use millis() for checking calling periods)
* - Change order of functions in all examples to "setup" functions and "draw" functions
* - APIs left to implement: IR, BLDCMotor, HumiditySensor, PHSensor, PowerGuard, PressureSensor, ResistenceInput, VoltageOutput
* - Add PAppletParent.exit(); to most errors...
* - Add specific example for 1045
* - [PROBABLY OK] if dual usage of same event function name fails - for every event (which has dual usage) check type of channel before invoking
Expand Down Expand Up @@ -457,6 +459,19 @@ public Channel(PApplet theParent, String type, int hubPort, int chNum) {
this(theParent, type, -1, hubPort, chNum, "");
}

/**
* broaderish constructor
*
* @param theParent the parent PApplet
* @param type 4 numbers or 3 letters and 4 numbers describing type of device to associate to this channel
* @param serialNum serial number of hub or interfaceKit (to be used in case there are more than one hub/IK connected to the computer)
* @param hubPort the port number of hub or interfaceKit where the device is connected, or hub/IK serial number (if number used has more than 4 digits)
* @param chNum specify the channel used (see general constructor), or hub port if serial number was specified in previous parameter
*/
public Channel(PApplet theParent, String type, int serialNum, int hubPort, int chNum) {
this(theParent, type, serialNum, hubPort, chNum, "");
}

/**
* minimal constructor w/ secondary I/O
*
Expand Down Expand Up @@ -536,27 +551,27 @@ public Channel(PApplet theParent, String type, String secondaryIO, int hubPort,
*
* @param theParent the parent PApplet
* @param type 4 numbers or 3 letters and 4 numbers describing type of device to associate to this channel
* @param serial serial number of hub or interfaceKit (to be used in case there are more than one hub/IK connected to the computer)
* @param serialNum serial number of hub or interfaceKit (to be used in case there are more than one hub/IK connected to the computer)
* @param hubPort the port number of hub or interfaceKit where the device is connected, or hub/IK serial number (if number used has more than 4 digits)
* @param secondaryIO either "digital_input" or "digital_output" to indicate digital channel (unless trivial by board type)
* @param chNum specify the channel used (see general constructor), or hub port if serial number was specified in previous parameter
*/
public Channel(PApplet theParent, String type, int serialNum, int hubPort, String secondaryIO, int chNum) {
this(theParent, type, -1, hubPort, chNum, secondaryIO);
this(theParent, type, serialNum, hubPort, chNum, secondaryIO);
}

/**
* the most general constructor w/ secondary I/O 2
*
* @param theParent the parent PApplet
* @param type 4 numbers or 3 letters and 4 numbers describing type of device to associate to this channel
* @param serial serial number of hub or interfaceKit (to be used in case there are more than one hub/IK connected to the computer)
* @param serialNum serial number of hub or interfaceKit (to be used in case there are more than one hub/IK connected to the computer)
* @param secondaryIO either "digital_input" or "digital_output" to indicate digital channel (unless trivial by board type)
* @param hubPort the port number of hub or interfaceKit where the device is connected, or hub/IK serial number (if number used has more than 4 digits)
* @param chNum specify the channel used (see general constructor), or hub port if serial number was specified in previous parameter
*/
public Channel(PApplet theParent, String type, int serialNum, String secondaryIO, int hubPort, int chNum) {
this(theParent, type, -1, hubPort, chNum, secondaryIO);
this(theParent, type, serialNum, hubPort, chNum, secondaryIO);
}

/**
Expand All @@ -565,12 +580,12 @@ public Channel(PApplet theParent, String type, int serialNum, String secondaryIO
* @param theParent the parent PApplet
* @param type 4 numbers or 3 letters and 4 numbers describing type of device to associate to this channel
* @param secondaryIO either "digital_input" or "digital_output" to indicate digital channel (unless trivial by board type)
* @param serial serial number of hub or interfaceKit (to be used in case there are more than one hub/IK connected to the computer)
* @param serialNum serial number of hub or interfaceKit (to be used in case there are more than one hub/IK connected to the computer)
* @param hubPort the port number of hub or interfaceKit where the device is connected, or hub/IK serial number (if number used has more than 4 digits)
* @param chNum specify the channel used (see general constructor), or hub port if serial number was specified in previous parameter
*/
public Channel(PApplet theParent, String type, String secondaryIO, int serialNum, int hubPort, int chNum) {
this(theParent, type, -1, hubPort, chNum, secondaryIO);
this(theParent, type, serialNum, hubPort, chNum, secondaryIO);
}


Expand All @@ -580,7 +595,7 @@ public Channel(PApplet theParent, String type, String secondaryIO, int serialNum
*
* @param theParent the parent PApplet
* @param type 4 numbers or 3 letters and 4 numbers describing type of device to associate to this channel
* @param serial serial number of hub or interfaceKit (to be used in case there are more than one hub/IK connected to the computer)
* @param serialNum serial number of hub or interfaceKit (to be used in case there are more than one hub/IK connected to the computer)
* @param hubPort the port number of hub or interfaceKit where the device is connected. Only needed if different than 0 or if a channel number is specified
* @param chNum if the device has more than one channel (e.g. wheatstone bridge) - specify the channel used
*/
Expand All @@ -590,12 +605,25 @@ public Channel(PApplet theParent, String type, int serialNum, int hubPort, int c
myParent.registerMethod("draw", this);
myParent.registerMethod("dispose", this);
if (hubPort > 9999) {
int h = serialNum;
serialNum = hubPort;
if (chNum>-1) hubPort = chNum;
else hubPort = 0;
chNum = -1;
hubPort = h;
if (hubPort == -1) {
hubPort = chNum;
chNum = h;
}
if (hubPort == -1) {
hubPort = 0;
}
}
else if (chNum > 9999) {
int c = serialNum;
serialNum = chNum;
chNum = hubPort;
hubPort = c;
}

System.out.println("Type: "+type + " \tSerial: "+serialNum +"\thubPort: "+hubPort+ "\tchannel: "+chNum+ "\tsecIO: "+secondaryIO);
deviceType = type;
int p = deviceType.indexOf("_");
if (p > 0) deviceType = deviceType.substring(0, p);
Expand Down
8 changes: 5 additions & 3 deletions src/shenkar/SimplePhidgets/P_Stepper.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,6 @@ public void close() {
@Override
public void setTargetPosition(float pos) {
try {
if (((Stepper)device).getControlMode() != StepperControlMode.STEP) {
((Stepper)device).setControlMode(StepperControlMode.STEP);
}
if (((Stepper)device).getEngaged() == false) {
((Stepper)device).setEngaged(true);
}
Expand Down Expand Up @@ -948,6 +945,11 @@ public float getVelocityLimit() {
@Override
public void setVelocityLimit(float vel) {
try {
if (((Stepper)device).getControlMode() == StepperControlMode.RUN) {
if (((Stepper)device).getEngaged() == false) {
((Stepper)device).setEngaged(true);
}
}
((Stepper)device).setVelocityLimit((double)vel);
}
catch (PhidgetException ex) {
Expand Down

0 comments on commit a5775c8

Please sign in to comment.