An unexpected output of TalonSRX in Swerve

Our team is trying to use TalonSRX as our swerve’s turning motor. As the chief coder in my team, when l simulate my swerve , it seems that the output of TalonSRX is so good. When l push my rotation axis ( The right axis of my XboxController ) , the output of TalonSRX fluctuates. And also it seems that when l didn’t use the XboxController , the output of both drive motor and turning motor can’t return to 0 . l have already set the deadzone to 0.075 . l think it is enough.

Any answer is appreciated.

Hi @mendax1234! I first want to say I really appreciate you enthusiasm to learn! Having seen the multiple threads you’ve been asking about have been pretty insightful.

You may want to consider changing the thread title to more appropriately address the problem you are having. I read the title “The problem when using TalonSRX in Swerve” and presumed you were saying there was some fundamental issue CTRE had to fix or Swerve and Talons wouldn’t play nicely. Being able to have a clear title explaining your issue will not only help the right people find you, but all help others with similar issues in the future!

Keep up the great work!
(Unfortunately I don’t know about your problem, but I thought I would chime in)

So generally, I like to frame questions in this format:

  • In theory, when I perform a set of actions, I expect a particular result.
  • In practice, when I actually perform those actions, I observe a different result.
  • Why do expected and actual results not match?

Looking at your post, here’s what I’m parsing out of it:

  • When code is run in simulation, when zero joystick commands are given, you expect zero motor commands.
  • However, when you run your code in simulation, when zero joystick commands are given, you observe nonzero motor commands.
  • Why are the motor commands nonzero, instead of zero?

For context, for others looking here, in the provided .zip file, I do not see any modeling of azimuth motor/gearbox/encoder behavior. Code appears to be running “open-loop”.

@mendax1234 - can you confirm I’ve accurately summarized your situation and question?

PS: Soapbox Speech

The English language absolutely sucks.

It’s evolved and borrowed from tons of different languages, has no standardized body to keep its rules contained, has been morphed and adapted by tons of cultures worldwide. Add in sundry cultural influences that make it hard for people to admit lack of knowledge, or say “no” to things… English communication is really hard.

Both personally and professionally, I’ve basically decided that grammar doesn’t matter. It’s so rare to met a person who wasn’t trying their absolute best to get their point across, I will always start with that assumption. Just because the other person doesn’t parse or organize words the same way I do doesn’t mean there isn’t solid, intelligent, well-ordered thought in their mind.

What I do push for a lot, especially in technical communication: Careful application of vocabulary and organization of thoughts.

For one, be careful and deliberate when choosing words, especially technical ones (ex: “Voltage”). The fewer assumptions or guesses the audience has to make on your technical facts, the better. Use pictures or descriptions if needed, and don’t be afraid to admit when a term is unfamiliar or ambiguous to you.

For organization: I love bulleted lists.

  1. use numbered lists to indicate events that flow with time.
  2. Presumably, this thing happened after the first item in the list.

While English does have grammatical constructs to indicate the flow of time (“in the past”, “first”, “then”, “later”, “eventually”), these tend to be very nuanced and not easily applied (especially if your native language doesn’t have a similar tense system to English).

  • Use unordered lists to indicate facts or events that should be all considered simultaneously.
  • Presumably, this thing has no “time relation” to the first item in the list.

Yes , that is true! l want to make a video to better explain my issue , but it seems that l can’t insert it in this thread.

l use PIDController when calculating the output of drive and turning swerve.

Thanks for your advice , l will try to avoid this ambiguity.

1 Like

So when I say “closed loop” versus “open loop”, here’s what I’m describing:

On the real robot, your code is designed to interact with the hardware in a fashion similar to this:

The electronics and hardware influence each other in a way which forms (literally) a closed loop of information. The code outputs (motor commands) are indeed connected back to the inputs (sensor readings).

Of course, the connection isn’t direct, and there’s no lines of code for it. But, indirectly, they are connected.

However, when you run in simulation, the picture looks more like this:

Here, there is no connection at all from the software outputs to the software inputs. No direct or indirect connection. The code is now running in an “open loop” fashion.

For any closed-loop controller (PID included) to function “normally”, it is assumed that some relationship exists between its outputs and its inputs. In simulation, this would not be the case.

I know this doesn’t quite directly answer your question… but hopefully it starts you down a path of resolving the difference between what you expect, and what you see?

Yeah, a really helpful solution.

  • However , in the simulation , the output of Talon FX seems to be more stable the the output of TalonSRX.

  • Another question is , my xboxcontroller 's value is below my deadzone . However , the output of the motor is not zero . Is there something wrong with my code? ( I think the problem areas have been flagged)

  • About the question about the output of Talon SRX , l guess that the direction of zero vector is random , but l don’t know whether has combine this into WPILIb?