From 64d95b15b6dde0378b823978da722c6ac09ceef9 Mon Sep 17 00:00:00 2001 From: anivanchen Date: Tue, 5 Apr 2022 23:00:51 -0400 Subject: [PATCH 01/18] Update READMEs --- src/com/stuypulse/stuylib/math/readme.md | 18 +++---- src/com/stuypulse/stuylib/network/readme.md | 48 ++++++++++++++++++- .../stuylib/streams/filters/readme.md | 34 ++++++------- src/com/stuypulse/stuylib/streams/readme.md | 36 +++++++------- src/com/stuypulse/stuylib/util/readme.md | 10 +++- 5 files changed, 102 insertions(+), 44 deletions(-) diff --git a/src/com/stuypulse/stuylib/math/readme.md b/src/com/stuypulse/stuylib/math/readme.md index 2688fe35..049787de 100644 --- a/src/com/stuypulse/stuylib/math/readme.md +++ b/src/com/stuypulse/stuylib/math/readme.md @@ -1,23 +1,23 @@ # StuyLib Math Library -## What is the point of these classes +The Math library in StuyLib contains helpful utilities that make FRC programming easier and cleaner. ### [SLMath](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/SLMath.java) -SLMath is just a class with some static math functions that are useful in robotics. +SLMath is a class with static math functions that are useful in robotics. -For example, when squaring a number, `SLMath.square(x)` will keep the sign of the number. *this is used when filtering controller inputs* `SLMath.pow(x, p)` will also keep the sign of x no matter what the value of x or p. This might not seem useful normally, but is nice to have in FRC. +For example, when squaring a number, `SLMath.square(x)` will keep the sign of the number. *This is used when filtering controller inputs.* `SLMath.pow(x, p)` will also keep the sign of `x` no matter what the value of `x` or `p`. This might not seem useful normally, but is nice to have in FRC. Other functions like `SLMath.limit` or `SLMath.deadband` are super helpful in FRC. -### [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) +### [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) -This is just a standard Vector2D class that has every feature you would need, and also works with our other classes in Stuylib. It also works nicely with our [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Angle.java) class, which is a nice bonus. +This is an [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) class that removes the confusion about degrees and radians, and works nicely with our [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java). When doing math with the [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) class, you do not need to worry about the value of the angle being outside the range of `-pi < x < pi`. -### [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) +### [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) -This is an angle class that removes the confusion about degrees / radians, and works nicely with our [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java). When doing math with the angle class, you do not need to worry about the value of the angle being outside the range of `-pi < x < pi`. +The [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) class contains features that cover common coordinate vector manipulation needs, and also works with other classes in StuyLib. It also works nicely with the [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Angle.java) class. -## Summary +### [Polar2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Polar2D.java) -This Math folder in stuylib contains some helpful utilities that make programming FRC code a little bit easier. \ No newline at end of file +The [Polar2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Polar2D.java) class contains features that cover common polar vector manipulation needs. It is heavily dependant on the [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Angle.java) and [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) classes. \ No newline at end of file diff --git a/src/com/stuypulse/stuylib/network/readme.md b/src/com/stuypulse/stuylib/network/readme.md index d060cf7b..dd1e2a5f 100644 --- a/src/com/stuypulse/stuylib/network/readme.md +++ b/src/com/stuypulse/stuylib/network/readme.md @@ -1,3 +1,49 @@ # StuyLib Robot Networking Library -WIP... \ No newline at end of file +The Robot Networking Library simplifies user interaction with the APIs of various network elements of FRC Robotics such as NetworkTables / SmartDashboard or the Limelight. + +## Usage + +Say we wanted to insert values into SmartDashboard which we could use to control a motor, either in code or on SmartDashboard, we could write: +``` +SmartNumber MOTOR_SPEED = new SmartNumber("Conveyor/Motor Speed", 1.0); +SmartBoolean MOTOR_DISABLED = new SmartBoolean("Conveyor/Disabled", false) +``` + +By creating a new SmartNumber, we can now adjust the speed of the motor using SmartDashboard during testing. In addition, we can toggle the reject function of the motor through SmartDashboard or by manipulating the SmartBoolean value through code. Using SmartDashboard to store values allow for them to be "centralized" and more easily accessible throughout the program. + +For example, if we wanted to disable a motor: +``` +if (shouldDisableMotor()) { + Settings.Subsystem.MOTOR_DISABLED.set(true); +} +``` +If we want to run a motor: +``` +if (hasBall()) { + motor.set(Settings.Subsystem.MOTOR_SPEED.get()) +} +else { + motor.stopMotor() +} +``` + +### [Limelight](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/limelight/readme.md) + +Read the limelight [`readme.md`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/limelight/readme.md) to learn more. + +### [SLNetworkTable](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SLNetworkTable.java) + +[SLNetworkTable](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SLNetworkTable.java) is used to easily interface with a network table. It can be used to get or set values on the network table. + +### [SmartBoolean](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartBoolean.java) + +[SmartBoolean](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartBoolean.java) is a wrapper of the SmartDashboard API for manipulating `boolean` values on SmartDashboard. + +### [SmartNumber](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartNumber.java) + +[SmartNumber](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartNumber.java) is a wrapper of the SmartDashboard API for manipulating `double` values on SmartDashboard. Their values can be the returned, casted as a `double`, `float`, `int`, or `long`. + +### [SmartString](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartString.java) + +[SmartString](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartString.java) is a wrapper of the SmartDashboard API for manipulating `String` values on SmartDashboard. \ No newline at end of file diff --git a/src/com/stuypulse/stuylib/streams/filters/readme.md b/src/com/stuypulse/stuylib/streams/filters/readme.md index bce64a5f..d68c5f6a 100644 --- a/src/com/stuypulse/stuylib/streams/filters/readme.md +++ b/src/com/stuypulse/stuylib/streams/filters/readme.md @@ -2,9 +2,9 @@ ## What is a filter? -A filter is basically a class / function that takes in a value, and returns the "filtered" value. +A filter is a class / function that takes in a value and returns the "filtered" value. -For example say we made a Moving Average Filter. +For example, below is an example of a Moving Average filter. ```java // Returns the average of the last 3 values @@ -17,36 +17,38 @@ System.out.println(avg.get(4)); // Prints: 3.0 System.out.println(avg.get(5)); // Prints: 4.0 ``` -Everytime we called `.get()` on the filter, it returned the averagee of the last 3 values, because thats what the filter was made to do. +Every time we call `.get()` on the filter, it returned the average of the last 3 values. -## What should we use them for? +## Usage ### Ramping Motors When sending speed values to motors, you might not always want them to update immediately, as that could cause jerk and current spikes. -In WPILib, there is the option to ramp motors when configuring them. This ramping algorithm is analygous to the filtering done by the filter called [Rate Limit](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/RateLimit.java). RateLimit works good for smoothing out the motion of the robot, but through testing we have found that the filter called [LowPass Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java), does a much nicer job of providing smooth motion without introducing a large delay. +In WPILib, there is the option to ramp motors when configuring them. This ramping algorithm is analygous to the filtering done by the filter called [`RateLimit`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/RateLimit.java). `RateLimit` works well for smoothing out the motion of the robot, however through testing we have found that the filter called a [`LowPassFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java), does a significantly better job at providing smooth motion without introducing a large delay. -We did experiment with [Speed Profile](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/SpeedProfile.java), which algebraicly removes jerk from the inputs of a conroller, however the delay it introduced killed its usefulness compared to [LowPass Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java). +We experimented with [`SpeedProfile`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/SpeedProfile.java), which algebraically removes jerk from the inputs of a controller, however the delay it introduced significantly lowered usefulness compared to [`LowPassFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java). -The reduced jerk when controlling the motors is a huge advantage as it uses less power, and prevents the robot from skipping / tilting, which can mess with sensor data. This allows the driver to drive faster without worrying about damaging the robot. - -Delay is the biggest issue with filters. Because they can not predict the future, it's impossible for it to smooth out values without introducing some amount of delay. We've found that filters that prioritize recent values more than past ones, are able to do the best. +The reduced jerk when controlling the motors is a huge advantage compared to unfiltered input, as it uses less power and prevents the robot from skidding / tilting, which can mess with sensor data. This allows the driver to drive faster and smoother, without worrying about damaging the robot. ### Filtering Data -When reading data from something like the Limelight or an encoder, sometimes noise can be an issue. Encoders sometimes include a form of [Moving Average](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/MovingAverage.java) to smooth out noise in data. However, filters can often add a delay, which if fed into a PID loop, can often cause decreased performance. We've found that using a small [LowPass Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java) on data that has a slight bit of noise in it can help a lot, however it will decrease performance. +When reading data from something like the Limelight or an encoder, sometimes noise can be an issue. Encoders sometimes include a form of [`MovingAverage`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/MovingAverage.java) to smooth out noise in data. However, filters can often add a delay, which if fed into a PID loop, can often cause decreased performance. We've found that using a small [`LowPassFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java) on data that has a slight bit of noise in it can help a lot, however it will decrease performance. + +A recently added filter named [`MedianFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/MedianFilter.java) is able to reduce noise while not having a huge impact on delay. It is good to combine this filter with other filters to get an optimal result. + +## Filter Delay -A recently added filter named [Median Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/MedianFilter.java) is able to reduce noise while not having a huge impact on delay. It is good to combine this filter with other filters to get an optimal result. +Delay is the biggest issue with filters. Due to their inability predict the future, it's impossible for it to smooth out values without introducing some amount of delay. We've found that filters that prioritize recent values more than past ones, are able to perform with lower delay whilst maintining impressive filtering performance. -## Which Filter should I use? +## Choosing your filter -Some filters have internal timers in them which keep track of real world time. This is helpful if the data your collecting is real time, and in a time series. When it comes to FRC Robotics, almost all data that we have used filters on is real time. Be sure to read the documentation of certain filters to see which ones use timers in them. +Some filters have internal timers in them which keep track of real world time. This is helpful if the data your collecting is real time, and in a time series. When it comes to FRC robotics, almost all data that we have used filters on is real time. Be sure to read the documentation of certain filters to see which ones use timers in them. -Depending on which type of data you are working with, some filters might be better than others. However, we've found the [LowPass Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java) to be an amazing all around filter, and should be used as a Rule of Thumb when testing out filters. *(meaning that LowPass Filters will usually be the best)* +Depending on which type of data you are working with, some filters might be better than others. However, we've found the [`LowPassFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java) to be an amazing all around filter, and should be used as a Rule of Thumb when testing out filters *(`LowPass` filters will usually be the best)*. -Also, combine filters using [IFilterGroup](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/IFilterGroup.java), as filtering filtered values can often have interesting and desirable results. +Filters can be combined using [`IFilterGroup`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/IFilterGroup.java), as filtering filtered values can often have interesting and desirable results. ## Why do filters take in `Numbers` instead of `double`? -In order to help make filters more configurable, the configuation is done using the Number class. Why? Because [SmartNumber](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartNumber.java) extends `Number`, which makes it extremely easy to change values like the RC of a [LowPass Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java) on the fly. +In order to help make filters more configurable, the configuation is done using the Number class. Why? Because [SmartNumber](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartNumber.java) extends `Number`, which makes it extremely easy to change values, such as the RC of a [`LowPassFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java), on the fly. diff --git a/src/com/stuypulse/stuylib/streams/readme.md b/src/com/stuypulse/stuylib/streams/readme.md index caab1eec..f60c27dd 100644 --- a/src/com/stuypulse/stuylib/streams/readme.md +++ b/src/com/stuypulse/stuylib/streams/readme.md @@ -1,6 +1,8 @@ # StuyLib Streams Library -## What is a Stream +The Streams library in StuyLib contains streams which return a stream of data. It also contains [filters](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters) which can be used to filter through raw input to reduce noise, jitter, input spikes, and jerkiness. + +## What is a stream? A stream is any class / lambda that when you call `.get()` it returns a double. @@ -17,7 +19,7 @@ System.out.println(speed.get()); // Prints the current desired speed By using a stream here, we now have an object we can call / pass around to get the desired speed of the robot. All we would need to do is call `.get()` to recieve the data. -## Why is this useful +## Why is this useful? An [IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/IStream.java) is a useful object to pass around as it represents a constantly updating stream of information. There are things we can do with this stream to get some extra functionality. @@ -33,6 +35,21 @@ IStream filtered_speed = new FilteredIStream(speed, new LowPassFilter(0.5)); System.out.println(filtered_speed.get()); // Prints the filtered value of the stream ``` +### [PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java) + +[PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java) is a very powerful wrapper around an [IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/IStream.java) that polls the underlying `.get()` function a fixed number of times per second. When you call `.get()` on a [PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java), it will return you the last polled value from the underlying stream. + +```java +// Creates an IStream that is updated 50 times a second. +IStream polled_speed = new PollingIStream(speed, 50.0); +``` + +This is useful for streams where the state changes when you call `.get()`. Say you were using reading from [CSVIStream.Reader](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/CSVIStream.java), but you wanted a new value every 50th of a second. By using a PollingIStream, no matter how fast you call `.get()`, you will only ever recieve a new value every 50th of a second. When using a [Filtered IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/FilteredIStream.java) or a [CSVIStream.Reader](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/CSVIStream.java), the value can change when you call `.get()`, so its important to be aware when you poll a stream. + +### [BufferedIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/BufferedIStream.java) + +A [BufferedIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/BufferedIStream.java) is just a wrapper around a normal [IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/IStream.java) that lets you access past values with `.get(delta)`. When stored inside an IStream it acts identically to the original stream, making its usage a bit difficult. + ### [CSVIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/CSVIStream.java) CSVIStream has two child classes in it, `CSVIStream.Writer` and `CSVIStream.Reader`. @@ -56,18 +73,3 @@ System.out.println(file_speed.get()); // The third value of the CSV file. ``` This is useful in general for things like logging or reading CSV files in a streamlined way. - -### [PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java) - -[PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java) is a very powerful wrapper around an [IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/IStream.java) that polls the underlying `.get()` function a fixed number of times per second. When you call `.get()` on a [PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java), it will return you the last polled value from the underlying stream. - -```java -// Creates an IStream that is updated 50 times a second. -IStream polled_speed = new PollingIStream(speed, 50.0); -``` - -This is useful for streams where the state changes when you call `.get()`. Say you were using reading from [CSVIStream.Reader](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/CSVIStream.java), but you wanted a new value every 50th of a second. By using a PollingIStream, no matter how fast you call `.get()`, you will only ever recieve a new value every 50th of a second. When using a [Filtered IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/FilteredIStream.java) or a [CSVIStream.Reader](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/CSVIStream.java), the value can change when you call `.get()`, so its important to be aware when you poll a stream. - -### [BufferedIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/BufferedIStream.java) - -A [BufferedIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/BufferedIStream.java) is just a wrapper around a normal [IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/IStream.java) that lets you access past values with `.get(delta)`. When stored inside an IStream it acts identically to the original stream, making its usage a bit difficult. diff --git a/src/com/stuypulse/stuylib/util/readme.md b/src/com/stuypulse/stuylib/util/readme.md index 9db2b1d2..dd56d10a 100644 --- a/src/com/stuypulse/stuylib/util/readme.md +++ b/src/com/stuypulse/stuylib/util/readme.md @@ -1,3 +1,11 @@ # StuyLib Misc Utils. -WIP... \ No newline at end of file +These miscellaneous utility classes do not fall under any of the other sublibraries and exist as experiments or as classes that are handy to have around. + +### [StopWatch](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/util/StopWatch.java) + +The [StopWatch](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/util/StopWatch.java) class can be used as timers in other classes which depend on intervals of time. + +### [HashBuilder](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/util/HashBuilder.java) + +The [HashBuilder](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/util/HashBuilder.java) class implements various hash manipulation features and exists as an experiment with generating and manipulating hashes. \ No newline at end of file From 1378542710c7cd710b291f4b0f6ea0573c316525 Mon Sep 17 00:00:00 2001 From: anivanchen Date: Tue, 5 Apr 2022 23:50:20 -0400 Subject: [PATCH 02/18] Update limelight README --- .../stuylib/network/limelight/readme.md | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/com/stuypulse/stuylib/network/limelight/readme.md b/src/com/stuypulse/stuylib/network/limelight/readme.md index 927217fd..e735659c 100644 --- a/src/com/stuypulse/stuylib/network/limelight/readme.md +++ b/src/com/stuypulse/stuylib/network/limelight/readme.md @@ -1,3 +1,34 @@ # StuyLib Limelight Library -WIP... \ No newline at end of file +The Limelight Library allows the programmer to interface with the Limelight's network table. It allows for cleaner code which would be used for robot functions such as alignment for shooting or target acquisition. + +### [Limelight](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/limelight/Limelight.java) + +[Limelight](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/limelight/Limelight.java) allows you to check the status of the limelight and get raw data from the limelight, along with data regarding the target, and utilize the returned data in manipulating the robot to align with a target. It also features low level control over the various elements of the Limelight's pipeline such as `LEDMode`. + +Example: To determine the distance of the limelight from the target... + +``` +double targetHeight = 96.0; +double limelightHeight = 38.7; +double limelightPitch = 27.0; +double heightDifference = targetHeight - limelightHeight; + +public static boolean hasAnyTarget() { + return kLimelight.getValidTarget(); +} + +public static Angle getYAngle() { + if (hasAnyTarget()) { + return Angle.fromDegrees(kLimelight.getTargetYAngle() + limelightPitch); + } + return Angle.kZero; +} + +public static double getDistance() { + if (hasAnyTarget()) { + return heightDifference / getYAngle().tan(); + } + return Angle.kZero; +} +``` From 2cb2fbdb6a7842a52511c76b233ea7c7b32c048e Mon Sep 17 00:00:00 2001 From: anivanchen Date: Wed, 6 Apr 2022 10:09:27 -0400 Subject: [PATCH 03/18] More READMEs and fix typo --- src/com/stuypulse/stuylib/input/Gamepad.java | 2 +- .../stuylib/input/gamepads/readme.md | 16 ++++++++++++++- .../stuylib/input/keyboard/readme.md | 13 +++++++++++- src/com/stuypulse/stuylib/input/readme.md | 20 +++++++++++++++++-- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/com/stuypulse/stuylib/input/Gamepad.java b/src/com/stuypulse/stuylib/input/Gamepad.java index d87c6a74..4ba3cca2 100644 --- a/src/com/stuypulse/stuylib/input/Gamepad.java +++ b/src/com/stuypulse/stuylib/input/Gamepad.java @@ -11,7 +11,7 @@ import edu.wpi.first.wpilibj2.command.button.Button; /** - * An class for using gamepads with different interfaces. You can implement this class in another + * A class for using gamepads with different interfaces. You can implement this class in another * file, and then use it with a standard interface. * *

Any unimplemented buttons will never be triggered, so if a certain controller is missing one, diff --git a/src/com/stuypulse/stuylib/input/gamepads/readme.md b/src/com/stuypulse/stuylib/input/gamepads/readme.md index 400c0c62..fa3be135 100644 --- a/src/com/stuypulse/stuylib/input/gamepads/readme.md +++ b/src/com/stuypulse/stuylib/input/gamepads/readme.md @@ -1,3 +1,17 @@ # StuyLib Gamepad Implementations -WIP... \ No newline at end of file +Implementations of various gamepads used in FRC robotics + +### AutoGamepad + +### Logitech + +### PS4 + +### Xbox + +### KeyGamepad + +### NetKeyGamepad + +### SimKeyGamepad \ No newline at end of file diff --git a/src/com/stuypulse/stuylib/input/keyboard/readme.md b/src/com/stuypulse/stuylib/input/keyboard/readme.md index 73d6c9b9..f062fefc 100644 --- a/src/com/stuypulse/stuylib/input/keyboard/readme.md +++ b/src/com/stuypulse/stuylib/input/keyboard/readme.md @@ -1,3 +1,14 @@ # StuyLib Network Keyboard -WIP... \ No newline at end of file +### [NetKeyboard](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyboard.java) + +[NetKeyboard](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyboard.java) implements and simplifies interactions with keyboard information through a network table. + +### [NetKeyListener](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyListener.java) + +[NetKeyListener](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyListener.java) listens for and uploads keyboard events to the keyboard network table. + +### [NetKeyWindow](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyWindow.java) + +[NetKeyWindow](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyWindow.java) opens a Java AWT window and simulates a keyboard with a [NetKeyListener](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyListener.java) which can be used to control a robot. + diff --git a/src/com/stuypulse/stuylib/input/readme.md b/src/com/stuypulse/stuylib/input/readme.md index f0cbefe4..cf136ecb 100644 --- a/src/com/stuypulse/stuylib/input/readme.md +++ b/src/com/stuypulse/stuylib/input/readme.md @@ -1,3 +1,19 @@ -# StuyLib Gamepad Library +# StuyLib Input Library -WIP... \ No newline at end of file +The Input library contains classes which simplifies gamepad / keyboard input and standardizes the way input is handled and retrieved. + +To learn about specific gamepads, [read here](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/readme.md). + +To learn about keyboard input, [read here](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/readme.md). + +### [Gamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/Gamepad.java) + +[Gamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/Gamepad.java) is a class which standardizes the gamepad interface. It does not do anything by itself and must be extended by other gamepads. + +### [GamepadState](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/GamepadState.java) + +[GamepadState](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/GamepadState.java) stores the state of a [`Gamepad`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/Gamepad.java) separated by the different buttons and axis. Yet to be implemented, it can be used to "record" and "play back" gamepad input. + +### [SPIGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/WPIGamepad.java) + +The [SPIGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/WPIGamepad.java) class adds functions which make interactions with WPILib's `Joystick` class simpler. From 35d74f55f095f65060e263c9b5c7ca7afdbbd21f Mon Sep 17 00:00:00 2001 From: anivanchen Date: Wed, 6 Apr 2022 14:31:25 -0400 Subject: [PATCH 04/18] MORE READMEs --- .../stuylib/input/gamepads/readme.md | 30 ++++++++++++++----- .../stuylib/input/keyboard/readme.md | 3 +- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/com/stuypulse/stuylib/input/gamepads/readme.md b/src/com/stuypulse/stuylib/input/gamepads/readme.md index fa3be135..4469924f 100644 --- a/src/com/stuypulse/stuylib/input/gamepads/readme.md +++ b/src/com/stuypulse/stuylib/input/gamepads/readme.md @@ -1,17 +1,31 @@ # StuyLib Gamepad Implementations -Implementations of various gamepads used in FRC robotics +Implementations of various gamepads used in FRC robotics. -### AutoGamepad +### [AutoGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) -### Logitech +[AutoGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) detects the gamepad you are using and uses this to determine which gamepad implementation to return for your connected gamepad. It is used to prevent wrong values from being read from your gamepad due to your code believing you are using a different type than the one you are using. -### PS4 +### [Logitech](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) -### Xbox +[Logitech](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) is the implementation of the Logitech gamepad, which has an X and D mode. -### KeyGamepad +### [PS4](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) -### NetKeyGamepad +[PS4](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) is the implementation of the PS4 gamepad. -### SimKeyGamepad \ No newline at end of file +### [Xbox](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) + +[Xbox](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) is the implementation of the Xbox gamepad. + +### [KeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) + +[KeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) manages the keymapping for keyboard gamepads. + +### [NetKeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) + +[NetKeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java)takes in keyboard inputs and maps them to a gamepad to simulate a gamepad, despite using a keyboard as an input medium. + +### [SimKeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) + +[SimKeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) opens a window which accepts keyboard / trackpad inputs within the window and maps them to a gamepad to simulate one. It is meant to be used in the robot simulation and will not work on an actual robot, except the [Romi](https://github.com/StuyPulse/StuyRomi) which utilizes the simulator for control. \ No newline at end of file diff --git a/src/com/stuypulse/stuylib/input/keyboard/readme.md b/src/com/stuypulse/stuylib/input/keyboard/readme.md index f062fefc..aaeffded 100644 --- a/src/com/stuypulse/stuylib/input/keyboard/readme.md +++ b/src/com/stuypulse/stuylib/input/keyboard/readme.md @@ -1,5 +1,7 @@ # StuyLib Network Keyboard +Network keyboards can be used as input devices to trigger commands during testing, especially when running simulations or the [Romi](https://github.com/StuyPulse/StuyRomi). + ### [NetKeyboard](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyboard.java) [NetKeyboard](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyboard.java) implements and simplifies interactions with keyboard information through a network table. @@ -11,4 +13,3 @@ ### [NetKeyWindow](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyWindow.java) [NetKeyWindow](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyWindow.java) opens a Java AWT window and simulates a keyboard with a [NetKeyListener](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyListener.java) which can be used to control a robot. - From 6871ae130f2442ef5a6ea077190ad67f3b0d7a95 Mon Sep 17 00:00:00 2001 From: anivanchen Date: Wed, 6 Apr 2022 14:45:05 -0400 Subject: [PATCH 05/18] Start Controls README --- src/com/stuypulse/stuylib/control/readme.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/com/stuypulse/stuylib/control/readme.md b/src/com/stuypulse/stuylib/control/readme.md index a07b58ef..6a2e0c2f 100644 --- a/src/com/stuypulse/stuylib/control/readme.md +++ b/src/com/stuypulse/stuylib/control/readme.md @@ -1,6 +1,20 @@ -# StuyLib Control Algorithms +# StuyLib Control Algorithms Library -WPI... +The Control Algorithms library contains various control algorithms which are commonly used in robotics such as [PID](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDController.java) or [Bang Bang](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/BangBangController.java). They are intuitively programmed and handles the complex mathematics behind each algorithm for the programmer, allowing for beginners to use PID in their control systems. However, it is HIGHLY recommended to have a concrete understanding of what you are using as they require tuning. + +## What is control theory? + + + +### [Controller](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/Controller.java) + +### [BangBangController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/BangBangController.java) + +### [PIDCalculator](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDCalculator.java) + +### [PIDController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDController.java) + +### [TBHController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/TBHController.java) ## Why is `Number` used over `double` From 6f00594135305708fc9643aa3efb15f79716e7f8 Mon Sep 17 00:00:00 2001 From: anivanchen Date: Tue, 5 Apr 2022 23:00:51 -0400 Subject: [PATCH 06/18] Update READMEs --- src/com/stuypulse/stuylib/math/readme.md | 18 +++---- src/com/stuypulse/stuylib/network/readme.md | 48 ++++++++++++++++++- .../stuylib/streams/filters/readme.md | 34 ++++++------- src/com/stuypulse/stuylib/streams/readme.md | 36 +++++++------- src/com/stuypulse/stuylib/util/readme.md | 10 +++- 5 files changed, 102 insertions(+), 44 deletions(-) diff --git a/src/com/stuypulse/stuylib/math/readme.md b/src/com/stuypulse/stuylib/math/readme.md index 2688fe35..049787de 100644 --- a/src/com/stuypulse/stuylib/math/readme.md +++ b/src/com/stuypulse/stuylib/math/readme.md @@ -1,23 +1,23 @@ # StuyLib Math Library -## What is the point of these classes +The Math library in StuyLib contains helpful utilities that make FRC programming easier and cleaner. ### [SLMath](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/SLMath.java) -SLMath is just a class with some static math functions that are useful in robotics. +SLMath is a class with static math functions that are useful in robotics. -For example, when squaring a number, `SLMath.square(x)` will keep the sign of the number. *this is used when filtering controller inputs* `SLMath.pow(x, p)` will also keep the sign of x no matter what the value of x or p. This might not seem useful normally, but is nice to have in FRC. +For example, when squaring a number, `SLMath.square(x)` will keep the sign of the number. *This is used when filtering controller inputs.* `SLMath.pow(x, p)` will also keep the sign of `x` no matter what the value of `x` or `p`. This might not seem useful normally, but is nice to have in FRC. Other functions like `SLMath.limit` or `SLMath.deadband` are super helpful in FRC. -### [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) +### [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) -This is just a standard Vector2D class that has every feature you would need, and also works with our other classes in Stuylib. It also works nicely with our [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Angle.java) class, which is a nice bonus. +This is an [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) class that removes the confusion about degrees and radians, and works nicely with our [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java). When doing math with the [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) class, you do not need to worry about the value of the angle being outside the range of `-pi < x < pi`. -### [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) +### [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) -This is an angle class that removes the confusion about degrees / radians, and works nicely with our [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java). When doing math with the angle class, you do not need to worry about the value of the angle being outside the range of `-pi < x < pi`. +The [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) class contains features that cover common coordinate vector manipulation needs, and also works with other classes in StuyLib. It also works nicely with the [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Angle.java) class. -## Summary +### [Polar2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Polar2D.java) -This Math folder in stuylib contains some helpful utilities that make programming FRC code a little bit easier. \ No newline at end of file +The [Polar2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Polar2D.java) class contains features that cover common polar vector manipulation needs. It is heavily dependant on the [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Angle.java) and [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) classes. \ No newline at end of file diff --git a/src/com/stuypulse/stuylib/network/readme.md b/src/com/stuypulse/stuylib/network/readme.md index d060cf7b..dd1e2a5f 100644 --- a/src/com/stuypulse/stuylib/network/readme.md +++ b/src/com/stuypulse/stuylib/network/readme.md @@ -1,3 +1,49 @@ # StuyLib Robot Networking Library -WIP... \ No newline at end of file +The Robot Networking Library simplifies user interaction with the APIs of various network elements of FRC Robotics such as NetworkTables / SmartDashboard or the Limelight. + +## Usage + +Say we wanted to insert values into SmartDashboard which we could use to control a motor, either in code or on SmartDashboard, we could write: +``` +SmartNumber MOTOR_SPEED = new SmartNumber("Conveyor/Motor Speed", 1.0); +SmartBoolean MOTOR_DISABLED = new SmartBoolean("Conveyor/Disabled", false) +``` + +By creating a new SmartNumber, we can now adjust the speed of the motor using SmartDashboard during testing. In addition, we can toggle the reject function of the motor through SmartDashboard or by manipulating the SmartBoolean value through code. Using SmartDashboard to store values allow for them to be "centralized" and more easily accessible throughout the program. + +For example, if we wanted to disable a motor: +``` +if (shouldDisableMotor()) { + Settings.Subsystem.MOTOR_DISABLED.set(true); +} +``` +If we want to run a motor: +``` +if (hasBall()) { + motor.set(Settings.Subsystem.MOTOR_SPEED.get()) +} +else { + motor.stopMotor() +} +``` + +### [Limelight](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/limelight/readme.md) + +Read the limelight [`readme.md`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/limelight/readme.md) to learn more. + +### [SLNetworkTable](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SLNetworkTable.java) + +[SLNetworkTable](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SLNetworkTable.java) is used to easily interface with a network table. It can be used to get or set values on the network table. + +### [SmartBoolean](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartBoolean.java) + +[SmartBoolean](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartBoolean.java) is a wrapper of the SmartDashboard API for manipulating `boolean` values on SmartDashboard. + +### [SmartNumber](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartNumber.java) + +[SmartNumber](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartNumber.java) is a wrapper of the SmartDashboard API for manipulating `double` values on SmartDashboard. Their values can be the returned, casted as a `double`, `float`, `int`, or `long`. + +### [SmartString](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartString.java) + +[SmartString](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartString.java) is a wrapper of the SmartDashboard API for manipulating `String` values on SmartDashboard. \ No newline at end of file diff --git a/src/com/stuypulse/stuylib/streams/filters/readme.md b/src/com/stuypulse/stuylib/streams/filters/readme.md index bce64a5f..d68c5f6a 100644 --- a/src/com/stuypulse/stuylib/streams/filters/readme.md +++ b/src/com/stuypulse/stuylib/streams/filters/readme.md @@ -2,9 +2,9 @@ ## What is a filter? -A filter is basically a class / function that takes in a value, and returns the "filtered" value. +A filter is a class / function that takes in a value and returns the "filtered" value. -For example say we made a Moving Average Filter. +For example, below is an example of a Moving Average filter. ```java // Returns the average of the last 3 values @@ -17,36 +17,38 @@ System.out.println(avg.get(4)); // Prints: 3.0 System.out.println(avg.get(5)); // Prints: 4.0 ``` -Everytime we called `.get()` on the filter, it returned the averagee of the last 3 values, because thats what the filter was made to do. +Every time we call `.get()` on the filter, it returned the average of the last 3 values. -## What should we use them for? +## Usage ### Ramping Motors When sending speed values to motors, you might not always want them to update immediately, as that could cause jerk and current spikes. -In WPILib, there is the option to ramp motors when configuring them. This ramping algorithm is analygous to the filtering done by the filter called [Rate Limit](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/RateLimit.java). RateLimit works good for smoothing out the motion of the robot, but through testing we have found that the filter called [LowPass Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java), does a much nicer job of providing smooth motion without introducing a large delay. +In WPILib, there is the option to ramp motors when configuring them. This ramping algorithm is analygous to the filtering done by the filter called [`RateLimit`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/RateLimit.java). `RateLimit` works well for smoothing out the motion of the robot, however through testing we have found that the filter called a [`LowPassFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java), does a significantly better job at providing smooth motion without introducing a large delay. -We did experiment with [Speed Profile](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/SpeedProfile.java), which algebraicly removes jerk from the inputs of a conroller, however the delay it introduced killed its usefulness compared to [LowPass Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java). +We experimented with [`SpeedProfile`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/SpeedProfile.java), which algebraically removes jerk from the inputs of a controller, however the delay it introduced significantly lowered usefulness compared to [`LowPassFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java). -The reduced jerk when controlling the motors is a huge advantage as it uses less power, and prevents the robot from skipping / tilting, which can mess with sensor data. This allows the driver to drive faster without worrying about damaging the robot. - -Delay is the biggest issue with filters. Because they can not predict the future, it's impossible for it to smooth out values without introducing some amount of delay. We've found that filters that prioritize recent values more than past ones, are able to do the best. +The reduced jerk when controlling the motors is a huge advantage compared to unfiltered input, as it uses less power and prevents the robot from skidding / tilting, which can mess with sensor data. This allows the driver to drive faster and smoother, without worrying about damaging the robot. ### Filtering Data -When reading data from something like the Limelight or an encoder, sometimes noise can be an issue. Encoders sometimes include a form of [Moving Average](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/MovingAverage.java) to smooth out noise in data. However, filters can often add a delay, which if fed into a PID loop, can often cause decreased performance. We've found that using a small [LowPass Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java) on data that has a slight bit of noise in it can help a lot, however it will decrease performance. +When reading data from something like the Limelight or an encoder, sometimes noise can be an issue. Encoders sometimes include a form of [`MovingAverage`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/MovingAverage.java) to smooth out noise in data. However, filters can often add a delay, which if fed into a PID loop, can often cause decreased performance. We've found that using a small [`LowPassFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java) on data that has a slight bit of noise in it can help a lot, however it will decrease performance. + +A recently added filter named [`MedianFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/MedianFilter.java) is able to reduce noise while not having a huge impact on delay. It is good to combine this filter with other filters to get an optimal result. + +## Filter Delay -A recently added filter named [Median Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/MedianFilter.java) is able to reduce noise while not having a huge impact on delay. It is good to combine this filter with other filters to get an optimal result. +Delay is the biggest issue with filters. Due to their inability predict the future, it's impossible for it to smooth out values without introducing some amount of delay. We've found that filters that prioritize recent values more than past ones, are able to perform with lower delay whilst maintining impressive filtering performance. -## Which Filter should I use? +## Choosing your filter -Some filters have internal timers in them which keep track of real world time. This is helpful if the data your collecting is real time, and in a time series. When it comes to FRC Robotics, almost all data that we have used filters on is real time. Be sure to read the documentation of certain filters to see which ones use timers in them. +Some filters have internal timers in them which keep track of real world time. This is helpful if the data your collecting is real time, and in a time series. When it comes to FRC robotics, almost all data that we have used filters on is real time. Be sure to read the documentation of certain filters to see which ones use timers in them. -Depending on which type of data you are working with, some filters might be better than others. However, we've found the [LowPass Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java) to be an amazing all around filter, and should be used as a Rule of Thumb when testing out filters. *(meaning that LowPass Filters will usually be the best)* +Depending on which type of data you are working with, some filters might be better than others. However, we've found the [`LowPassFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java) to be an amazing all around filter, and should be used as a Rule of Thumb when testing out filters *(`LowPass` filters will usually be the best)*. -Also, combine filters using [IFilterGroup](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/IFilterGroup.java), as filtering filtered values can often have interesting and desirable results. +Filters can be combined using [`IFilterGroup`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/IFilterGroup.java), as filtering filtered values can often have interesting and desirable results. ## Why do filters take in `Numbers` instead of `double`? -In order to help make filters more configurable, the configuation is done using the Number class. Why? Because [SmartNumber](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartNumber.java) extends `Number`, which makes it extremely easy to change values like the RC of a [LowPass Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java) on the fly. +In order to help make filters more configurable, the configuation is done using the Number class. Why? Because [SmartNumber](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartNumber.java) extends `Number`, which makes it extremely easy to change values, such as the RC of a [`LowPassFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java), on the fly. diff --git a/src/com/stuypulse/stuylib/streams/readme.md b/src/com/stuypulse/stuylib/streams/readme.md index caab1eec..f60c27dd 100644 --- a/src/com/stuypulse/stuylib/streams/readme.md +++ b/src/com/stuypulse/stuylib/streams/readme.md @@ -1,6 +1,8 @@ # StuyLib Streams Library -## What is a Stream +The Streams library in StuyLib contains streams which return a stream of data. It also contains [filters](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters) which can be used to filter through raw input to reduce noise, jitter, input spikes, and jerkiness. + +## What is a stream? A stream is any class / lambda that when you call `.get()` it returns a double. @@ -17,7 +19,7 @@ System.out.println(speed.get()); // Prints the current desired speed By using a stream here, we now have an object we can call / pass around to get the desired speed of the robot. All we would need to do is call `.get()` to recieve the data. -## Why is this useful +## Why is this useful? An [IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/IStream.java) is a useful object to pass around as it represents a constantly updating stream of information. There are things we can do with this stream to get some extra functionality. @@ -33,6 +35,21 @@ IStream filtered_speed = new FilteredIStream(speed, new LowPassFilter(0.5)); System.out.println(filtered_speed.get()); // Prints the filtered value of the stream ``` +### [PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java) + +[PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java) is a very powerful wrapper around an [IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/IStream.java) that polls the underlying `.get()` function a fixed number of times per second. When you call `.get()` on a [PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java), it will return you the last polled value from the underlying stream. + +```java +// Creates an IStream that is updated 50 times a second. +IStream polled_speed = new PollingIStream(speed, 50.0); +``` + +This is useful for streams where the state changes when you call `.get()`. Say you were using reading from [CSVIStream.Reader](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/CSVIStream.java), but you wanted a new value every 50th of a second. By using a PollingIStream, no matter how fast you call `.get()`, you will only ever recieve a new value every 50th of a second. When using a [Filtered IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/FilteredIStream.java) or a [CSVIStream.Reader](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/CSVIStream.java), the value can change when you call `.get()`, so its important to be aware when you poll a stream. + +### [BufferedIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/BufferedIStream.java) + +A [BufferedIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/BufferedIStream.java) is just a wrapper around a normal [IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/IStream.java) that lets you access past values with `.get(delta)`. When stored inside an IStream it acts identically to the original stream, making its usage a bit difficult. + ### [CSVIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/CSVIStream.java) CSVIStream has two child classes in it, `CSVIStream.Writer` and `CSVIStream.Reader`. @@ -56,18 +73,3 @@ System.out.println(file_speed.get()); // The third value of the CSV file. ``` This is useful in general for things like logging or reading CSV files in a streamlined way. - -### [PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java) - -[PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java) is a very powerful wrapper around an [IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/IStream.java) that polls the underlying `.get()` function a fixed number of times per second. When you call `.get()` on a [PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java), it will return you the last polled value from the underlying stream. - -```java -// Creates an IStream that is updated 50 times a second. -IStream polled_speed = new PollingIStream(speed, 50.0); -``` - -This is useful for streams where the state changes when you call `.get()`. Say you were using reading from [CSVIStream.Reader](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/CSVIStream.java), but you wanted a new value every 50th of a second. By using a PollingIStream, no matter how fast you call `.get()`, you will only ever recieve a new value every 50th of a second. When using a [Filtered IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/FilteredIStream.java) or a [CSVIStream.Reader](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/CSVIStream.java), the value can change when you call `.get()`, so its important to be aware when you poll a stream. - -### [BufferedIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/BufferedIStream.java) - -A [BufferedIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/BufferedIStream.java) is just a wrapper around a normal [IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/IStream.java) that lets you access past values with `.get(delta)`. When stored inside an IStream it acts identically to the original stream, making its usage a bit difficult. diff --git a/src/com/stuypulse/stuylib/util/readme.md b/src/com/stuypulse/stuylib/util/readme.md index 9db2b1d2..dd56d10a 100644 --- a/src/com/stuypulse/stuylib/util/readme.md +++ b/src/com/stuypulse/stuylib/util/readme.md @@ -1,3 +1,11 @@ # StuyLib Misc Utils. -WIP... \ No newline at end of file +These miscellaneous utility classes do not fall under any of the other sublibraries and exist as experiments or as classes that are handy to have around. + +### [StopWatch](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/util/StopWatch.java) + +The [StopWatch](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/util/StopWatch.java) class can be used as timers in other classes which depend on intervals of time. + +### [HashBuilder](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/util/HashBuilder.java) + +The [HashBuilder](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/util/HashBuilder.java) class implements various hash manipulation features and exists as an experiment with generating and manipulating hashes. \ No newline at end of file From 9cdc309fdacf8f234292063575ccc6ce61288faf Mon Sep 17 00:00:00 2001 From: anivanchen Date: Tue, 5 Apr 2022 23:50:20 -0400 Subject: [PATCH 07/18] Update limelight README --- .../stuylib/network/limelight/readme.md | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/com/stuypulse/stuylib/network/limelight/readme.md b/src/com/stuypulse/stuylib/network/limelight/readme.md index 927217fd..e735659c 100644 --- a/src/com/stuypulse/stuylib/network/limelight/readme.md +++ b/src/com/stuypulse/stuylib/network/limelight/readme.md @@ -1,3 +1,34 @@ # StuyLib Limelight Library -WIP... \ No newline at end of file +The Limelight Library allows the programmer to interface with the Limelight's network table. It allows for cleaner code which would be used for robot functions such as alignment for shooting or target acquisition. + +### [Limelight](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/limelight/Limelight.java) + +[Limelight](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/limelight/Limelight.java) allows you to check the status of the limelight and get raw data from the limelight, along with data regarding the target, and utilize the returned data in manipulating the robot to align with a target. It also features low level control over the various elements of the Limelight's pipeline such as `LEDMode`. + +Example: To determine the distance of the limelight from the target... + +``` +double targetHeight = 96.0; +double limelightHeight = 38.7; +double limelightPitch = 27.0; +double heightDifference = targetHeight - limelightHeight; + +public static boolean hasAnyTarget() { + return kLimelight.getValidTarget(); +} + +public static Angle getYAngle() { + if (hasAnyTarget()) { + return Angle.fromDegrees(kLimelight.getTargetYAngle() + limelightPitch); + } + return Angle.kZero; +} + +public static double getDistance() { + if (hasAnyTarget()) { + return heightDifference / getYAngle().tan(); + } + return Angle.kZero; +} +``` From a425c4d1b51312283001d1cd25d11278c3ec1f4b Mon Sep 17 00:00:00 2001 From: anivanchen Date: Wed, 6 Apr 2022 10:09:27 -0400 Subject: [PATCH 08/18] More READMEs and fix typo --- src/com/stuypulse/stuylib/input/Gamepad.java | 2 +- .../stuylib/input/gamepads/readme.md | 16 ++++++++++++++- .../stuylib/input/keyboard/readme.md | 13 +++++++++++- src/com/stuypulse/stuylib/input/readme.md | 20 +++++++++++++++++-- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/com/stuypulse/stuylib/input/Gamepad.java b/src/com/stuypulse/stuylib/input/Gamepad.java index d87c6a74..4ba3cca2 100644 --- a/src/com/stuypulse/stuylib/input/Gamepad.java +++ b/src/com/stuypulse/stuylib/input/Gamepad.java @@ -11,7 +11,7 @@ import edu.wpi.first.wpilibj2.command.button.Button; /** - * An class for using gamepads with different interfaces. You can implement this class in another + * A class for using gamepads with different interfaces. You can implement this class in another * file, and then use it with a standard interface. * *

Any unimplemented buttons will never be triggered, so if a certain controller is missing one, diff --git a/src/com/stuypulse/stuylib/input/gamepads/readme.md b/src/com/stuypulse/stuylib/input/gamepads/readme.md index 400c0c62..fa3be135 100644 --- a/src/com/stuypulse/stuylib/input/gamepads/readme.md +++ b/src/com/stuypulse/stuylib/input/gamepads/readme.md @@ -1,3 +1,17 @@ # StuyLib Gamepad Implementations -WIP... \ No newline at end of file +Implementations of various gamepads used in FRC robotics + +### AutoGamepad + +### Logitech + +### PS4 + +### Xbox + +### KeyGamepad + +### NetKeyGamepad + +### SimKeyGamepad \ No newline at end of file diff --git a/src/com/stuypulse/stuylib/input/keyboard/readme.md b/src/com/stuypulse/stuylib/input/keyboard/readme.md index 73d6c9b9..f062fefc 100644 --- a/src/com/stuypulse/stuylib/input/keyboard/readme.md +++ b/src/com/stuypulse/stuylib/input/keyboard/readme.md @@ -1,3 +1,14 @@ # StuyLib Network Keyboard -WIP... \ No newline at end of file +### [NetKeyboard](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyboard.java) + +[NetKeyboard](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyboard.java) implements and simplifies interactions with keyboard information through a network table. + +### [NetKeyListener](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyListener.java) + +[NetKeyListener](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyListener.java) listens for and uploads keyboard events to the keyboard network table. + +### [NetKeyWindow](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyWindow.java) + +[NetKeyWindow](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyWindow.java) opens a Java AWT window and simulates a keyboard with a [NetKeyListener](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyListener.java) which can be used to control a robot. + diff --git a/src/com/stuypulse/stuylib/input/readme.md b/src/com/stuypulse/stuylib/input/readme.md index f0cbefe4..cf136ecb 100644 --- a/src/com/stuypulse/stuylib/input/readme.md +++ b/src/com/stuypulse/stuylib/input/readme.md @@ -1,3 +1,19 @@ -# StuyLib Gamepad Library +# StuyLib Input Library -WIP... \ No newline at end of file +The Input library contains classes which simplifies gamepad / keyboard input and standardizes the way input is handled and retrieved. + +To learn about specific gamepads, [read here](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/readme.md). + +To learn about keyboard input, [read here](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/readme.md). + +### [Gamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/Gamepad.java) + +[Gamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/Gamepad.java) is a class which standardizes the gamepad interface. It does not do anything by itself and must be extended by other gamepads. + +### [GamepadState](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/GamepadState.java) + +[GamepadState](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/GamepadState.java) stores the state of a [`Gamepad`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/Gamepad.java) separated by the different buttons and axis. Yet to be implemented, it can be used to "record" and "play back" gamepad input. + +### [SPIGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/WPIGamepad.java) + +The [SPIGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/WPIGamepad.java) class adds functions which make interactions with WPILib's `Joystick` class simpler. From 955281ad2c999e4bd1de9ac8526130caf07ad3e2 Mon Sep 17 00:00:00 2001 From: anivanchen Date: Wed, 6 Apr 2022 14:31:25 -0400 Subject: [PATCH 09/18] MORE READMEs --- .../stuylib/input/gamepads/readme.md | 30 ++++++++++++++----- .../stuylib/input/keyboard/readme.md | 3 +- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/com/stuypulse/stuylib/input/gamepads/readme.md b/src/com/stuypulse/stuylib/input/gamepads/readme.md index fa3be135..4469924f 100644 --- a/src/com/stuypulse/stuylib/input/gamepads/readme.md +++ b/src/com/stuypulse/stuylib/input/gamepads/readme.md @@ -1,17 +1,31 @@ # StuyLib Gamepad Implementations -Implementations of various gamepads used in FRC robotics +Implementations of various gamepads used in FRC robotics. -### AutoGamepad +### [AutoGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) -### Logitech +[AutoGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) detects the gamepad you are using and uses this to determine which gamepad implementation to return for your connected gamepad. It is used to prevent wrong values from being read from your gamepad due to your code believing you are using a different type than the one you are using. -### PS4 +### [Logitech](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) -### Xbox +[Logitech](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) is the implementation of the Logitech gamepad, which has an X and D mode. -### KeyGamepad +### [PS4](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) -### NetKeyGamepad +[PS4](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) is the implementation of the PS4 gamepad. -### SimKeyGamepad \ No newline at end of file +### [Xbox](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) + +[Xbox](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) is the implementation of the Xbox gamepad. + +### [KeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) + +[KeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) manages the keymapping for keyboard gamepads. + +### [NetKeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) + +[NetKeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java)takes in keyboard inputs and maps them to a gamepad to simulate a gamepad, despite using a keyboard as an input medium. + +### [SimKeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) + +[SimKeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) opens a window which accepts keyboard / trackpad inputs within the window and maps them to a gamepad to simulate one. It is meant to be used in the robot simulation and will not work on an actual robot, except the [Romi](https://github.com/StuyPulse/StuyRomi) which utilizes the simulator for control. \ No newline at end of file diff --git a/src/com/stuypulse/stuylib/input/keyboard/readme.md b/src/com/stuypulse/stuylib/input/keyboard/readme.md index f062fefc..aaeffded 100644 --- a/src/com/stuypulse/stuylib/input/keyboard/readme.md +++ b/src/com/stuypulse/stuylib/input/keyboard/readme.md @@ -1,5 +1,7 @@ # StuyLib Network Keyboard +Network keyboards can be used as input devices to trigger commands during testing, especially when running simulations or the [Romi](https://github.com/StuyPulse/StuyRomi). + ### [NetKeyboard](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyboard.java) [NetKeyboard](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyboard.java) implements and simplifies interactions with keyboard information through a network table. @@ -11,4 +13,3 @@ ### [NetKeyWindow](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyWindow.java) [NetKeyWindow](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyWindow.java) opens a Java AWT window and simulates a keyboard with a [NetKeyListener](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyListener.java) which can be used to control a robot. - From cd2ae28280e0792f494dd1b3e17eb265047b481f Mon Sep 17 00:00:00 2001 From: anivanchen Date: Wed, 6 Apr 2022 14:45:05 -0400 Subject: [PATCH 10/18] Start Controls README --- src/com/stuypulse/stuylib/control/readme.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/com/stuypulse/stuylib/control/readme.md b/src/com/stuypulse/stuylib/control/readme.md index a07b58ef..6a2e0c2f 100644 --- a/src/com/stuypulse/stuylib/control/readme.md +++ b/src/com/stuypulse/stuylib/control/readme.md @@ -1,6 +1,20 @@ -# StuyLib Control Algorithms +# StuyLib Control Algorithms Library -WPI... +The Control Algorithms library contains various control algorithms which are commonly used in robotics such as [PID](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDController.java) or [Bang Bang](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/BangBangController.java). They are intuitively programmed and handles the complex mathematics behind each algorithm for the programmer, allowing for beginners to use PID in their control systems. However, it is HIGHLY recommended to have a concrete understanding of what you are using as they require tuning. + +## What is control theory? + + + +### [Controller](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/Controller.java) + +### [BangBangController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/BangBangController.java) + +### [PIDCalculator](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDCalculator.java) + +### [PIDController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDController.java) + +### [TBHController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/TBHController.java) ## Why is `Number` used over `double` From c0762a5e9c66b4903ccf8213b5e69a14f471cd2b Mon Sep 17 00:00:00 2001 From: anivanchen Date: Tue, 5 Apr 2022 23:00:51 -0400 Subject: [PATCH 11/18] Update READMEs --- src/com/stuypulse/stuylib/math/readme.md | 18 +++---- src/com/stuypulse/stuylib/network/readme.md | 48 ++++++++++++++++++- .../stuylib/streams/filters/readme.md | 34 ++++++------- src/com/stuypulse/stuylib/streams/readme.md | 36 +++++++------- src/com/stuypulse/stuylib/util/readme.md | 10 +++- 5 files changed, 102 insertions(+), 44 deletions(-) diff --git a/src/com/stuypulse/stuylib/math/readme.md b/src/com/stuypulse/stuylib/math/readme.md index 2688fe35..049787de 100644 --- a/src/com/stuypulse/stuylib/math/readme.md +++ b/src/com/stuypulse/stuylib/math/readme.md @@ -1,23 +1,23 @@ # StuyLib Math Library -## What is the point of these classes +The Math library in StuyLib contains helpful utilities that make FRC programming easier and cleaner. ### [SLMath](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/SLMath.java) -SLMath is just a class with some static math functions that are useful in robotics. +SLMath is a class with static math functions that are useful in robotics. -For example, when squaring a number, `SLMath.square(x)` will keep the sign of the number. *this is used when filtering controller inputs* `SLMath.pow(x, p)` will also keep the sign of x no matter what the value of x or p. This might not seem useful normally, but is nice to have in FRC. +For example, when squaring a number, `SLMath.square(x)` will keep the sign of the number. *This is used when filtering controller inputs.* `SLMath.pow(x, p)` will also keep the sign of `x` no matter what the value of `x` or `p`. This might not seem useful normally, but is nice to have in FRC. Other functions like `SLMath.limit` or `SLMath.deadband` are super helpful in FRC. -### [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) +### [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) -This is just a standard Vector2D class that has every feature you would need, and also works with our other classes in Stuylib. It also works nicely with our [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Angle.java) class, which is a nice bonus. +This is an [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) class that removes the confusion about degrees and radians, and works nicely with our [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java). When doing math with the [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) class, you do not need to worry about the value of the angle being outside the range of `-pi < x < pi`. -### [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) +### [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) -This is an angle class that removes the confusion about degrees / radians, and works nicely with our [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java). When doing math with the angle class, you do not need to worry about the value of the angle being outside the range of `-pi < x < pi`. +The [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) class contains features that cover common coordinate vector manipulation needs, and also works with other classes in StuyLib. It also works nicely with the [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Angle.java) class. -## Summary +### [Polar2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Polar2D.java) -This Math folder in stuylib contains some helpful utilities that make programming FRC code a little bit easier. \ No newline at end of file +The [Polar2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Polar2D.java) class contains features that cover common polar vector manipulation needs. It is heavily dependant on the [Angle](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Angle.java) and [Vector2D](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/math/Vector2D.java) classes. \ No newline at end of file diff --git a/src/com/stuypulse/stuylib/network/readme.md b/src/com/stuypulse/stuylib/network/readme.md index d060cf7b..dd1e2a5f 100644 --- a/src/com/stuypulse/stuylib/network/readme.md +++ b/src/com/stuypulse/stuylib/network/readme.md @@ -1,3 +1,49 @@ # StuyLib Robot Networking Library -WIP... \ No newline at end of file +The Robot Networking Library simplifies user interaction with the APIs of various network elements of FRC Robotics such as NetworkTables / SmartDashboard or the Limelight. + +## Usage + +Say we wanted to insert values into SmartDashboard which we could use to control a motor, either in code or on SmartDashboard, we could write: +``` +SmartNumber MOTOR_SPEED = new SmartNumber("Conveyor/Motor Speed", 1.0); +SmartBoolean MOTOR_DISABLED = new SmartBoolean("Conveyor/Disabled", false) +``` + +By creating a new SmartNumber, we can now adjust the speed of the motor using SmartDashboard during testing. In addition, we can toggle the reject function of the motor through SmartDashboard or by manipulating the SmartBoolean value through code. Using SmartDashboard to store values allow for them to be "centralized" and more easily accessible throughout the program. + +For example, if we wanted to disable a motor: +``` +if (shouldDisableMotor()) { + Settings.Subsystem.MOTOR_DISABLED.set(true); +} +``` +If we want to run a motor: +``` +if (hasBall()) { + motor.set(Settings.Subsystem.MOTOR_SPEED.get()) +} +else { + motor.stopMotor() +} +``` + +### [Limelight](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/limelight/readme.md) + +Read the limelight [`readme.md`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/limelight/readme.md) to learn more. + +### [SLNetworkTable](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SLNetworkTable.java) + +[SLNetworkTable](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SLNetworkTable.java) is used to easily interface with a network table. It can be used to get or set values on the network table. + +### [SmartBoolean](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartBoolean.java) + +[SmartBoolean](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartBoolean.java) is a wrapper of the SmartDashboard API for manipulating `boolean` values on SmartDashboard. + +### [SmartNumber](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartNumber.java) + +[SmartNumber](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartNumber.java) is a wrapper of the SmartDashboard API for manipulating `double` values on SmartDashboard. Their values can be the returned, casted as a `double`, `float`, `int`, or `long`. + +### [SmartString](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartString.java) + +[SmartString](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartString.java) is a wrapper of the SmartDashboard API for manipulating `String` values on SmartDashboard. \ No newline at end of file diff --git a/src/com/stuypulse/stuylib/streams/filters/readme.md b/src/com/stuypulse/stuylib/streams/filters/readme.md index bce64a5f..d68c5f6a 100644 --- a/src/com/stuypulse/stuylib/streams/filters/readme.md +++ b/src/com/stuypulse/stuylib/streams/filters/readme.md @@ -2,9 +2,9 @@ ## What is a filter? -A filter is basically a class / function that takes in a value, and returns the "filtered" value. +A filter is a class / function that takes in a value and returns the "filtered" value. -For example say we made a Moving Average Filter. +For example, below is an example of a Moving Average filter. ```java // Returns the average of the last 3 values @@ -17,36 +17,38 @@ System.out.println(avg.get(4)); // Prints: 3.0 System.out.println(avg.get(5)); // Prints: 4.0 ``` -Everytime we called `.get()` on the filter, it returned the averagee of the last 3 values, because thats what the filter was made to do. +Every time we call `.get()` on the filter, it returned the average of the last 3 values. -## What should we use them for? +## Usage ### Ramping Motors When sending speed values to motors, you might not always want them to update immediately, as that could cause jerk and current spikes. -In WPILib, there is the option to ramp motors when configuring them. This ramping algorithm is analygous to the filtering done by the filter called [Rate Limit](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/RateLimit.java). RateLimit works good for smoothing out the motion of the robot, but through testing we have found that the filter called [LowPass Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java), does a much nicer job of providing smooth motion without introducing a large delay. +In WPILib, there is the option to ramp motors when configuring them. This ramping algorithm is analygous to the filtering done by the filter called [`RateLimit`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/RateLimit.java). `RateLimit` works well for smoothing out the motion of the robot, however through testing we have found that the filter called a [`LowPassFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java), does a significantly better job at providing smooth motion without introducing a large delay. -We did experiment with [Speed Profile](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/SpeedProfile.java), which algebraicly removes jerk from the inputs of a conroller, however the delay it introduced killed its usefulness compared to [LowPass Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java). +We experimented with [`SpeedProfile`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/SpeedProfile.java), which algebraically removes jerk from the inputs of a controller, however the delay it introduced significantly lowered usefulness compared to [`LowPassFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java). -The reduced jerk when controlling the motors is a huge advantage as it uses less power, and prevents the robot from skipping / tilting, which can mess with sensor data. This allows the driver to drive faster without worrying about damaging the robot. - -Delay is the biggest issue with filters. Because they can not predict the future, it's impossible for it to smooth out values without introducing some amount of delay. We've found that filters that prioritize recent values more than past ones, are able to do the best. +The reduced jerk when controlling the motors is a huge advantage compared to unfiltered input, as it uses less power and prevents the robot from skidding / tilting, which can mess with sensor data. This allows the driver to drive faster and smoother, without worrying about damaging the robot. ### Filtering Data -When reading data from something like the Limelight or an encoder, sometimes noise can be an issue. Encoders sometimes include a form of [Moving Average](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/MovingAverage.java) to smooth out noise in data. However, filters can often add a delay, which if fed into a PID loop, can often cause decreased performance. We've found that using a small [LowPass Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java) on data that has a slight bit of noise in it can help a lot, however it will decrease performance. +When reading data from something like the Limelight or an encoder, sometimes noise can be an issue. Encoders sometimes include a form of [`MovingAverage`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/MovingAverage.java) to smooth out noise in data. However, filters can often add a delay, which if fed into a PID loop, can often cause decreased performance. We've found that using a small [`LowPassFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java) on data that has a slight bit of noise in it can help a lot, however it will decrease performance. + +A recently added filter named [`MedianFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/MedianFilter.java) is able to reduce noise while not having a huge impact on delay. It is good to combine this filter with other filters to get an optimal result. + +## Filter Delay -A recently added filter named [Median Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/MedianFilter.java) is able to reduce noise while not having a huge impact on delay. It is good to combine this filter with other filters to get an optimal result. +Delay is the biggest issue with filters. Due to their inability predict the future, it's impossible for it to smooth out values without introducing some amount of delay. We've found that filters that prioritize recent values more than past ones, are able to perform with lower delay whilst maintining impressive filtering performance. -## Which Filter should I use? +## Choosing your filter -Some filters have internal timers in them which keep track of real world time. This is helpful if the data your collecting is real time, and in a time series. When it comes to FRC Robotics, almost all data that we have used filters on is real time. Be sure to read the documentation of certain filters to see which ones use timers in them. +Some filters have internal timers in them which keep track of real world time. This is helpful if the data your collecting is real time, and in a time series. When it comes to FRC robotics, almost all data that we have used filters on is real time. Be sure to read the documentation of certain filters to see which ones use timers in them. -Depending on which type of data you are working with, some filters might be better than others. However, we've found the [LowPass Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java) to be an amazing all around filter, and should be used as a Rule of Thumb when testing out filters. *(meaning that LowPass Filters will usually be the best)* +Depending on which type of data you are working with, some filters might be better than others. However, we've found the [`LowPassFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java) to be an amazing all around filter, and should be used as a Rule of Thumb when testing out filters *(`LowPass` filters will usually be the best)*. -Also, combine filters using [IFilterGroup](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/IFilterGroup.java), as filtering filtered values can often have interesting and desirable results. +Filters can be combined using [`IFilterGroup`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/IFilterGroup.java), as filtering filtered values can often have interesting and desirable results. ## Why do filters take in `Numbers` instead of `double`? -In order to help make filters more configurable, the configuation is done using the Number class. Why? Because [SmartNumber](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartNumber.java) extends `Number`, which makes it extremely easy to change values like the RC of a [LowPass Filter](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java) on the fly. +In order to help make filters more configurable, the configuation is done using the Number class. Why? Because [SmartNumber](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartNumber.java) extends `Number`, which makes it extremely easy to change values, such as the RC of a [`LowPassFilter`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters/LowPassFilter.java), on the fly. diff --git a/src/com/stuypulse/stuylib/streams/readme.md b/src/com/stuypulse/stuylib/streams/readme.md index caab1eec..f60c27dd 100644 --- a/src/com/stuypulse/stuylib/streams/readme.md +++ b/src/com/stuypulse/stuylib/streams/readme.md @@ -1,6 +1,8 @@ # StuyLib Streams Library -## What is a Stream +The Streams library in StuyLib contains streams which return a stream of data. It also contains [filters](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/filters) which can be used to filter through raw input to reduce noise, jitter, input spikes, and jerkiness. + +## What is a stream? A stream is any class / lambda that when you call `.get()` it returns a double. @@ -17,7 +19,7 @@ System.out.println(speed.get()); // Prints the current desired speed By using a stream here, we now have an object we can call / pass around to get the desired speed of the robot. All we would need to do is call `.get()` to recieve the data. -## Why is this useful +## Why is this useful? An [IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/IStream.java) is a useful object to pass around as it represents a constantly updating stream of information. There are things we can do with this stream to get some extra functionality. @@ -33,6 +35,21 @@ IStream filtered_speed = new FilteredIStream(speed, new LowPassFilter(0.5)); System.out.println(filtered_speed.get()); // Prints the filtered value of the stream ``` +### [PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java) + +[PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java) is a very powerful wrapper around an [IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/IStream.java) that polls the underlying `.get()` function a fixed number of times per second. When you call `.get()` on a [PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java), it will return you the last polled value from the underlying stream. + +```java +// Creates an IStream that is updated 50 times a second. +IStream polled_speed = new PollingIStream(speed, 50.0); +``` + +This is useful for streams where the state changes when you call `.get()`. Say you were using reading from [CSVIStream.Reader](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/CSVIStream.java), but you wanted a new value every 50th of a second. By using a PollingIStream, no matter how fast you call `.get()`, you will only ever recieve a new value every 50th of a second. When using a [Filtered IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/FilteredIStream.java) or a [CSVIStream.Reader](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/CSVIStream.java), the value can change when you call `.get()`, so its important to be aware when you poll a stream. + +### [BufferedIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/BufferedIStream.java) + +A [BufferedIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/BufferedIStream.java) is just a wrapper around a normal [IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/IStream.java) that lets you access past values with `.get(delta)`. When stored inside an IStream it acts identically to the original stream, making its usage a bit difficult. + ### [CSVIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/CSVIStream.java) CSVIStream has two child classes in it, `CSVIStream.Writer` and `CSVIStream.Reader`. @@ -56,18 +73,3 @@ System.out.println(file_speed.get()); // The third value of the CSV file. ``` This is useful in general for things like logging or reading CSV files in a streamlined way. - -### [PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java) - -[PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java) is a very powerful wrapper around an [IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/IStream.java) that polls the underlying `.get()` function a fixed number of times per second. When you call `.get()` on a [PollingIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/PollingIStream.java), it will return you the last polled value from the underlying stream. - -```java -// Creates an IStream that is updated 50 times a second. -IStream polled_speed = new PollingIStream(speed, 50.0); -``` - -This is useful for streams where the state changes when you call `.get()`. Say you were using reading from [CSVIStream.Reader](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/CSVIStream.java), but you wanted a new value every 50th of a second. By using a PollingIStream, no matter how fast you call `.get()`, you will only ever recieve a new value every 50th of a second. When using a [Filtered IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/FilteredIStream.java) or a [CSVIStream.Reader](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/CSVIStream.java), the value can change when you call `.get()`, so its important to be aware when you poll a stream. - -### [BufferedIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/BufferedIStream.java) - -A [BufferedIStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/BufferedIStream.java) is just a wrapper around a normal [IStream](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/streams/IStream.java) that lets you access past values with `.get(delta)`. When stored inside an IStream it acts identically to the original stream, making its usage a bit difficult. diff --git a/src/com/stuypulse/stuylib/util/readme.md b/src/com/stuypulse/stuylib/util/readme.md index 9db2b1d2..dd56d10a 100644 --- a/src/com/stuypulse/stuylib/util/readme.md +++ b/src/com/stuypulse/stuylib/util/readme.md @@ -1,3 +1,11 @@ # StuyLib Misc Utils. -WIP... \ No newline at end of file +These miscellaneous utility classes do not fall under any of the other sublibraries and exist as experiments or as classes that are handy to have around. + +### [StopWatch](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/util/StopWatch.java) + +The [StopWatch](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/util/StopWatch.java) class can be used as timers in other classes which depend on intervals of time. + +### [HashBuilder](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/util/HashBuilder.java) + +The [HashBuilder](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/util/HashBuilder.java) class implements various hash manipulation features and exists as an experiment with generating and manipulating hashes. \ No newline at end of file From bf6ba9477ccdf53be8f417c48ba7d8be4a009898 Mon Sep 17 00:00:00 2001 From: anivanchen Date: Tue, 5 Apr 2022 23:50:20 -0400 Subject: [PATCH 12/18] Update limelight README --- .../stuylib/network/limelight/readme.md | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/com/stuypulse/stuylib/network/limelight/readme.md b/src/com/stuypulse/stuylib/network/limelight/readme.md index 927217fd..e735659c 100644 --- a/src/com/stuypulse/stuylib/network/limelight/readme.md +++ b/src/com/stuypulse/stuylib/network/limelight/readme.md @@ -1,3 +1,34 @@ # StuyLib Limelight Library -WIP... \ No newline at end of file +The Limelight Library allows the programmer to interface with the Limelight's network table. It allows for cleaner code which would be used for robot functions such as alignment for shooting or target acquisition. + +### [Limelight](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/limelight/Limelight.java) + +[Limelight](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/limelight/Limelight.java) allows you to check the status of the limelight and get raw data from the limelight, along with data regarding the target, and utilize the returned data in manipulating the robot to align with a target. It also features low level control over the various elements of the Limelight's pipeline such as `LEDMode`. + +Example: To determine the distance of the limelight from the target... + +``` +double targetHeight = 96.0; +double limelightHeight = 38.7; +double limelightPitch = 27.0; +double heightDifference = targetHeight - limelightHeight; + +public static boolean hasAnyTarget() { + return kLimelight.getValidTarget(); +} + +public static Angle getYAngle() { + if (hasAnyTarget()) { + return Angle.fromDegrees(kLimelight.getTargetYAngle() + limelightPitch); + } + return Angle.kZero; +} + +public static double getDistance() { + if (hasAnyTarget()) { + return heightDifference / getYAngle().tan(); + } + return Angle.kZero; +} +``` From cf4f56e9144799c726ef15f144b674e7e184fb42 Mon Sep 17 00:00:00 2001 From: anivanchen Date: Wed, 6 Apr 2022 10:09:27 -0400 Subject: [PATCH 13/18] More READMEs and fix typo --- src/com/stuypulse/stuylib/input/Gamepad.java | 2 +- .../stuylib/input/gamepads/readme.md | 16 ++++++++++++++- .../stuylib/input/keyboard/readme.md | 13 +++++++++++- src/com/stuypulse/stuylib/input/readme.md | 20 +++++++++++++++++-- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/com/stuypulse/stuylib/input/Gamepad.java b/src/com/stuypulse/stuylib/input/Gamepad.java index d87c6a74..4ba3cca2 100644 --- a/src/com/stuypulse/stuylib/input/Gamepad.java +++ b/src/com/stuypulse/stuylib/input/Gamepad.java @@ -11,7 +11,7 @@ import edu.wpi.first.wpilibj2.command.button.Button; /** - * An class for using gamepads with different interfaces. You can implement this class in another + * A class for using gamepads with different interfaces. You can implement this class in another * file, and then use it with a standard interface. * *

Any unimplemented buttons will never be triggered, so if a certain controller is missing one, diff --git a/src/com/stuypulse/stuylib/input/gamepads/readme.md b/src/com/stuypulse/stuylib/input/gamepads/readme.md index 400c0c62..fa3be135 100644 --- a/src/com/stuypulse/stuylib/input/gamepads/readme.md +++ b/src/com/stuypulse/stuylib/input/gamepads/readme.md @@ -1,3 +1,17 @@ # StuyLib Gamepad Implementations -WIP... \ No newline at end of file +Implementations of various gamepads used in FRC robotics + +### AutoGamepad + +### Logitech + +### PS4 + +### Xbox + +### KeyGamepad + +### NetKeyGamepad + +### SimKeyGamepad \ No newline at end of file diff --git a/src/com/stuypulse/stuylib/input/keyboard/readme.md b/src/com/stuypulse/stuylib/input/keyboard/readme.md index 73d6c9b9..f062fefc 100644 --- a/src/com/stuypulse/stuylib/input/keyboard/readme.md +++ b/src/com/stuypulse/stuylib/input/keyboard/readme.md @@ -1,3 +1,14 @@ # StuyLib Network Keyboard -WIP... \ No newline at end of file +### [NetKeyboard](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyboard.java) + +[NetKeyboard](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyboard.java) implements and simplifies interactions with keyboard information through a network table. + +### [NetKeyListener](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyListener.java) + +[NetKeyListener](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyListener.java) listens for and uploads keyboard events to the keyboard network table. + +### [NetKeyWindow](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyWindow.java) + +[NetKeyWindow](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyWindow.java) opens a Java AWT window and simulates a keyboard with a [NetKeyListener](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyListener.java) which can be used to control a robot. + diff --git a/src/com/stuypulse/stuylib/input/readme.md b/src/com/stuypulse/stuylib/input/readme.md index f0cbefe4..cf136ecb 100644 --- a/src/com/stuypulse/stuylib/input/readme.md +++ b/src/com/stuypulse/stuylib/input/readme.md @@ -1,3 +1,19 @@ -# StuyLib Gamepad Library +# StuyLib Input Library -WIP... \ No newline at end of file +The Input library contains classes which simplifies gamepad / keyboard input and standardizes the way input is handled and retrieved. + +To learn about specific gamepads, [read here](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/readme.md). + +To learn about keyboard input, [read here](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/readme.md). + +### [Gamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/Gamepad.java) + +[Gamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/Gamepad.java) is a class which standardizes the gamepad interface. It does not do anything by itself and must be extended by other gamepads. + +### [GamepadState](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/GamepadState.java) + +[GamepadState](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/GamepadState.java) stores the state of a [`Gamepad`](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/Gamepad.java) separated by the different buttons and axis. Yet to be implemented, it can be used to "record" and "play back" gamepad input. + +### [SPIGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/WPIGamepad.java) + +The [SPIGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/WPIGamepad.java) class adds functions which make interactions with WPILib's `Joystick` class simpler. From 6f4414b2ae231b0d728a8603a797a83d7d39b676 Mon Sep 17 00:00:00 2001 From: anivanchen Date: Wed, 6 Apr 2022 14:31:25 -0400 Subject: [PATCH 14/18] MORE READMEs --- .../stuylib/input/gamepads/readme.md | 30 ++++++++++++++----- .../stuylib/input/keyboard/readme.md | 3 +- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/com/stuypulse/stuylib/input/gamepads/readme.md b/src/com/stuypulse/stuylib/input/gamepads/readme.md index fa3be135..4469924f 100644 --- a/src/com/stuypulse/stuylib/input/gamepads/readme.md +++ b/src/com/stuypulse/stuylib/input/gamepads/readme.md @@ -1,17 +1,31 @@ # StuyLib Gamepad Implementations -Implementations of various gamepads used in FRC robotics +Implementations of various gamepads used in FRC robotics. -### AutoGamepad +### [AutoGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) -### Logitech +[AutoGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) detects the gamepad you are using and uses this to determine which gamepad implementation to return for your connected gamepad. It is used to prevent wrong values from being read from your gamepad due to your code believing you are using a different type than the one you are using. -### PS4 +### [Logitech](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) -### Xbox +[Logitech](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) is the implementation of the Logitech gamepad, which has an X and D mode. -### KeyGamepad +### [PS4](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) -### NetKeyGamepad +[PS4](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) is the implementation of the PS4 gamepad. -### SimKeyGamepad \ No newline at end of file +### [Xbox](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) + +[Xbox](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) is the implementation of the Xbox gamepad. + +### [KeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) + +[KeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) manages the keymapping for keyboard gamepads. + +### [NetKeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) + +[NetKeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java)takes in keyboard inputs and maps them to a gamepad to simulate a gamepad, despite using a keyboard as an input medium. + +### [SimKeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) + +[SimKeyGamepad](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/gamepads/AutoGamepad.java) opens a window which accepts keyboard / trackpad inputs within the window and maps them to a gamepad to simulate one. It is meant to be used in the robot simulation and will not work on an actual robot, except the [Romi](https://github.com/StuyPulse/StuyRomi) which utilizes the simulator for control. \ No newline at end of file diff --git a/src/com/stuypulse/stuylib/input/keyboard/readme.md b/src/com/stuypulse/stuylib/input/keyboard/readme.md index f062fefc..aaeffded 100644 --- a/src/com/stuypulse/stuylib/input/keyboard/readme.md +++ b/src/com/stuypulse/stuylib/input/keyboard/readme.md @@ -1,5 +1,7 @@ # StuyLib Network Keyboard +Network keyboards can be used as input devices to trigger commands during testing, especially when running simulations or the [Romi](https://github.com/StuyPulse/StuyRomi). + ### [NetKeyboard](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyboard.java) [NetKeyboard](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyboard.java) implements and simplifies interactions with keyboard information through a network table. @@ -11,4 +13,3 @@ ### [NetKeyWindow](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyWindow.java) [NetKeyWindow](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyWindow.java) opens a Java AWT window and simulates a keyboard with a [NetKeyListener](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/input/keyboard/NetKeyListener.java) which can be used to control a robot. - From ab8ee054d6f66f86e54f05e2f1d121cec9e1e0f8 Mon Sep 17 00:00:00 2001 From: anivanchen Date: Wed, 6 Apr 2022 14:45:05 -0400 Subject: [PATCH 15/18] Start Controls README --- src/com/stuypulse/stuylib/control/readme.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/com/stuypulse/stuylib/control/readme.md b/src/com/stuypulse/stuylib/control/readme.md index a07b58ef..6a2e0c2f 100644 --- a/src/com/stuypulse/stuylib/control/readme.md +++ b/src/com/stuypulse/stuylib/control/readme.md @@ -1,6 +1,20 @@ -# StuyLib Control Algorithms +# StuyLib Control Algorithms Library -WPI... +The Control Algorithms library contains various control algorithms which are commonly used in robotics such as [PID](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDController.java) or [Bang Bang](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/BangBangController.java). They are intuitively programmed and handles the complex mathematics behind each algorithm for the programmer, allowing for beginners to use PID in their control systems. However, it is HIGHLY recommended to have a concrete understanding of what you are using as they require tuning. + +## What is control theory? + + + +### [Controller](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/Controller.java) + +### [BangBangController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/BangBangController.java) + +### [PIDCalculator](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDCalculator.java) + +### [PIDController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDController.java) + +### [TBHController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/TBHController.java) ## Why is `Number` used over `double` From 9a991a951925a2e1c9c6527a1dbf2a09fcd3df46 Mon Sep 17 00:00:00 2001 From: anivanchen Date: Thu, 7 Apr 2022 10:50:44 -0400 Subject: [PATCH 16/18] Update READMEs --- .../stuylib/control/PIDCalculator.java | 2 +- src/com/stuypulse/stuylib/control/readme.md | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/com/stuypulse/stuylib/control/PIDCalculator.java b/src/com/stuypulse/stuylib/control/PIDCalculator.java index a5a63f78..e1367e8b 100644 --- a/src/com/stuypulse/stuylib/control/PIDCalculator.java +++ b/src/com/stuypulse/stuylib/control/PIDCalculator.java @@ -16,7 +16,7 @@ /** * This is a Bang-Bang controller that while controlling the robot, will be able to calculate the * values for the PID controller. It does this by taking the results of oscillations, then creating - * a PIDController withe the correct values once the oscillations have been measured. + * a PIDController with the correct values once the oscillations have been measured. * * @author Sam (sam.belliveau@gmail.com) */ diff --git a/src/com/stuypulse/stuylib/control/readme.md b/src/com/stuypulse/stuylib/control/readme.md index 6a2e0c2f..d9f45737 100644 --- a/src/com/stuypulse/stuylib/control/readme.md +++ b/src/com/stuypulse/stuylib/control/readme.md @@ -4,18 +4,29 @@ The Control Algorithms library contains various control algorithms which are com ## What is control theory? +Control theory is the application of mathematics to predict and analyze the behavior of systems and make them responsive and robust to external forces. We apply control theory to the systems we design to make them meet our expected output and behavioral specifications. +## Why is `Number` used over `double` + +This is to allow for the use of [SmartNumber](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartNumber.java), which extends `Number`. This makes things like configuring PID values significantly easier, as they can be instantly hooked into SmartDashboard without any configuration. ### [Controller](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/Controller.java) +The [Controller](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/Controller.java) abstract class is used to create controllers and includes functions which makes controller implementations easier. + ### [BangBangController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/BangBangController.java) + + + ### [PIDCalculator](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDCalculator.java) +[PIDCalculator](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDCalculator.java) is a Bang-Bang controller which can be used to calculate the values for the [PIDController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDController.java). It creates a [PIDController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDController.java) with correct values as oscillations occur. + ### [PIDController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDController.java) -### [TBHController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/TBHController.java) +[PIDController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDController.java) is an implementation of a PID controller. Our implementation features an intergral reset every time the error reaches 0 to prevevnt integral lag. Setups involving rate may not be suitable for this controller. -## Why is `Number` used over `double` +### [TBHController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/TBHController.java) -This is to allow for the use of [SmartNumber](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartNumber.java), which extends `Number`. This makes things like configuring PID values significantly easier, as they can be instantly hooked into SmartDashboard without any configuration. \ No newline at end of file +A "take back half" controller which increases the speed until it goes over the reference, then decreases the speed by half and repeats the process. From 358cdb90e4b15e4a5982258ea3817a7aef9e9142 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 7 Apr 2022 10:52:58 -0400 Subject: [PATCH 17/18] Update readme.md --- src/com/stuypulse/stuylib/control/readme.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/com/stuypulse/stuylib/control/readme.md b/src/com/stuypulse/stuylib/control/readme.md index 6a2e0c2f..d9f45737 100644 --- a/src/com/stuypulse/stuylib/control/readme.md +++ b/src/com/stuypulse/stuylib/control/readme.md @@ -4,18 +4,29 @@ The Control Algorithms library contains various control algorithms which are com ## What is control theory? +Control theory is the application of mathematics to predict and analyze the behavior of systems and make them responsive and robust to external forces. We apply control theory to the systems we design to make them meet our expected output and behavioral specifications. +## Why is `Number` used over `double` + +This is to allow for the use of [SmartNumber](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartNumber.java), which extends `Number`. This makes things like configuring PID values significantly easier, as they can be instantly hooked into SmartDashboard without any configuration. ### [Controller](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/Controller.java) +The [Controller](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/Controller.java) abstract class is used to create controllers and includes functions which makes controller implementations easier. + ### [BangBangController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/BangBangController.java) + + + ### [PIDCalculator](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDCalculator.java) +[PIDCalculator](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDCalculator.java) is a Bang-Bang controller which can be used to calculate the values for the [PIDController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDController.java). It creates a [PIDController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDController.java) with correct values as oscillations occur. + ### [PIDController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDController.java) -### [TBHController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/TBHController.java) +[PIDController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDController.java) is an implementation of a PID controller. Our implementation features an intergral reset every time the error reaches 0 to prevevnt integral lag. Setups involving rate may not be suitable for this controller. -## Why is `Number` used over `double` +### [TBHController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/TBHController.java) -This is to allow for the use of [SmartNumber](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/network/SmartNumber.java), which extends `Number`. This makes things like configuring PID values significantly easier, as they can be instantly hooked into SmartDashboard without any configuration. \ No newline at end of file +A "take back half" controller which increases the speed until it goes over the reference, then decreases the speed by half and repeats the process. From 8be77bcdaa116c17b2a4e3ddf04043581ffa2f49 Mon Sep 17 00:00:00 2001 From: anivanchen Date: Thu, 7 Apr 2022 23:13:31 -0400 Subject: [PATCH 18/18] Update control readme --- src/com/stuypulse/stuylib/control/readme.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/com/stuypulse/stuylib/control/readme.md b/src/com/stuypulse/stuylib/control/readme.md index d9f45737..616acedd 100644 --- a/src/com/stuypulse/stuylib/control/readme.md +++ b/src/com/stuypulse/stuylib/control/readme.md @@ -16,8 +16,7 @@ The [Controller](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypuls ### [BangBangController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/BangBangController.java) - - +A [BangBangController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/BangBangController.java) goes forward at full force when the error is positive and backwards at full force when the error is negative. ### [PIDCalculator](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/PIDCalculator.java) @@ -29,4 +28,4 @@ The [Controller](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypuls ### [TBHController](https://github.com/StuyPulse/StuyLib/blob/main/src/com/stuypulse/stuylib/control/TBHController.java) -A "take back half" controller which increases the speed until it goes over the reference, then decreases the speed by half and repeats the process. +A "take back half" controller which increases the speed until it goes over the reference, then decreases the speed by half and repeats the process until the error reaches 0.