Repository navigation
Fs90r servo #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
taartspi
wants to merge
7
commits into
main
Choose a base branch
from
fs90r_servo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fs90r servo #166
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
032d05d
fs90r servo 360 degree continual rotation
taartspi f5ad100
update README.md included fs90r and sg90
taartspi 83d00ab
pom uipdate tomew pi4j and driver
taartspi 21a835e
Finished unit test fs90R
taartspi 73d7c5c
Review cleanup,, rename the example.
taartspi 549e721
Fix console title in Fs90rApp
taartspi a8c2010
Revise command-line options in README.md
taartspi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
|
|
||
|
|
||
| java -classpath ./*:../classes com.pi4j.devices.fs90r.Fs90rApp $@ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| /* | ||
| * /* | ||
| * * | ||
| * | ||
| */ | ||
|
|
||
| package com.pi4j.devices.fs90r; | ||
|
|
||
|
|
||
| import com.pi4j.drivers.motor.fs90r.Fs90RDriver; | ||
| import com.pi4j.io.pwm.Pwm; | ||
| import com.pi4j.io.pwm.PwmConfigBuilder; | ||
| import com.pi4j.boardinfo.util.PwmChipUtil; | ||
| import com.pi4j.Pi4J; | ||
| import com.pi4j.context.Context; | ||
| import com.pi4j.io.pwm.PwmConfig; | ||
| import com.pi4j.io.pwm.PwmType; | ||
| import com.pi4j.util.Console; | ||
| import com.pi4j.util.Delay; | ||
|
|
||
| /** | ||
| * Example implementation for a FS90R servo motor. | ||
| * The Fs90R defines a specific PWM interface and exactly how the PWN signal | ||
| * controls the servo | ||
| * | ||
| * https://www.pololu.com/product/2820 | ||
| * | ||
| * See the README.md file for example usage and explanation. | ||
| * | ||
| * FS90R servo motor control. The driver will use the PWM device created by | ||
| * this app. It is assumed the device is a HardWare PWM. Hardware PWM creates | ||
| * a more consistent PWM signal. | ||
| */ | ||
| public class Fs90rApp { | ||
|
|
||
| private static final int DEFAULT_PWM_FREQUENCY = 50; | ||
| private static final int DEFAULT_CHANNEL_NUMBER = 2; | ||
| private static final int SERVO_NUMBER = 1; | ||
|
|
||
|
|
||
| private static double degree = 90.0; | ||
| private static Integer channel = DEFAULT_CHANNEL_NUMBER ; | ||
| private static Console console ; | ||
| private static Fs90RDriver fs90R ; | ||
| private static final Delay delay = new Delay(); | ||
| private static java .util.Scanner scanner; | ||
| private static double lowPulse = 1000.0; | ||
| private static double highPulse = 2000.0; | ||
|
|
||
|
|
||
| public Fs90rApp() { | ||
| super(); | ||
|
|
||
| } | ||
|
|
||
|
|
||
| /** | ||
| * <p>main.</p> | ||
| * See the README.md file for example usage. | ||
| * @param args an array of {@link java.lang.String} objects. | ||
| * @throws java.lang.Exception if any. | ||
| */ | ||
| static void main(String[] args) throws Exception { | ||
| System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "INFO"); | ||
|
|
||
| int onlyOne = 0; // numerous parms a mutually exclusive | ||
|
|
||
| scanner = new java.util.Scanner(System.in); | ||
|
|
||
| console = new Console(); | ||
| Context pi4j = Pi4J.newAutoContext(); | ||
| console.title("<-- The Pi4J V5 Project Extension -->", "Fs90rApp"); | ||
| String helpString = " Parms: -c channel -cw (clockwise) S M F -ccw (counter-clockwise) S M F -h HELP \n" + | ||
| " -low microseconds -high microseconds -cw -ccw mutually exclusive -d degree \n" + | ||
| " degree must be in the range 0..180. 90 stop, 0..89 CW, 91..180 CCW "; | ||
|
|
||
|
|
||
| for (int i = 0; i < args.length; i++) { | ||
| String o = args[i]; | ||
| if (o.contentEquals("-low")) { | ||
| String a = args[i + 1]; | ||
| lowPulse = Double.parseDouble(a.substring(0)); | ||
| i++; | ||
| } else if (o.contentEquals("-high")) { | ||
| String a = args[i + 1]; | ||
| highPulse = Double.parseDouble(a.substring(0)); | ||
| i++; | ||
| } else if (o.contentEquals("-d")) { | ||
| String a = args[i + 1]; | ||
| degree = Double.parseDouble(a.substring(0)); | ||
| if((!Double.isFinite(degree) || degree < 0) || (degree > 180)){ | ||
|
taartspi marked this conversation as resolved.
|
||
| console.println("-d degree must be in range 0..180"); | ||
| System.exit(40); | ||
| } | ||
| onlyOne++; | ||
| i++; | ||
| } else if (o.contentEquals("-c")) { | ||
| String a = args[i + 1]; | ||
| channel = Integer.parseInt(a.substring(0)); | ||
| i++; | ||
| } else if (o.contentEquals("-cw")) { /* 0-89 */ | ||
| String a = args[i + 1]; | ||
| onlyOne++; | ||
| i++; | ||
| if (a.equalsIgnoreCase("S")) { | ||
| degree = 75.0; | ||
| } else if (a.equalsIgnoreCase("M")) { | ||
| degree = 40.0; | ||
| } else if (a.equalsIgnoreCase("F")) { | ||
| degree = 0.0; | ||
| } else { | ||
| console.println(" -cw invalid "); | ||
| System.exit(41); | ||
| } | ||
| } else if (o.contentEquals("-ccw")) { /* 191-180 */ | ||
| String a = args[i + 1]; | ||
| i++; | ||
| onlyOne++; | ||
| if (a.equalsIgnoreCase("S")) { | ||
| degree = 105.0; | ||
| } else if (a.equalsIgnoreCase("M")) { | ||
| degree = 140.0; | ||
| } else if (a.equalsIgnoreCase("F")) { | ||
| degree = 180.0; | ||
| } else { | ||
| console.println(" -ccw invalid "); | ||
| System.exit(42); | ||
| } | ||
| } else if (o.contentEquals("-q")) { | ||
| console.println("Exit"); | ||
| System.exit(0); | ||
| } else if (o.contentEquals("-h")) { | ||
| console.println(helpString); | ||
| System.exit(0); | ||
| }else { | ||
| console.println(" !!! Invalid Parm " + o); | ||
| console.println(helpString); | ||
| System.exit(43); | ||
| } | ||
| } | ||
|
|
||
| if (onlyOne > 1 ) { | ||
| console.println(" mutually exclusive parms used."); | ||
| console.println(helpString); | ||
| System.exit(44); | ||
| } | ||
| Pwm pwm = createPwm(SERVO_NUMBER, channel, pi4j); | ||
|
|
||
| fs90R = new Fs90RDriver(pwm, lowPulse, highPulse); | ||
|
|
||
| // if user did not provide a -cw -ccw or -d default sets stop | ||
| fs90R.setServoRotation(degree); | ||
|
|
||
| waitChange( 10l); | ||
|
|
||
| pi4j.shutdown(pwm); | ||
|
|
||
| } | ||
|
|
||
|
|
||
| static Pwm createPwm(int servoNumber, Integer channel, Context pi4j) { | ||
|
|
||
| final PwmConfig config = PwmConfigBuilder.newInstance (pi4j) | ||
| .id ("fs90RNumber" + servoNumber) | ||
| .name ("fs90R number " + servoNumber) | ||
| .pwmType(PwmType.HARDWARE) | ||
| .channel(channel) | ||
| .chip(PwmChipUtil.getPWMChip()) | ||
| .frequency(DEFAULT_PWM_FREQUENCY) | ||
| .build (); | ||
|
|
||
| return pi4j.create (config); | ||
| } | ||
|
|
||
| static void waitChange(long c){ | ||
| while(true){ | ||
| delay.setMillis(c).materialize(); | ||
| console.println("Enter q - quit, or degree value "); | ||
| if (scanner.hasNextInt() ) { | ||
| double nextDegree = scanner.nextDouble(); | ||
| if((!Double.isFinite(nextDegree) || nextDegree < 0) || (nextDegree > 180)){ | ||
| console.println(" degree must be in the range 0..180. 90 stop, 0..89 CW, 91..180 CCW"); | ||
| }else { | ||
| fs90R.setServoRotation(nextDegree); | ||
| } | ||
| } else{ | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
|
|
||
|
|
||
| ##Device application to operate a Fs90r stepping servo. This servo can rotate 360 degree continuously. | ||
| The PWM signal sent to the servo device set the direction and RPM of rotation. | ||
|
|
||
|
|
||
|
|
||
| Driver for a Fs90r servo motor. | ||
| The Fs90r defines a specific PWM interface and exactly how the PWN signal | ||
| controls the servo | ||
|
|
||
| https://www.pololu.com/product/2820 | ||
|
|
||
|
|
||
| These devices do not have a customary DataSheet. Most servo devices provide limited specifications | ||
| for required pulse width, they just say 1 - 2 millisecond. | ||
|
|
||
| The FS90 R 360 defines a specific PWM interface and exactly how the PWN signal | ||
| controls the servo. There are many different manufacturers of the FS90 servo. | ||
| The pulse width required for setting the servo at 0 degrees MAX Clockwise (CW) or 180 degrees | ||
| MAX CounterClockWise (CCW) varies by manufacturer. The driver by default uses the pulse width timing as | ||
| (low)1000 - (high)2000 microseconds. The user of this example application can change these defaults | ||
| when first invoking the program. | ||
|
|
||
| If the servo does not rotate to the expected RPM,Example to rotate faster CW reduce the -low | ||
| argument, to rotate CCW faster increase the -high argument. The -low -high change should be balanced or 90 degree will not properly align. | ||
| Meaning if you reduce the -low by 200, you should increase the -high by 200, or visa-versa. | ||
|
|
||
|
|
||
|
|
||
|
|
||
| https://www.pololu.com/product/2820 | ||
|
|
||
|
|
||
|
|
||
| Fs90r Pi | ||
| Grey/Brown Ground | ||
| Red 5V | ||
| Yellow GPIO18 config.sys contains dtoverlay=pwm-2chan | ||
|
|
||
|
|
||
|
|
||
| 1. ./mvnw clean package | ||
| 2. cd target/distribution | ||
| 3. ./runFs90r.sh args | ||
|
|
||
| -h help | ||
| -c channel (default 2) set the channel, depending on config.txt 1 2 3 4 | ||
| -cw clockwise S M F | ||
| -ccw counter-clockwise S M F | ||
| -low double pulse width for 0 degree microseconds | ||
| -high double pulse width for 180 degree microseconds | ||
| -q quit servo will stop | ||
|
|
||
|
|
||
| Application running, awaiting input of 0-180 degree | ||
| ./runFs90r.sh | ||
|
|
||
| Application running CCW, then awaiting input of 0-180 degree | ||
| ./runFs90r.sh 160 | ||
|
|
||
|
|
||
|
|
||
| Set output shaft Fast ClockWise, then enter 90 for stop | ||
| ./runFs90r.sh -cw F | ||
| 90 | ||
|
|
||
|
|
||
| Set output shaft Slow CounterClockWise, then enter 0 for MAX soeed | ||
| ./runFs90r.sh -ccw S | ||
| 0 | ||
|
|
||
| My Fs90r appears faster rotation wih these values for the -low and -high limmits | ||
| ./runFs90r.sh -low 550 -high 2450 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.