Giter VIP home page Giter VIP logo

yagsl-example's Introduction

Yet Another Generic Swerve Library (YAGSL) Example project

YAGSL is intended to be an easy implementation of a generic swerve drive that should work for most square swerve drives. The project is documented on here. The JSON documentation can also be found here

This example is intended to be a starting place on how to use YAGSL. By no means is this intended to be the base of your robot project. YAGSL provides an easy way to generate a SwerveDrive which can be used in both TimedRobot and Command-Based Robot templates.

Overview

Installation

Vendor URL:

https://broncbotz3481.github.io/YAGSL-Lib/yagsl/yagsl.json

Javadocs here
Library here
Code here
WIKI
Config Generation

Create an issue if there is any errors you find!

We will be actively montoring this and fix any issues when we can!

Development

  • Development happens here on YAGSL-Example. YAGSL and YAGSL-Lib are updated on a nightly basis.

Support our developers!

Buy Me a Robot at ko-fi.com

TL;DR Generate and download your configuration here and unzip it so that it follows structure below:

deploy
└── swerve
    ├── controllerproperties.json
    ├── modules
    │   ├── backleft.json
    │   ├── backright.json
    │   ├── frontleft.json
    │   ├── frontright.json
    │   ├── physicalproperties.json
    │   └── pidfproperties.json
    └── swervedrive.json

Then create your SwerveDrive object like this.

import java.io.File;
import edu.wpi.first.wpilibj.Filesystem;
import swervelib.parser.SwerveParser;
import swervelib.SwerveDrive;
import edu.wpi.first.math.util.Units;


SwerveDrive swerveDrive=new SwerveParser(new File(Filesystem.getDeployDirectory(),"swerve")).createSwerveDrive(Units.feetToMeters(14.5));

Migrating Old Configuration Files

  1. Delete wheelDiamter, gearRatio, encoderPulsePerRotation from physicalproperties.json
  2. Add optimalVoltage to physicalproperties.json
  3. Delete maxSpeed and optimalVoltage from swervedrive.json
  4. IF a swerve module doesn't have the same drive motor or steering motor as the rest of the swerve drive you MUST specify a conversionFactor for BOTH the drive and steering motor in the modules configuration JSON file. IF one of the motors is the same as the rest of the swerve drive and you want to use that conversionFactor, set the conversionFactor in the module JSON configuration to 0.
  5. You MUST specify the maximum speed when creating a SwerveDrive through new SwerveParser(directory).createSwerveDrive(maximumSpeed);
  6. IF you do not want to set conversionFactor in swervedrive.json. You can pass it into the constructor as a parameter like this
double DriveConversionFactor = SwerveMath.calculateMetersPerRotation(Units.inchesToMeters(WHEEL_DIAMETER), GEAR_RATIO, ENCODER_RESOLUTION);
double SteeringConversionFactor = SwerveMath.calculateDegreesPerSteeringRotation(GEAR_RATIO, ENCODER_RESOLUTION);
SwerveDrive swerveDrive = new SwerveParser(directory).createSwerveDrive(maximumSpeed, SteeringConversionFactor, DriveConversionFactor);

Falcon Support would not have been possible without support from Team 1466 Webb Robotics!

Configuration Tips

My Robot Spins around uncontrollably during autonomous or when attempting to set the heading!

  • Invert the gyro scope.
  • Invert the drive motors for every module. (If front and back become reversed when turning)

Angle motors are erratic.

  • Invert the angle motor.

My robot is heavy.

  • Implement momentum velocity limitations in SwerveMath.

Ensure the IMU is centered on the robot

Maintainers

  • @thenetworkgrinch
  • @Technologyman00

Special Thanks to Team 7900! Trial N' Terror

Without the debugging and aid of Team 7900 the project could never be as stable or active as it is.

yagsl-example's People

Contributors

5010tigerdynasty avatar 7910f6ba7ee4 avatar ajs256 avatar balien-12 avatar clrozeboom avatar dezash123 avatar dylan-watson avatar flint221 avatar garrettsummerfi3ld avatar geraldtm avatar guineawheek avatar josephtlockwood avatar jwbonner avatar marshalltappen avatar robopenguin7 avatar technologyman00 avatar thegamer1002 avatar thenetworkgrinch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

yagsl-example's Issues

Add Overridable Settings.

Modules should be able to override the following settings.

  • Encoder pulse per revolution.
  • Free speed RPM.

Cache Sensor Data

Within reason sensor data is not updated as often as we query it. Therefore if sensor data is queries within a timeframe we return the cached data. Caching would occur in Abstracted classes and result in lower CANBus usage. Possible method of doing this would be creating a counter in SwerveDriveTelemetry.

Extend Rotation2d

Rotation2d needs to store the original unoptimized angle it was instantiated with to determine the given angle from the absolute encoders

(note: This will NEVER work with thrifty encoders or those which cant exceed 360deg)

v2 Json Generator issues

There are a few issues with the v2 Json Generator as it stands with the current version of the library

In all instances of 'absoluteEncoderOffset', there is a typo that generates the json as 'absolueEncoderOffset' (missing the t in absolute)

In module properties, the json entry 'freespeedrpm' doesn't exist, can only be 'angleMotorFreeSpeedRPM' according to the build error when I try to build

In all modules, when inverting, it prepends the module name (frontleft, backright, etc) to the angle or motor line, reading backleftangle. The build error indicates the only acceptable fields to be angle and drive, so the frontleft, etc need to be removed. I didn't test to see if it worked with encoders being inverted, but it didn't say that they were an option when I was viewing the stacktrace.

And thats all I noticed with my program. Don't have a robot to test on now, but when I made these three changes to my json files, it built and ran a simulation!

Support "X" mode

X mode is where the modules go into 45 degree angles making it immobile which could be useful for protecting against defense.

Change `fscalar` to `ks`

fscalar in the JSON config is ks and following some normalized documentation should be preferred.

Deferring to @7910f6ba7ee4 since this is a major design change to a function used by them (and apparently all other falcon teams).

Address heading drift

Track the desired position of the robot and control the heading exclusively by that.

Rename X and Y

X refers to front in module locations and Y refers to left. Should we rename this to front and left respectively to make it less confusing?

This would be a breaking change but it could be worth it.

Add 2nd Order Kinematics Taking into account chassis acceleration.

The current second order kinematics only uses omega squared, the angular speed of the robot in the calculations. This means that physically, the kinematics only produce the intended result when the robot is already spinning, then moves translationally. When the robot starts spinning and moving at the same time, it does not go straight.

The acceleration vector line should be updated to include a rough approximation of:

  • angular acceleration
  • translational acceleration in x
  • translational acceleration in y

This can probably be approximated just simply using a timer to find the change over timestep per iteration, storing the past chassis speeds inside of the kinematics class.

https://github.com/BroncBotz3481/YAGSL-Example/tree/52-add-2nd-order-kinematics-taking-into-account-chassis-acceleration is the linked branch.

Document TimedRobot base class dependency and support AdvantageKit LoggedRobot

Presently, swervelib has several modules that call Robot.getInstance().addPeriodic() to set up periodic operations:

  • SwerveModule.java
  • encoders/PWMAnalogEncoder.java
  • encoders/PWMDutyCycleEncoder.java

The use of addPeriodic() implicitly creates a dependency on Robot being a subclass of edu.wpi.first.wpilibj.TimedRobot. However, this is not the case when using the AdvantageKit library from FRC 6328 for logging and log playback. AdvantageKit requires the use of a LoggedRobot base class, which does not supply the addPeriodic functionality.

Minimally, the dependency on TimedRobot should be documented.

For cases where LoggedRobot is being used as the robot base class, it is suggested that a Timer (edu.wpi.first.wpilibj.Timer) or similar class be used in a swerve subsystem to provide periodic callbacks to swerve components.

Steering Issues

          i fixed the positions and used the pre tried config options but now im haveing an issue were the robot will not turn correcctly as both sticks seem to drive until both are operated at the same time were they then seem to steer

Originally posted by @aidenm05 in #37 (comment)

Abstract Kinematics

Add enum to select kinematics to SwerveDrive constructor and abstract kinematics to select which one to use.
Steps:

  • Remove 2nd order kinematics
  • Add first order kinematics
  • Abstract first order kinematics
  • Implement 2nd order kinematics
  • Add enum to select which kinematics to use.

Strafing on a 45 is about half speed.

HI, love the library, only having one issue, when I try and tele-op drive on a 45, so a combination of X and Y with no rotation, the robot moves at about half the absolute speed compared to when only moving in the X and Y.

Any ideas?

@thenetworkgrinch

LockPose not working.

The lockPose() method does not work because it commands module states that have a speed of 0. In the setModuleStates() method, there are a few lines put into place to stop angle movement when speeds are less than 0.1.

Since the lines that stop module angular movement are useful in stopping excessive module movement in place, the lockPose() function should probably be updated, possibly using an overload with setModuleStates().

https://github.com/BroncBotz3481/YAGSL-Example/tree/51-lockpose-not-working is the linked branch for the issue.

FAQ

If the robot spins out of control in autonomous or teleop absolute drive the gyro is inverted.

Fix CANCoder Synchronization

https://www.chiefdelphi.com/t/yet-another-generic-swerve-library-yagsl-beta/425148/159
https://www.chiefdelphi.com/t/yet-another-generic-swerve-library-yagsl-beta/425148/117
Appear to have issues with what is believed to be the cancoder sync.

Possible causes of issues:

  • getAbsolutePosition() not being constrained to (0, 360) because of the offset
  • the synchronizeEncoders() is placed in the periodic updateOdometry() which means a lack of causality with setReference(). Because of the PID loop running on the motor, with the setpoint derived from the past motor measurements and a new measurement, this could cause some unexpected temporary behavior.

It also could be easier to implement a Steer and Drive Controller to wrap the absolute encoder like democat's swervelib. This would match what they do, which is known to work.

Rewrite to Model 95s code

  • Rearrange code into single package.
  • Separate SwerveDrive, SwerveModule, and SwerveController configuration options from Constants.
  • Adopt store configuration at construction style instead of global referencing.
  • Implement SwerveMotor augmentation for SwerveModule.
  • Implement AbsoluteEncoder augmentation for SwerveModule.
  • Separate SwerveModule constants from SwerveMotor constants.
  • Add on state-space estimation.
  • Move helper functions into SwerveMath.
  • Document every function.
  • Separate functions into correct units.
  • Extrapolate calculated constants into Configuration classes for SwerveDrive, SwerveModule, and SwerveMotor.
  • Add support for integrated absolute encoders.
  • Add support for defining PID output ranges.
  • Switch Odometry to SwervePoseEstimator.
  • Make certain configs optional (maybe)
  • Write documentation for JSON.

Single wheel driving upon telleop

hi, I'm having an issue where when I start Telyop using the example with all falcons one motor just drives at max speed and when I do autonomous autonomous program goes through and then at the end of it, one motor drives at max speed I've tried unplugging the motor that was driving at max speed and then it just switch to the next drive motor, I've also tried choosing different field configurations like closed field oriented in such get nothing. Any help would be greatly appreciated because I really really like this project.

Remove `fscalar` as a config option?

With the voltage scaling fix for talon motors, everything seems to work as expected, suggesting that a scalar for the feedforward is not needed. Should we remove this option now that the theoretical feedforward works as expected?

Fix TalonFX ArbitraryFeedforward (uses percentage output not voltage)

The ArbitraryFeedforward in the set() method for TalonFX motors takes in an input of percentage output from (-1, 1). The current assumption was that it takes in voltage. This should be fixed by just dividing the input of the setReference() method by the nominal voltage (and storing a local nominal voltage to do so).

Fix Wording for Encoder

Encoder pulse per rotation is not for "non-integrated encoders" only, it is the total pulses for the motor controller encoders, which is 2048 for falcons

Add custom standard deviation version of addVisionMeasurement

While the current version of the method has trustworthiness, it would be beneficial if a completely custom set of standard deviations could be supplied. We are calculating these values in a custom way based on having both photonvision and limelight, and it would be useful to have the ability to pass in these custom standard deviations.

Investigate Odometry Inversion

When the drive motors are inverted for a Falcon/Falcon/CANCoder setup the odometry is completely reversed as if the sensor readings are not setting inversion states. If this is the case inversion needs to be changed to a psuedo-inverrsion or sensor readings need to be corrected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.