Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open a test file for claw and learn how to use the debugger! #1

Open
wants to merge 2 commits into
base: dm/makeclaw
Choose a base branch
from

Conversation

ZacharyEagan
Copy link

This PR introduces the concept of unit testing robot sub-modules, Utilizing the debugger, and reviewing PRs.

Unit tests are a handy tool to help write better code faster and with greater confidence. Unit tests provide the following benefits:

  1. They provide True documentation of code behaviors. While a comment may get out of date or be inaccurate, a unit test will simply fail if it does not express the true operation of the code.
  2. They provide an easy way to view small chunks of robot code in action in a safe environment (See debugging below) This allows anyone to get started programming with, or without a robot
  3. They provide a second 'user' of a piece of code promoting better defined interfaces, you might be able to write a messy function for the robot but now try writing a test for it.
  4. For more benefits check out the keywords: 'clean code', 'test driven development'

Using the debugger: I'll give a demo of this tomorrow, but the debugger allows you to step through your code as it executes, one line at a time. You can even look at the values of variables!

Reviewing PRs: If you're reading this then you're already well on your way, now try finding something you don't like or have a question about in the source files I changed. Leave a comment, ask a question or request some changes!

Copy link

sweep-ai bot commented Nov 2, 2023

Apply Sweep Rules to your PR?

  • Apply: Leftover TODOs in the code should be handled.
  • Apply: All new business logic should have corresponding unit tests in the tests/ directory.
  • Apply: Any clearly inefficient or repeated code should be optimized or refactored.

Comment on lines +16 to +30
override fun periodic() {
super.periodic()
val presentSpeed = motor.get()

val presentSpeedIsCloseToDesiredSpeedLow : Boolean = ( (desiredSpeed - 0.01) <= presentSpeed )
val presentSpeedIsCloseToDesiredSpeedHigh : Boolean = ( (desiredSpeed + 0.01) >= presentSpeed )
val presentSpeedIsCloseToDesiredSpeed : Boolean = presentSpeedIsCloseToDesiredSpeedHigh && presentSpeedIsCloseToDesiredSpeedLow

if ( false == presentSpeedIsCloseToDesiredSpeed ) {
motor.set(presentSpeed + speedIncrementPerCycle)
} else {
speedIncrementPerCycle = 0.0
}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code should be in the command

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it doesn't have to speed up you can just set the speed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants