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

Update with WPILib stuff #1

Merged
merged 25 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d640c0f
[wpimath] Fix pose estimator local measurement standard deviation doc…
calcmogul Mar 20, 2022
d0fef18
[wpimath] Remove redundant `this.` from ExtendedKalmanFilter.java (#4…
calcmogul Mar 20, 2022
d5cb6fe
[wpimath] Support zero cost entries in MakeCostMatrix() (#4100)
calcmogul Mar 20, 2022
95ae23b
[wpimath] Improve EKF numerical stability (#4093)
calcmogul Mar 20, 2022
89ffcbb
[wpimath] Update TrapezoidProfile class name in comment (NFC) (#4107)
calcmogul Mar 20, 2022
765efa3
[wpimath] Remove redundant column index from vectors (#4116)
calcmogul Mar 20, 2022
0d70884
[wpimath] Add InterpolatedTreeMap (#4073)
Ashray-g Mar 20, 2022
cdafc72
[examples] Remove unused LinearPlantInversionFeedforward includes (#4…
calcmogul Mar 20, 2022
78108c2
[wpimath] Fix PIDController having incorrect error after calling SetS…
calcmogul Mar 20, 2022
8d79dc8
[wpimath] Add ImplicitModelFollower (#4056)
calcmogul Mar 20, 2022
e1b6e5f
[wpilib] Improve MotorSafety documentation (NFC) (#4120)
sciencewhiz Mar 21, 2022
ba0dcca
[wpimath] Fix reference to Rotation2d.fromRadians() (#4118)
calcmogul Mar 21, 2022
126e3de
[wpilibc] Remove unused SetPriority() call from Ultrasonic (#4123)
calcmogul Mar 24, 2022
069f932
[build] Fix gl3w cmake build (#4139)
PeterJohnson Mar 29, 2022
2e462a1
[wpimath] Constexprify units unary operators (#4138)
calcmogul Mar 29, 2022
b4620f0
[wpimath] Fix Rotation2d interpolation in Java (#4125)
calcmogul Mar 29, 2022
c8905ec
[wpimath] Remove ImplicitModelFollower dt argument (#4119)
calcmogul Mar 29, 2022
9650e67
[wpiutil] DataLog: Document finish and thread safety (NFC) (#4140)
PeterJohnson Mar 29, 2022
81c5b41
[wpilibj] Document MechanismLigament2d angle unit (NFC) (#4142)
calcmogul Mar 31, 2022
88222da
[hal] Fix misspelling in AnalogInput/Output docs (NFC) (#4153)
apppppppple Apr 8, 2022
1b26e2d
[commands] Add RepeatCommand (#4009)
ExcaliburFRC6738 Apr 8, 2022
f27a1f9
[commands] Fix JoystickButton.getAsBoolean (#4131)
ohowe1 Apr 9, 2022
5bf46a9
[wpimath] Add ComputerVisionUtil (#4124)
calcmogul Apr 9, 2022
9751716
[wpilib] Compressor: Rename enabled to isEnabled (#4147)
yeSpud Apr 9, 2022
aef4b16
[wpimath] Remove unnecessary NOLINT in LinearPlantInversionFeedforwar…
calcmogul Apr 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hal/src/main/native/include/hal/AnalogInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analogPortHandle);
HAL_Bool HAL_CheckAnalogModule(int32_t module);

/**
* Checks that the analog output channel number is value.
* Checks that the analog output channel number is valid.
* Verifies that the analog channel number is one of the legal channel numbers.
* Channel numbers are 0-based.
*
Expand Down
2 changes: 1 addition & 1 deletion hal/src/main/native/include/hal/AnalogOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ double HAL_GetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
int32_t* status);

/**
* Checks that the analog output channel number is value.
* Checks that the analog output channel number is valid.
*
* Verifies that the analog channel number is one of the legal channel numbers.
* Channel numbers are 0-based.
Expand Down
2 changes: 1 addition & 1 deletion imgui/CMakeLists.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ExternalProject_Add(glfw3
)
ExternalProject_Add(gl3w
GIT_REPOSITORY https://github.com/skaslev/gl3w
GIT_TAG 3755745085ac2e865fd22270cfe9169c26640f70
GIT_TAG 5f8d7fd191ba22ff2b60c1106d7135bb9a335533
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/gl3w-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/gl3w-build"
INSTALL_COMMAND ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,22 @@ default PerpetualCommand perpetually() {
return new PerpetualCommand(this);
}

/**
* Decorates this command to run repeatedly, restarting it when it ends, until this command is
* interrupted. The decorated command can still be canceled.
*
* <p>Note: This decorator works by composing this command within a CommandGroup. The command
* cannot be used independently after being decorated, or be re-decorated with a different
* decorator, unless it is manually cleared from the list of grouped commands with {@link
* CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be further
* decorated without issue.
*
* @return the decorated command
*/
default RepeatCommand repeat() {
return new RepeatCommand(this);
}

/**
* Decorates this command to run "by proxy" by wrapping it in a {@link ProxyScheduleCommand}. This
* is useful for "forking off" from command groups when the user does not wish to extend the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package edu.wpi.first.wpilibj2.command;

import static edu.wpi.first.wpilibj2.command.CommandGroupBase.registerGroupedCommands;
import static edu.wpi.first.wpilibj2.command.CommandGroupBase.requireUngrouped;

/**
* A command that runs another command repeatedly, restarting it when it ends, until this command is
* interrupted. While this class does not extend {@link CommandGroupBase}, it is still considered a
* CommandGroup, as it allows one to compose another command within it; the command instances that
* are passed to it cannot be added to any other groups, or scheduled individually.
*
* <p>As a rule, CommandGroups require the union of the requirements of their component commands.
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class RepeatCommand extends CommandBase {
protected final Command m_command;

/**
* Creates a new RepeatCommand. Will run another command repeatedly, restarting it whenever it
* ends, until this command is interrupted.
*
* @param command the command to run repeatedly
*/
public RepeatCommand(Command command) {
requireUngrouped(command);
registerGroupedCommands(command);
m_command = command;
m_requirements.addAll(command.getRequirements());
}

@Override
public void initialize() {
m_command.initialize();
}

@Override
public void execute() {
m_command.execute();
if (m_command.isFinished()) {
// restart command
m_command.end(false);
m_command.initialize();
}
}

@Override
public boolean isFinished() {
return false;
}

@Override
public void end(boolean interrupted) {
m_command.end(interrupted);
}

@Override
public boolean runsWhenDisabled() {
return m_command.runsWhenDisabled();
}

@Override
public RepeatCommand repeat() {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Trigger() {
* @return whether or not the trigger condition is active.
*/
public boolean get() {
return this.getAsBoolean();
return m_isActive.getAsBoolean();
}

/**
Expand All @@ -69,8 +69,8 @@ public boolean get() {
* @return whether or not the trigger condition is active.
*/
@Override
public boolean getAsBoolean() {
return m_isActive.getAsBoolean();
public final boolean getAsBoolean() {
return this.get();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "frc2/command/ParallelRaceGroup.h"
#include "frc2/command/PerpetualCommand.h"
#include "frc2/command/ProxyScheduleCommand.h"
#include "frc2/command/RepeatCommand.h"
#include "frc2/command/SequentialCommandGroup.h"
#include "frc2/command/WaitCommand.h"
#include "frc2/command/WaitUntilCommand.h"
Expand Down Expand Up @@ -87,6 +88,10 @@ PerpetualCommand Command::Perpetually() && {
return PerpetualCommand(std::move(*this).TransferOwnership());
}

RepeatCommand Command::Repeat() && {
return RepeatCommand(std::move(*this).TransferOwnership());
}

ProxyScheduleCommand Command::AsProxy() {
return ProxyScheduleCommand(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#include "frc2/command/RepeatCommand.h"

using namespace frc2;

RepeatCommand::RepeatCommand(std::unique_ptr<Command>&& command) {
if (!CommandGroupBase::RequireUngrouped(*command)) {
return;
}
m_command = std::move(command);
m_command->SetGrouped(true);
AddRequirements(m_command->GetRequirements());
}

void RepeatCommand::Initialize() {
m_command->Initialize();
}

void RepeatCommand::Execute() {
m_command->Execute();
if (m_command->IsFinished()) {
// restart command
m_command->End(false);
m_command->Initialize();
}
}

bool RepeatCommand::IsFinished() {
return false;
}

void RepeatCommand::End(bool interrupted) {
m_command->End(interrupted);
}

bool RepeatCommand::RunsWhenDisabled() const {
return m_command->RunsWhenDisabled();
}

RepeatCommand RepeatCommand::Repeat() && {
return std::move(*this);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ParallelDeadlineGroup;
class SequentialCommandGroup;
class PerpetualCommand;
class ProxyScheduleCommand;
class RepeatCommand;

/**
* A state machine representing a complete action to be performed by the robot.
Expand Down Expand Up @@ -185,6 +186,14 @@ class Command {
*/
virtual PerpetualCommand Perpetually() &&;

/**
* Decorates this command to run repeatedly, restarting it when it ends, until
* this command is interrupted. The decorated command can still be canceled.
*
* @return the decorated command
*/
virtual RepeatCommand Repeat() &&;

/**
* Decorates this command to run "by proxy" by wrapping it in a
* ProxyScheduleCommand. This is useful for "forking off" from command groups
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#pragma once

#ifdef _WIN32
#pragma warning(push)
#pragma warning(disable : 4521)
#endif

#include <memory>
#include <utility>

#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandGroupBase.h"
#include "frc2/command/CommandHelper.h"

namespace frc2 {
/**
* A command that runs another command repeatedly, restarting it when it ends,
* until this command is interrupted. While this class does not extend {@link
* CommandGroupBase}, it is still considered a CommandGroup, as it allows one to
* compose another command within it; the command instances that are passed to
* it cannot be added to any other groups, or scheduled individually.
*
* <p>As a rule, CommandGroups require the union of the requirements of their
* component commands.
*
* <p>This class is provided by the NewCommands VendorDep
*/
class RepeatCommand : public CommandHelper<CommandBase, RepeatCommand> {
public:
/**
* Creates a new RepeatCommand. Will run another command repeatedly,
* restarting it whenever it ends, until this command is interrupted.
*
* @param command the command to run repeatedly
*/
explicit RepeatCommand(std::unique_ptr<Command>&& command);

/**
* Creates a new RepeatCommand. Will run another command repeatedly,
* restarting it whenever it ends, until this command is interrupted.
*
* @param command the command to run repeatedly
*/
template <class T, typename = std::enable_if_t<std::is_base_of_v<
Command, std::remove_reference_t<T>>>>
explicit RepeatCommand(T&& command)
: RepeatCommand(std::make_unique<std::remove_reference_t<T>>(
std::forward<T>(command))) {}

RepeatCommand(RepeatCommand&& other) = default;

// No copy constructors for command groups
RepeatCommand(const RepeatCommand& other) = delete;

// Prevent template expansion from emulating copy ctor
RepeatCommand(RepeatCommand&) = delete;

void Initialize() override;

void Execute() override;

bool IsFinished() override;

void End(bool interrupted) override;

bool RunsWhenDisabled() const override;

RepeatCommand Repeat() && override;

private:
std::unique_ptr<Command> m_command;
};
} // namespace frc2

#ifdef _WIN32
#pragma warning(pop)
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package edu.wpi.first.wpilibj2.command;

import static org.junit.jupiter.api.Assertions.assertEquals;

import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.simulation.DriverStationSim;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;

class RepeatCommandTest {
@Test
void callsMethodsCorrectly() {
HAL.initialize(500, 0);
// enable so that we don't need to mess with `runsWhenDisabled` for each command
DriverStationSim.setEnabled(true);

var initCounter = new AtomicInteger(0);
var exeCounter = new AtomicInteger(0);
var isFinishedCounter = new AtomicInteger(0);
var endCounter = new AtomicInteger(0);
var isFinishedHook = new AtomicBoolean(false);

final var command =
new RepeatCommand(
new FunctionalCommand(
initCounter::incrementAndGet,
exeCounter::incrementAndGet,
interrupted -> endCounter.incrementAndGet(),
() -> {
isFinishedCounter.incrementAndGet();
return isFinishedHook.get();
}));

assertEquals(0, initCounter.get());
assertEquals(0, exeCounter.get());
assertEquals(0, isFinishedCounter.get());
assertEquals(0, endCounter.get());

CommandScheduler.getInstance().schedule(command);
assertEquals(1, initCounter.get());
assertEquals(0, exeCounter.get());
assertEquals(0, isFinishedCounter.get());
assertEquals(0, endCounter.get());

isFinishedHook.set(false);
CommandScheduler.getInstance().run();
assertEquals(1, initCounter.get());
assertEquals(1, exeCounter.get());
assertEquals(1, isFinishedCounter.get());
assertEquals(0, endCounter.get());

isFinishedHook.set(true);
CommandScheduler.getInstance().run();
assertEquals(2, initCounter.get());
assertEquals(2, exeCounter.get());
assertEquals(2, isFinishedCounter.get());
assertEquals(1, endCounter.get());

isFinishedHook.set(false);
CommandScheduler.getInstance().run();
assertEquals(2, initCounter.get());
assertEquals(3, exeCounter.get());
assertEquals(3, isFinishedCounter.get());
assertEquals(1, endCounter.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,13 @@ void debounceTest() {
scheduler.run();
verify(command).schedule(true);
}

@Test
void booleanSupplierTest() {
InternalButton button = new InternalButton();

assertFalse(button.getAsBoolean());
button.setPressed(true);
assertTrue(button.getAsBoolean());
}
}
Loading