diff --git a/CMakeLists.txt b/CMakeLists.txt index 904133b882..83533f6c84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=2 -Wall -Wextra -Wno-unused-par SET(CMAKE_SKIP_BUILD_RPATH TRUE) file(GLOB_RECURSE NI_LIBS ni-libraries/*.so*) +get_filename_component(WPILIB_INCLUDES wpilibc/wpilibC++/include REALPATH) get_filename_component(HAL_API_INCLUDES hal/include REALPATH) get_filename_component(NWT_API_INCLUDES networktables/cpp/include REALPATH) add_subdirectory(hal) diff --git a/simulation/debs/Makefile b/simulation/debs/Makefile index cf9712f58a..a9b8da9b22 100644 --- a/simulation/debs/Makefile +++ b/simulation/debs/Makefile @@ -108,12 +108,12 @@ pull-eclipse-plugins: echo Increment version? pull-eclipse-toolchain: - rm -rf frcsim-eclipse-plugins/frcsim-eclipse-toolchain-plugins/plugins - rm -rf frcsim-eclipse-plugins/frcsim-eclipse-toolchain-plugins/features - mkdir -p frcsim-eclipse-plugins/frcsim-eclipse-toolchain-plugins/plugins - mkdir -p frcsim-eclipse-plugins/frcsim-eclipse-toolchain-plugins/features - cp $(allwpilib)/eclipse-plugins/edu.wpi.first.wpilib.plugins.updatesite/target/site/plugins/edu.wpi.first.wpilib.plugins.cpp.toolchains.linux_* frcsim-eclipse-plugins/frcsim-eclipse-toolchain-plugins/plugins - cp $(allwpilib)/eclipse-plugins/edu.wpi.first.wpilib.plugins.updatesite/target/site/features/edu.wpi.first.wpilib.plugins.cpp.toolchains.linux.feature_* frcsim-eclipse-plugins/frcsim-eclipse-toolchain-plugins/features + rm -rf frcsim-eclipse-toolchain-plugin/frcsim-eclipse-toolchain-plugin/plugins + rm -rf frcsim-eclipse-toolchain-plugin/frcsim-eclipse-toolchain-plugin/features + mkdir -p frcsim-eclipse-toolchain-plugin/frcsim-eclipse-toolchain-plugin/plugins + mkdir -p frcsim-eclipse-toolchain-plugin/frcsim-eclipse-toolchain-plugin/features + cp $(allwpilib)/eclipse-plugins/edu.wpi.first.wpilib.plugins.updatesite/target/site/plugins/edu.wpi.first.wpilib.plugins.cpp.toolchains.linux_* frcsim-eclipse-toolchain-plugin/frcsim-eclipse-toolchain-plugin/plugins/ + cp $(allwpilib)/eclipse-plugins/edu.wpi.first.wpilib.plugins.updatesite/target/site/features/edu.wpi.first.wpilib.plugins.cpp.toolchains.linux.feature_* frcsim-eclipse-toolchain-plugin/frcsim-eclipse-toolchain-plugin/features/ echo Increment version? pull-libwpilibsim-cpp: @@ -125,6 +125,14 @@ download-models: wget $(gazebo-models-orig-url) -O frcsim-gazebo-models_${gazebo-models-version}.orig.tar.gz && \ tar xvf frcsim-gazebo-models_${gazebo-models-version}.orig.tar.gz +install: + sudo dpkg -i frcsim-gazebo-plugins/frcsim-gazebo-plugins_0.2-1_amd64.deb \ + frcsim-gazebo-models/frcsim-gazebo-models_0.2-1_all.deb \ + frcsim-eclipse-plugins/frcsim-eclipse-plugins_0.1-1_all.deb \ + frcsim-eclipse-toolchain-plugin/frcsim-eclipse-toolchain-plugin_0.1-1_all.deb \ + frcsim-libwpilibsim-cpp/frcsim-libwpilibsim-cpp_0.1-1_amd64.deb \ + frcsim/frcsim_0.1-1_all.deb + deploy: rsync -r -v -C -p repository/ adhenning@ccc.wpi.edu:public_html/frcsim/ diff --git a/simulation/debs/frcsim-gazebo-plugins/frcsim-gazebo-plugins/debian/control b/simulation/debs/frcsim-gazebo-plugins/frcsim-gazebo-plugins/debian/control index dae690a2e5..7d115e1fc1 100644 --- a/simulation/debs/frcsim-gazebo-plugins/frcsim-gazebo-plugins/debian/control +++ b/simulation/debs/frcsim-gazebo-plugins/frcsim-gazebo-plugins/debian/control @@ -3,11 +3,11 @@ Maintainer: Alex Henning Section: misc Priority: optional Standards-Version: 3.9.4 -Build-Depends: debhelper (>= 9), gazebo3, libgazebo-dev, libavcodec-dev, libavformat-dev, libswscale-dev, libtinyxml2-dev +Build-Depends: debhelper (>= 9), gazebo3, libgazebo-dev, libavcodec-dev, libavformat-dev, libswscale-dev Package: frcsim-gazebo-plugins Architecture: i386 amd64 -Depends: ${shlibs:Depends}, ${misc:Depends}, gazebo3, libgazebo-dev, libavcodec-dev, libswscale-dev, libtinyxml2-dev +Depends: ${shlibs:Depends}, ${misc:Depends}, gazebo3, libgazebo-dev, libavcodec-dev, libswscale-dev Description: FRC plugin for controlling robots in the gazebo plugin. This plugin allows robots in gazebo to communicate with WPILib programs and enables the control of the robots. \ No newline at end of file diff --git a/wpilibc/CMakeLists.txt b/wpilibc/CMakeLists.txt index 5e3c0e91bc..e772705abf 100644 --- a/wpilibc/CMakeLists.txt +++ b/wpilibc/CMakeLists.txt @@ -2,4 +2,5 @@ cmake_minimum_required(VERSION 2.8) project(WPILibC) add_subdirectory(wpilibC++) +add_subdirectory(wpilibC++Devices) add_subdirectory(wpilibC++IntegrationTests) diff --git a/wpilibc/wpilibC++/CMakeLists.txt b/wpilibc/wpilibC++/CMakeLists.txt index 4e35b0a226..67a234f5d4 100644 --- a/wpilibc/wpilibC++/CMakeLists.txt +++ b/wpilibc/wpilibC++/CMakeLists.txt @@ -1,11 +1,12 @@ cmake_minimum_required(VERSION 2.8) project(WPILibC++) -file(GLOB_RECURSE SRC_FILES lib/*.cpp) -include_directories(include/ ${HAL_API_INCLUDES} ${NWT_API_INCLUDES}) -add_library(WPILibAthena STATIC ${SRC_FILES}) -target_link_libraries(WPILibAthena HALAthena NetworkTables ${NI_LIBS}) -INSTALL(TARGETS WPILibAthena ARCHIVE DESTINATION lib COMPONENT lib) +file(GLOB_RECURSE SRC_FILES src/*.cpp) +include_directories(include/ ${NWT_API_INCLUDES} ${HAL_API_INCLUDES}) +add_library(WPILib STATIC ${SRC_FILES}) +set(CMAKE_CXX_FLAGS "-fPIC") +target_link_libraries(WPILib) +INSTALL(TARGETS WPILib ARCHIVE DESTINATION src COMPONENT src) INSTALL(DIRECTORY include DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT headers) # lib/ c m gcc_s ld-linux # usr/lib stdc++ diff --git a/wpilibc/wpilibC++/include/Controller.h b/wpilibc/wpilibC++/include/Controller.h index 94aaa05177..99eba88055 100644 --- a/wpilibc/wpilibC++/include/Controller.h +++ b/wpilibc/wpilibC++/include/Controller.h @@ -5,7 +5,10 @@ /*----------------------------------------------------------------------------*/ #pragma once -#include "HAL/HAL.hpp" +#include +#include +#include +#include /** * Interface for Controllers diff --git a/wpilibc/wpilibC++/include/Error.h b/wpilibc/wpilibC++/include/Error.h index 18c5abc46d..16bdd560f9 100644 --- a/wpilibc/wpilibC++/include/Error.h +++ b/wpilibc/wpilibC++/include/Error.h @@ -7,7 +7,7 @@ #include "Base.h" #include -#include "HAL/HAL.hpp" +#include // Forward declarations class ErrorBase; @@ -49,5 +49,6 @@ private: const ErrorBase* m_originatingObject; double m_timestamp; - static bool m_suspendOnErrorEnabled;DISALLOW_COPY_AND_ASSIGN(Error); + static bool m_suspendOnErrorEnabled; + DISALLOW_COPY_AND_ASSIGN(Error); }; diff --git a/wpilibc/wpilibC++/include/ErrorBase.h b/wpilibc/wpilibC++/include/ErrorBase.h index 2d991e4757..c4e3cea924 100644 --- a/wpilibc/wpilibC++/include/ErrorBase.h +++ b/wpilibc/wpilibC++/include/ErrorBase.h @@ -8,7 +8,6 @@ #include "Base.h" #include "Error.h" #include "HAL/Semaphore.hpp" -#include "HAL/HAL.hpp" #define wpi_setErrnoErrorWithContext(context) (this->SetErrnoError((context), __FILE__, __FUNCTION__, __LINE__)) #define wpi_setErrnoError() (wpi_setErrnoErrorWithContext("")) diff --git a/wpilibc/wpilibC++/include/GenericHID.h b/wpilibc/wpilibC++/include/GenericHID.h index ac16ad9461..ac3518942f 100644 --- a/wpilibc/wpilibC++/include/GenericHID.h +++ b/wpilibc/wpilibC++/include/GenericHID.h @@ -5,7 +5,7 @@ /*----------------------------------------------------------------------------*/ #pragma once -#include "HAL/HAL.hpp" +#include /** GenericHID Interface */ diff --git a/wpilibc/wpilibC++Sim/include/Base.h b/wpilibc/wpilibC++/include/HLUsageReporting.h similarity index 51% rename from wpilibc/wpilibC++Sim/include/Base.h rename to wpilibc/wpilibC++/include/HLUsageReporting.h index 2aaa4ee223..359b149e9a 100644 --- a/wpilibc/wpilibC++Sim/include/Base.h +++ b/wpilibc/wpilibC++/include/HLUsageReporting.h @@ -5,15 +5,21 @@ /*----------------------------------------------------------------------------*/ #pragma once -// If don't have C++11, define constexpr as const for WindRiver -#if __cplusplus < 201103L -#define constexpr const -#define nullptr NULL -#endif - -// A macro to disallow the copy constructor and operator= functions -// This should be used in the private: declarations for a class -#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ - TypeName(const TypeName&); \ - void operator=(const TypeName&) +class HLUsageReportingInterface +{ +public: + virtual ~HLUsageReportingInterface() {}; + virtual void ReportScheduler() = 0; + virtual void ReportSmartDashboard() = 0; +}; +class HLUsageReporting +{ +private: + static HLUsageReportingInterface* impl; + +public: + static void SetImplementation(HLUsageReportingInterface* i); + static void ReportScheduler(); + static void ReportSmartDashboard(); +}; diff --git a/wpilibc/wpilibC++/include/Notifier.h b/wpilibc/wpilibC++/include/Notifier.h index ad969360b1..4bd89879f3 100644 --- a/wpilibc/wpilibC++/include/Notifier.h +++ b/wpilibc/wpilibC++/include/Notifier.h @@ -5,8 +5,8 @@ /*----------------------------------------------------------------------------*/ #pragma once -#include "HAL/HAL.hpp" #include "ErrorBase.h" +#include "Task.h" #include "HAL/cpp/Synchronized.hpp" typedef void (*TimerEventHandler)(void *param); @@ -22,7 +22,6 @@ public: private: static Notifier *timerQueueHead; static ReentrantSemaphore queueSemaphore; - static void* m_notifier; static int refcount; static void ProcessQueue(uint32_t mask, void *params); // process the timer queue on a timer event @@ -39,4 +38,7 @@ private: SEMAPHORE_ID m_handlerSemaphore; // held by interrupt manager task while handler call is in progress DISALLOW_COPY_AND_ASSIGN(Notifier); + + static Task *task; + static void Run(); }; diff --git a/wpilibc/wpilibC++/include/PIDController.h b/wpilibc/wpilibC++/include/PIDController.h index cf2cedcaa9..cf7732f475 100644 --- a/wpilibc/wpilibC++/include/PIDController.h +++ b/wpilibc/wpilibC++/include/PIDController.h @@ -69,7 +69,6 @@ private: float m_minimumInput; // minimum input - limit setpoint to this bool m_continuous; // do the endpoints wrap around? eg. Absolute encoder bool m_enabled; //is the pid controller enabled - bool m_destruct; // should the calculate thread stop running float m_prevError; // the prior sensor input (used to compute velocity) double m_totalError; //the sum of the errors for use in the integral calc enum @@ -83,7 +82,9 @@ private: float m_error; float m_result; float m_period; - + + MUTEX_ID m_semaphore; + PIDSource *m_pidInput; PIDOutput *m_pidOutput; @@ -92,7 +93,7 @@ private: void Initialize(float p, float i, float d, float f, PIDSource *source, PIDOutput *output, float period = 0.05); - static void *CallCalculate(void *controller); + static void CallCalculate(void *controller); virtual ITable* GetTable(); virtual std::string GetSmartDashboardType(); diff --git a/wpilibc/wpilibC++/include/Resource.h b/wpilibc/wpilibC++/include/Resource.h index ed3bcbd17b..fcb9b486e7 100644 --- a/wpilibc/wpilibC++/include/Resource.h +++ b/wpilibc/wpilibC++/include/Resource.h @@ -7,7 +7,7 @@ #include "ErrorBase.h" #include "HAL/cpp/Synchronized.hpp" -#include "HAL/HAL.hpp" +#include /** * The Resource class is a convenient way to track allocated resources. diff --git a/wpilibc/wpilibC++/include/RobotState.h b/wpilibc/wpilibC++/include/RobotState.h new file mode 100644 index 0000000000..ee25493a79 --- /dev/null +++ b/wpilibc/wpilibC++/include/RobotState.h @@ -0,0 +1,33 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2008. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ +/*----------------------------------------------------------------------------*/ +#pragma once + +class RobotStateInterface +{ +public: + virtual ~RobotStateInterface() {}; + virtual bool IsDisabled() = 0; + virtual bool IsEnabled() = 0; + virtual bool IsOperatorControl() = 0; + virtual bool IsAutonomous() = 0; + virtual bool IsTest() = 0; +}; + +class RobotState +{ +private: + static RobotStateInterface* impl; + +public: + static void SetImplementation(RobotStateInterface* i); + static bool IsDisabled(); + static bool IsEnabled(); + static bool IsOperatorControl(); + static bool IsAutonomous(); + static bool IsTest(); +}; + + diff --git a/wpilibc/wpilibC++/include/Task.h b/wpilibc/wpilibC++/include/Task.h index 7377c9ecfa..ca1754a50d 100644 --- a/wpilibc/wpilibC++/include/Task.h +++ b/wpilibc/wpilibC++/include/Task.h @@ -6,7 +6,7 @@ #pragma once #include "ErrorBase.h" -#include "HAL/HAL.hpp" +#include "HAL/Task.hpp" /** * WPI task is a wrapper for the native Task object. diff --git a/wpilibc/wpilibC++/include/Timer.h b/wpilibc/wpilibC++/include/Timer.h index 67d574f2d3..03e33b76e2 100644 --- a/wpilibc/wpilibC++/include/Timer.h +++ b/wpilibc/wpilibC++/include/Timer.h @@ -34,6 +34,7 @@ public: static double GetFPGATimestamp(); static double GetPPCTimestamp(); + static double GetMatchTime(); private: double m_startTime; diff --git a/wpilibc/wpilibC++/include/Utility.h b/wpilibc/wpilibC++/include/Utility.h index b81feb8639..4fe325fa80 100644 --- a/wpilibc/wpilibC++/include/Utility.h +++ b/wpilibc/wpilibC++/include/Utility.h @@ -5,7 +5,7 @@ /*---------------------------------------------------------------------------*/ #pragma once -#include "HAL/HAL.hpp" +#include #include #define wpi_assert(condition) wpi_assert_impl(condition, #condition, NULL, __FILE__, __LINE__, __FUNCTION__) diff --git a/wpilibc/wpilibC++/include/WPIErrors.h b/wpilibc/wpilibC++/include/WPIErrors.h index 10a8849eb3..570ee0fef3 100644 --- a/wpilibc/wpilibC++/include/WPIErrors.h +++ b/wpilibc/wpilibC++/include/WPIErrors.h @@ -54,6 +54,7 @@ S(NetworkTablesWrongType, -42, "The wrong type was read from the NetworkTables e S(NetworkTablesCorrupt, -43, "NetworkTables data stream is corrupt"); S(SmartDashboardMissingKey, -43, "SmartDashboard data does not exist"); S(CommandIllegalUse, -50, "Illegal use of Command"); +S(UnsupportedInSimulation, -80, "Unsupported in simulation"); /* * Warnings diff --git a/wpilibc/wpilibC++/lib/Buttons/Button.cpp b/wpilibc/wpilibC++/lib/Buttons/Button.cpp deleted file mode 100644 index ba1489fd93..0000000000 --- a/wpilibc/wpilibC++/lib/Buttons/Button.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Buttons/Button.h" - -/** - * Specifies the command to run when a button is first pressed - * @param command The pointer to the command to run - */ -void Button::WhenPressed(Command *command) { - WhenActive(command); -} - -/** - * Specifies the command to be scheduled while the button is pressed - * The command will be scheduled repeatedly while the button is pressed and will - * be canceled when the button is released. - * @param command The pointer to the command to run - */ -void Button::WhileHeld(Command *command) { - WhileActive(command); -} - -/** - * Specifies the command to run when the button is released - * The command will be scheduled a single time. - * @param The pointer to the command to run - */ -void Button::WhenReleased(Command *command) { - WhenInactive(command); -} - -/** - * Cancels the specificed command when the button is pressed - * @param The command to be canceled - */ -void Button::CancelWhenPressed(Command *command) { - CancelWhenActive(command); -} - -/** - * Toggle the specified command when the button is pressed - * @param The command to be toggled - */ -void Button::ToggleWhenPressed(Command *command) { - ToggleWhenActive(command); -} diff --git a/wpilibc/wpilibC++/lib/Buttons/ButtonScheduler.cpp b/wpilibc/wpilibC++/lib/Buttons/ButtonScheduler.cpp deleted file mode 100644 index e7f71b983a..0000000000 --- a/wpilibc/wpilibC++/lib/Buttons/ButtonScheduler.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Buttons/ButtonScheduler.h" - -#include "Commands/Scheduler.h" - -ButtonScheduler::ButtonScheduler(bool last, Trigger *button, Command *orders) : - m_pressedLast(last), - m_button(button), - m_command(orders) -{ -} - -void ButtonScheduler::Start() -{ - Scheduler::GetInstance()->AddButton(this); -} diff --git a/wpilibc/wpilibC++/lib/Buttons/CancelButtonScheduler.cpp b/wpilibc/wpilibC++/lib/Buttons/CancelButtonScheduler.cpp deleted file mode 100644 index 5562158d17..0000000000 --- a/wpilibc/wpilibC++/lib/Buttons/CancelButtonScheduler.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Buttons/CancelButtonScheduler.h" - -#include "Buttons/Button.h" -#include "Commands/Command.h" - -CancelButtonScheduler::CancelButtonScheduler(bool last, Trigger *button, Command *orders) : - ButtonScheduler(last, button, orders) -{ - pressedLast = m_button->Grab(); -} - -void CancelButtonScheduler::Execute() -{ - if (m_button->Grab()) { - if (!pressedLast) { - pressedLast = true; - m_command->Cancel(); - } - } else { - pressedLast = false; - } -} - diff --git a/wpilibc/wpilibC++/lib/Buttons/HeldButtonScheduler.cpp b/wpilibc/wpilibC++/lib/Buttons/HeldButtonScheduler.cpp deleted file mode 100644 index fbe4a9f3fd..0000000000 --- a/wpilibc/wpilibC++/lib/Buttons/HeldButtonScheduler.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Buttons/HeldButtonScheduler.h" - -#include "Buttons/Button.h" -#include "Commands/Command.h" - -HeldButtonScheduler::HeldButtonScheduler(bool last, Trigger *button, Command *orders) : - ButtonScheduler(last, button, orders) -{ -} - -void HeldButtonScheduler::Execute() -{ - if (m_button->Grab()) - { - m_pressedLast = true; - m_command->Start(); - } - else - { - if (m_pressedLast) - { - m_pressedLast = false; - m_command->Cancel(); - } - } -} diff --git a/wpilibc/wpilibC++/lib/Buttons/InternalButton.cpp b/wpilibc/wpilibC++/lib/Buttons/InternalButton.cpp deleted file mode 100644 index 0bd322dd48..0000000000 --- a/wpilibc/wpilibC++/lib/Buttons/InternalButton.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Buttons/InternalButton.h" - -InternalButton::InternalButton() : - m_pressed(false), - m_inverted(false) -{ -} - -InternalButton::InternalButton(bool inverted) : - m_pressed(inverted), - m_inverted(inverted) -{ -} - -void InternalButton::SetInverted(bool inverted) -{ - m_inverted = inverted; -} - -void InternalButton::SetPressed(bool pressed) -{ - m_pressed = pressed; -} - -bool InternalButton::Get() -{ - return m_pressed ^ m_inverted; -} diff --git a/wpilibc/wpilibC++/lib/Buttons/JoystickButton.cpp b/wpilibc/wpilibC++/lib/Buttons/JoystickButton.cpp deleted file mode 100644 index 3dace65873..0000000000 --- a/wpilibc/wpilibC++/lib/Buttons/JoystickButton.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Buttons/JoystickButton.h" - -JoystickButton::JoystickButton(GenericHID *joystick, int buttonNumber) : - m_joystick(joystick), - m_buttonNumber(buttonNumber) -{ -} - -bool JoystickButton::Get() -{ - return m_joystick->GetRawButton(m_buttonNumber); -} diff --git a/wpilibc/wpilibC++/lib/Buttons/NetworkButton.cpp b/wpilibc/wpilibC++/lib/Buttons/NetworkButton.cpp deleted file mode 100644 index 5b67c2aac8..0000000000 --- a/wpilibc/wpilibC++/lib/Buttons/NetworkButton.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Buttons/NetworkButton.h" -#include "networktables/NetworkTable.h" - -NetworkButton::NetworkButton(const char *tableName, const char *field) ://TODO how is this supposed to work??? - m_netTable(NetworkTable::GetTable(tableName)), - m_field(field) -{ -} - -NetworkButton::NetworkButton(ITable *table, const char *field) : - m_netTable(table), - m_field(field) -{ -} - -bool NetworkButton::Get() -{ - /*if (m_netTable->isConnected()) - return m_netTable->GetBoolean(m_field.c_str()); - else - return false;*/ - return m_netTable->GetBoolean(m_field); -} diff --git a/wpilibc/wpilibC++/lib/Buttons/PressedButtonScheduler.cpp b/wpilibc/wpilibC++/lib/Buttons/PressedButtonScheduler.cpp deleted file mode 100644 index 3cf25ba6a0..0000000000 --- a/wpilibc/wpilibC++/lib/Buttons/PressedButtonScheduler.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Buttons/PressedButtonScheduler.h" - -#include "Buttons/Button.h" -#include "Commands/Command.h" - -PressedButtonScheduler::PressedButtonScheduler(bool last, Trigger *button, Command *orders) : - ButtonScheduler(last, button, orders) -{ -} - -void PressedButtonScheduler::Execute() -{ - if (m_button->Grab()) - { - if (!m_pressedLast) - { - m_pressedLast = true; - m_command->Start(); - } - } - else - { - m_pressedLast = false; - } -} diff --git a/wpilibc/wpilibC++/lib/Buttons/ReleasedButtonScheduler.cpp b/wpilibc/wpilibC++/lib/Buttons/ReleasedButtonScheduler.cpp deleted file mode 100644 index 8715573f2c..0000000000 --- a/wpilibc/wpilibC++/lib/Buttons/ReleasedButtonScheduler.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Buttons/ReleasedButtonScheduler.h" - -#include "Buttons/Button.h" -#include "Commands/Command.h" - -ReleasedButtonScheduler::ReleasedButtonScheduler(bool last, Trigger *button, Command *orders) : - ButtonScheduler(last, button, orders) -{ -} - -void ReleasedButtonScheduler::Execute() -{ - if (m_button->Grab()) - { - m_pressedLast = true; - } - else - { - if (m_pressedLast) - { - m_pressedLast = false; - m_command->Start(); - } - } -} diff --git a/wpilibc/wpilibC++/lib/Buttons/ToggleButtonScheduler.cpp b/wpilibc/wpilibC++/lib/Buttons/ToggleButtonScheduler.cpp deleted file mode 100644 index ed72160df7..0000000000 --- a/wpilibc/wpilibC++/lib/Buttons/ToggleButtonScheduler.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Buttons/ToggleButtonScheduler.h" - -#include "Buttons/Button.h" -#include "Commands/Command.h" - -ToggleButtonScheduler::ToggleButtonScheduler(bool last, Trigger *button, - Command *orders) : - ButtonScheduler(last, button, orders) { - pressedLast = m_button->Grab(); -} - -void ToggleButtonScheduler::Execute() { - if (m_button->Grab()) { - if (!pressedLast) { - pressedLast = true; - if (m_command->IsRunning()) { - m_command->Cancel(); - } else { - m_command->Start(); - } - } - } else { - pressedLast = false; - } -} - diff --git a/wpilibc/wpilibC++/lib/Buttons/Trigger.cpp b/wpilibc/wpilibC++/lib/Buttons/Trigger.cpp deleted file mode 100644 index 55b865b8f2..0000000000 --- a/wpilibc/wpilibC++/lib/Buttons/Trigger.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Buttons/Button.h" - -#include "Buttons/HeldButtonScheduler.h" -#include "Buttons/PressedButtonScheduler.h" -#include "Buttons/ReleasedButtonScheduler.h" -#include "Buttons/ToggleButtonScheduler.h" -#include "Buttons/CancelButtonScheduler.h" - -Trigger::Trigger() { - m_table = NULL; -} - -bool Trigger::Grab() -{ - if (Get()) - return true; - else if (m_table != NULL) - { - //if (m_table->isConnected())//TODO is connected on button? - return m_table->GetBoolean("pressed"); - /*else - return false;*/ - } - else - return false; -} - -void Trigger::WhenActive(Command *command) -{ - PressedButtonScheduler *pbs = new PressedButtonScheduler(Grab(), this, command); - pbs->Start(); -} - -void Trigger::WhileActive(Command *command) -{ - HeldButtonScheduler *hbs = new HeldButtonScheduler(Grab(), this, command); - hbs->Start(); -} - -void Trigger::WhenInactive(Command *command) -{ - ReleasedButtonScheduler *rbs = new ReleasedButtonScheduler(Grab(), this, command); - rbs->Start(); -} - -void Trigger::CancelWhenActive(Command *command) { - CancelButtonScheduler *cbs = new CancelButtonScheduler(Grab(), this, command); - cbs->Start(); -} - -void Trigger::ToggleWhenActive(Command *command) { - ToggleButtonScheduler *tbs = new ToggleButtonScheduler(Grab(), this, command); - tbs->Start(); -} - -std::string Trigger::GetSmartDashboardType(){ - return "Button"; -} - -void Trigger::InitTable(ITable* table){ - m_table = table; - if(m_table!=NULL){ - m_table->PutBoolean("pressed", Get()); - } -} - -ITable* Trigger::GetTable(){ - return m_table; -} diff --git a/wpilibc/wpilibC++/lib/Commands/CommandGroup.cpp b/wpilibc/wpilibC++/lib/Commands/CommandGroup.cpp deleted file mode 100644 index b1decd37ac..0000000000 --- a/wpilibc/wpilibC++/lib/Commands/CommandGroup.cpp +++ /dev/null @@ -1,383 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Commands/CommandGroup.h" -#include "WPIErrors.h" - -/** - * Creates a new {@link CommandGroup CommandGroup}. - */ -CommandGroup::CommandGroup() -{ - m_currentCommandIndex = -1; -} - -/** - * Creates a new {@link CommandGroup CommandGroup} with the given name. - * @param name the name for this command group - */ -CommandGroup::CommandGroup(const char *name) : - Command(name) -{ - m_currentCommandIndex = -1; -} - -CommandGroup::~CommandGroup() -{ -} - -/** - * Adds a new {@link Command Command} to the group. The {@link Command Command} will be started after - * all the previously added {@link Command Commands}. - * - *

Note that any requirements the given {@link Command Command} has will be added to the - * group. For this reason, a {@link Command Command's} requirements can not be changed after - * being added to a group.

- * - *

It is recommended that this method be called in the constructor.

- * - * @param command The {@link Command Command} to be added - */ -void CommandGroup::AddSequential(Command *command) -{ - if (command == NULL) - { - wpi_setWPIErrorWithContext(NullParameter, "command"); - return; - } - if (!AssertUnlocked("Cannot add new command to command group")) - return; - - command->SetParent(this); - - m_commands.push_back(CommandGroupEntry(command, CommandGroupEntry::kSequence_InSequence)); - // Iterate through command->GetRequirements() and call Requires() on each required subsystem - Command::SubsystemSet requirements = command->GetRequirements(); - Command::SubsystemSet::iterator iter = requirements.begin(); - for (; iter != requirements.end(); iter++) - Requires(*iter); -} - -/** - * Adds a new {@link Command Command} to the group with a given timeout. - * The {@link Command Command} will be started after all the previously added commands. - * - *

Once the {@link Command Command} is started, it will be run until it finishes or the time - * expires, whichever is sooner. Note that the given {@link Command Command} will have no - * knowledge that it is on a timer.

- * - *

Note that any requirements the given {@link Command Command} has will be added to the - * group. For this reason, a {@link Command Command's} requirements can not be changed after - * being added to a group.

- * - *

It is recommended that this method be called in the constructor.

- * - * @param command The {@link Command Command} to be added - * @param timeout The timeout (in seconds) - */ -void CommandGroup::AddSequential(Command *command, double timeout) -{ - if (command == NULL) - { - wpi_setWPIErrorWithContext(NullParameter, "command"); - return; - } - if (!AssertUnlocked("Cannot add new command to command group")) - return; - if (timeout < 0.0) - { - wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0"); - return; - } - - command->SetParent(this); - - m_commands.push_back(CommandGroupEntry(command, CommandGroupEntry::kSequence_InSequence, timeout)); - // Iterate through command->GetRequirements() and call Requires() on each required subsystem - Command::SubsystemSet requirements = command->GetRequirements(); - Command::SubsystemSet::iterator iter = requirements.begin(); - for (; iter != requirements.end(); iter++) - Requires(*iter); -} - -/** - * Adds a new child {@link Command} to the group. The {@link Command} will be started after - * all the previously added {@link Command Commands}. - * - *

Instead of waiting for the child to finish, a {@link CommandGroup} will have it - * run at the same time as the subsequent {@link Command Commands}. The child will run until either - * it finishes, a new child with conflicting requirements is started, or - * the main sequence runs a {@link Command} with conflicting requirements. In the latter - * two cases, the child will be canceled even if it says it can't be - * interrupted.

- * - *

Note that any requirements the given {@link Command Command} has will be added to the - * group. For this reason, a {@link Command Command's} requirements can not be changed after - * being added to a group.

- * - *

It is recommended that this method be called in the constructor.

- * - * @param command The command to be added - */ -void CommandGroup::AddParallel(Command *command) -{ - if (command == NULL) - { - wpi_setWPIErrorWithContext(NullParameter, "command"); - return; - } - if (!AssertUnlocked("Cannot add new command to command group")) - return; - - command->SetParent(this); - - m_commands.push_back(CommandGroupEntry(command, CommandGroupEntry::kSequence_BranchChild)); - // Iterate through command->GetRequirements() and call Requires() on each required subsystem - Command::SubsystemSet requirements = command->GetRequirements(); - Command::SubsystemSet::iterator iter = requirements.begin(); - for (; iter != requirements.end(); iter++) - Requires(*iter); -} - -/** - * Adds a new child {@link Command} to the group with the given timeout. The {@link Command} will be started after - * all the previously added {@link Command Commands}. - * - *

Once the {@link Command Command} is started, it will run until it finishes, is interrupted, - * or the time expires, whichever is sooner. Note that the given {@link Command Command} will have no - * knowledge that it is on a timer.

- * - *

Instead of waiting for the child to finish, a {@link CommandGroup} will have it - * run at the same time as the subsequent {@link Command Commands}. The child will run until either - * it finishes, the timeout expires, a new child with conflicting requirements is started, or - * the main sequence runs a {@link Command} with conflicting requirements. In the latter - * two cases, the child will be canceled even if it says it can't be - * interrupted.

- * - *

Note that any requirements the given {@link Command Command} has will be added to the - * group. For this reason, a {@link Command Command's} requirements can not be changed after - * being added to a group.

- * - *

It is recommended that this method be called in the constructor.

- * - * @param command The command to be added - * @param timeout The timeout (in seconds) - */ -void CommandGroup::AddParallel(Command *command, double timeout) -{ - if (command == NULL) - { - wpi_setWPIErrorWithContext(NullParameter, "command"); - return; - } - if (!AssertUnlocked("Cannot add new command to command group")) - return; - if (timeout < 0.0) - { - wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0"); - return; - } - - command->SetParent(this); - - m_commands.push_back(CommandGroupEntry(command, CommandGroupEntry::kSequence_BranchChild, timeout)); - // Iterate through command->GetRequirements() and call Requires() on each required subsystem - Command::SubsystemSet requirements = command->GetRequirements(); - Command::SubsystemSet::iterator iter = requirements.begin(); - for (; iter != requirements.end(); iter++) - Requires(*iter); -} - -void CommandGroup::_Initialize() -{ - m_currentCommandIndex = -1; -} - -void CommandGroup::_Execute() -{ - CommandGroupEntry entry; - Command *cmd = NULL; - bool firstRun = false; - - if (m_currentCommandIndex == -1) - { - firstRun = true; - m_currentCommandIndex = 0; - } - - while ((unsigned)m_currentCommandIndex < m_commands.size()) - { - if (cmd != NULL) - { - if (entry.IsTimedOut()) - cmd->_Cancel(); - - if (cmd->Run()) - { - break; - } - else - { - cmd->Removed(); - m_currentCommandIndex++; - firstRun = true; - cmd = NULL; - continue; - } - } - - entry = m_commands[m_currentCommandIndex]; - cmd = NULL; - - switch (entry.m_state) - { - case CommandGroupEntry::kSequence_InSequence: - cmd = entry.m_command; - if (firstRun) - { - cmd->StartRunning(); - CancelConflicts(cmd); - firstRun = false; - } - break; - - case CommandGroupEntry::kSequence_BranchPeer: - m_currentCommandIndex++; - entry.m_command->Start(); - break; - - case CommandGroupEntry::kSequence_BranchChild: - m_currentCommandIndex++; - CancelConflicts(entry.m_command); - entry.m_command->StartRunning(); - m_children.push_back(entry); - break; - } - } - - // Run Children - CommandList::iterator iter = m_children.begin(); - for (; iter != m_children.end();) - { - entry = *iter; - Command *child = entry.m_command; - if (entry.IsTimedOut()) - child->_Cancel(); - - if (!child->Run()) - { - child->Removed(); - iter = m_children.erase(iter); - } - else - { - iter++; - } - } -} - -void CommandGroup::_End() -{ - // Theoretically, we don't have to check this, but we do if teams override the IsFinished method - if (m_currentCommandIndex != -1 && (unsigned)m_currentCommandIndex < m_commands.size()) - { - Command *cmd = m_commands[m_currentCommandIndex].m_command; - cmd->_Cancel(); - cmd->Removed(); - } - - CommandList::iterator iter = m_children.begin(); - for (; iter != m_children.end(); iter++) - { - Command *cmd = iter->m_command; - cmd->_Cancel(); - cmd->Removed(); - } - m_children.clear(); -} - -void CommandGroup::_Interrupted() -{ - _End(); -} - -// Can be overwritten by teams -void CommandGroup::Initialize() -{ -} - -// Can be overwritten by teams -void CommandGroup::Execute() -{ -} - -// Can be overwritten by teams -void CommandGroup::End() -{ -} - -// Can be overwritten by teams -void CommandGroup::Interrupted() -{ -} - -bool CommandGroup::IsFinished() -{ - return (unsigned)m_currentCommandIndex >= m_commands.size() && m_children.empty(); -} - -bool CommandGroup::IsInterruptible() -{ - if (!Command::IsInterruptible()) - return false; - - if (m_currentCommandIndex != -1 && (unsigned)m_currentCommandIndex < m_commands.size()) - { - Command *cmd = m_commands[m_currentCommandIndex].m_command; - if (!cmd->IsInterruptible()) - return false; - } - - CommandList::iterator iter = m_children.begin(); - for (; iter != m_children.end(); iter++) - { - if (!iter->m_command->IsInterruptible()) - return false; - } - - return true; -} - -void CommandGroup::CancelConflicts(Command *command) -{ - CommandList::iterator childIter = m_children.begin(); - for (; childIter != m_children.end();) - { - Command *child = childIter->m_command; - bool erased = false; - - Command::SubsystemSet requirements = command->GetRequirements(); - Command::SubsystemSet::iterator requirementIter = requirements.begin(); - for (; requirementIter != requirements.end(); requirementIter++) - { - if (child->DoesRequire(*requirementIter)) - { - child->_Cancel(); - child->Removed(); - childIter = m_children.erase(childIter); - erased = true; - break; - } - } - if (!erased) - childIter++; - } -} - -int CommandGroup::GetSize() -{ - return m_children.size(); -} diff --git a/wpilibc/wpilibC++/lib/Commands/CommandGroupEntry.cpp b/wpilibc/wpilibC++/lib/Commands/CommandGroupEntry.cpp deleted file mode 100644 index 144825787e..0000000000 --- a/wpilibc/wpilibC++/lib/Commands/CommandGroupEntry.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Commands/CommandGroupEntry.h" - -#include "Commands/Command.h" - -CommandGroupEntry::CommandGroupEntry() : - m_timeout(-1.0), - m_command(NULL), - m_state(kSequence_InSequence) -{ -} - -CommandGroupEntry::CommandGroupEntry(Command *command, Sequence state) : - m_timeout(-1.0), - m_command(command), - m_state(state) -{ -} - -CommandGroupEntry::CommandGroupEntry(Command *command, Sequence state, double timeout) : - m_timeout(timeout), - m_command(command), - m_state(state) -{ -} - -bool CommandGroupEntry::IsTimedOut() -{ - if (m_timeout < 0.0) - return false; - double time = m_command->TimeSinceInitialized(); - if (time == 0.0) - return false; - return time >= m_timeout; -} diff --git a/wpilibc/wpilibC++/lib/Commands/PIDCommand.cpp b/wpilibc/wpilibC++/lib/Commands/PIDCommand.cpp deleted file mode 100644 index 19da02d22a..0000000000 --- a/wpilibc/wpilibC++/lib/Commands/PIDCommand.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Commands/PIDCommand.h" - -#include "PIDController.h" -#include "float.h" - -PIDCommand::PIDCommand(const char *name, double p, double i, double d, double f, double period) : - Command(name) -{ - m_controller = new PIDController(p, i, d, this, this, period); -} - -PIDCommand::PIDCommand(double p, double i, double d, double f, double period) -{ - m_controller = new PIDController(p, i, d, f, this, this, period); -} - -PIDCommand::PIDCommand(const char *name, double p, double i, double d) : - Command(name) -{ - m_controller = new PIDController(p, i, d, this, this); -} - -PIDCommand::PIDCommand(const char *name, double p, double i, double d, double period) : - Command(name) -{ - m_controller = new PIDController(p, i, d, this, this, period); -} - -PIDCommand::PIDCommand(double p, double i, double d) -{ - m_controller = new PIDController(p, i, d, this, this); -} - -PIDCommand::PIDCommand(double p, double i, double d, double period) -{ - m_controller = new PIDController(p, i, d, this, this, period); -} - -PIDCommand::~PIDCommand() -{ - delete m_controller; -} - -void PIDCommand::_Initialize() -{ - m_controller->Enable(); -} - -void PIDCommand::_End() -{ - m_controller->Disable(); -} - -void PIDCommand::_Interrupted() -{ - _End(); -} - -void PIDCommand::SetSetpointRelative(double deltaSetpoint) -{ - SetSetpoint(GetSetpoint() + deltaSetpoint); -} - -void PIDCommand::PIDWrite(float output) -{ - UsePIDOutput(output); -} - -double PIDCommand::PIDGet() -{ - return ReturnPIDInput(); -} - -PIDController *PIDCommand::GetPIDController() -{ - return m_controller; -} - -void PIDCommand::SetSetpoint(double setpoint) -{ - m_controller->SetSetpoint(setpoint); -} - -double PIDCommand::GetSetpoint() -{ - return m_controller->GetSetpoint(); -} - -double PIDCommand::GetPosition() -{ - return ReturnPIDInput(); -} - -std::string PIDCommand::GetSmartDashboardType(){ - return "PIDCommand"; -} -void PIDCommand::InitTable(ITable* table){ - m_controller->InitTable(table); - Command::InitTable(table); -} diff --git a/wpilibc/wpilibC++/lib/Commands/PrintCommand.cpp b/wpilibc/wpilibC++/lib/Commands/PrintCommand.cpp deleted file mode 100644 index 646db72b12..0000000000 --- a/wpilibc/wpilibC++/lib/Commands/PrintCommand.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Commands/PrintCommand.h" -#include "stdio.h" -#include - -PrintCommand::PrintCommand(const char *message) : - Command(((std::stringstream&)(std::stringstream("Print \"") << message << "\"")).str().c_str()) -{ - m_message = message; -} - -void PrintCommand::Initialize() -{ - printf("%s", m_message.c_str()); -} - -void PrintCommand::Execute() -{ -} - -bool PrintCommand::IsFinished() -{ - return true; -} - -void PrintCommand::End() -{ -} - -void PrintCommand::Interrupted() -{ -} diff --git a/wpilibc/wpilibC++/lib/Commands/Scheduler.cpp b/wpilibc/wpilibC++/lib/Commands/Scheduler.cpp deleted file mode 100644 index bff9fb56a1..0000000000 --- a/wpilibc/wpilibC++/lib/Commands/Scheduler.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Commands/Scheduler.h" - -#include "Buttons/ButtonScheduler.h" -#include "Commands/Subsystem.h" -//#include "NetworkCommunication/UsageReporting.h" -#include "HAL/cpp/Synchronized.hpp" -#include "WPIErrors.h" -#include -#include -#include - -Scheduler *Scheduler::_instance = NULL; - -Scheduler::Scheduler() : - m_buttonsLock(NULL), m_additionsLock(NULL), m_adding(false) { - m_buttonsLock = initializeMutexNormal(); - m_additionsLock = initializeMutexNormal(); - - HALReport(HALUsageReporting::kResourceType_Command, - HALUsageReporting::kCommand_Scheduler); - - m_table = NULL; - m_enabled = true; -} - -Scheduler::~Scheduler() { - takeMutex(m_additionsLock); - deleteMutex(m_additionsLock); - - takeMutex(m_buttonsLock); - deleteMutex(m_buttonsLock); -} - -/** - * Returns the {@link Scheduler}, creating it if one does not exist. - * @return the {@link Scheduler} - */ -Scheduler *Scheduler::GetInstance() { - if (_instance == NULL) - _instance = new Scheduler(); - return _instance; -} - -void Scheduler::SetEnabled(bool enabled) { - m_enabled = enabled; -} - -/** - * Add a command to be scheduled later. - * In any pass through the scheduler, all commands are added to the additions list, then - * at the end of the pass, they are all scheduled. - * @param command The command to be scheduled - */ -void Scheduler::AddCommand(Command *command) { - Synchronized sync(m_additionsLock); - if (std::find(m_additions.begin(), m_additions.end(), command) - != m_additions.end()) - return; - m_additions.push_back(command); -} - -void Scheduler::AddButton(ButtonScheduler *button) { - Synchronized sync(m_buttonsLock); - m_buttons.push_back(button); -} - -void Scheduler::ProcessCommandAddition(Command *command) { - if (command == NULL) - return; - - // Check to make sure no adding during adding - if (m_adding) { - wpi_setWPIErrorWithContext(IncompatibleState, "Can not start command from cancel method"); - return; - } - - // Only add if not already in - CommandSet::iterator found = m_commands.find(command); - if (found == m_commands.end()) { - // Check that the requirements can be had - Command::SubsystemSet requirements = command->GetRequirements(); - Command::SubsystemSet::iterator iter; - for (iter = requirements.begin(); iter != requirements.end(); iter++) { - Subsystem *lock = *iter; - if (lock->GetCurrentCommand() != NULL - && !lock->GetCurrentCommand()->IsInterruptible()) - return; - } - - // Give it the requirements - m_adding = true; - for (iter = requirements.begin(); iter != requirements.end(); iter++) { - Subsystem *lock = *iter; - if (lock->GetCurrentCommand() != NULL) { - lock->GetCurrentCommand()->Cancel(); - Remove(lock->GetCurrentCommand()); - } - lock->SetCurrentCommand(command); - } - m_adding = false; - - m_commands.insert(command); - - command->StartRunning(); - m_runningCommandsChanged = true; - } -} - -/** - * Runs a single iteration of the loop. This method should be called often in order to have a functioning - * {@link Command} system. The loop has five stages: - * - *
    - *
  1. Poll the Buttons
  2. - *
  3. Execute/Remove the Commands
  4. - *
  5. Send values to SmartDashboard
  6. - *
  7. Add Commands
  8. - *
  9. Add Defaults
  10. - *
- */ -void Scheduler::Run() { - // Get button input (going backwards preserves button priority) - { - if (!m_enabled) - return; - - Synchronized sync(m_buttonsLock); - ButtonVector::reverse_iterator rButtonIter = m_buttons.rbegin(); - for (; rButtonIter != m_buttons.rend(); rButtonIter++) { - (*rButtonIter)->Execute(); - } - } - - m_runningCommandsChanged = false; - - // Loop through the commands - CommandSet::iterator commandIter = m_commands.begin(); - for (; commandIter != m_commands.end();) { - Command *command = *commandIter; - // Increment before potentially removing to keep the iterator valid - commandIter++; - if (!command->Run()) { - Remove(command); - m_runningCommandsChanged = true; - } - } - - // Add the new things - { - Synchronized sync(m_additionsLock); - CommandVector::iterator additionsIter = m_additions.begin(); - for (; additionsIter != m_additions.end(); additionsIter++) { - ProcessCommandAddition(*additionsIter); - } - m_additions.clear(); - } - - // Add in the defaults - Command::SubsystemSet::iterator subsystemIter = m_subsystems.begin(); - for (; subsystemIter != m_subsystems.end(); subsystemIter++) { - Subsystem *lock = *subsystemIter; - if (lock->GetCurrentCommand() == NULL) { - ProcessCommandAddition(lock->GetDefaultCommand()); - } - lock->ConfirmCommand(); - } - - UpdateTable(); -} - -/** - * Registers a {@link Subsystem} to this {@link Scheduler}, so that the {@link Scheduler} might know - * if a default {@link Command} needs to be run. All {@link Subsystem Subsystems} should call this. - * @param system the system - */ -void Scheduler::RegisterSubsystem(Subsystem *subsystem) { - if (subsystem == NULL) { - wpi_setWPIErrorWithContext(NullParameter, "subsystem"); - return; - } - m_subsystems.insert(subsystem); -} - -/** - * Removes the {@link Command} from the {@link Scheduler}. - * @param command the command to remove - */ -void Scheduler::Remove(Command *command) { - if (command == NULL) { - wpi_setWPIErrorWithContext(NullParameter, "command"); - return; - } - - if (!m_commands.erase(command)) - return; - - Command::SubsystemSet requirements = command->GetRequirements(); - Command::SubsystemSet::iterator iter = requirements.begin(); - for (; iter != requirements.end(); iter++) { - Subsystem *lock = *iter; - lock->SetCurrentCommand(NULL); - } - - command->Removed(); -} - -void Scheduler::RemoveAll() { - while (m_commands.size() > 0) { - Remove(*m_commands.begin()); - } -} - -/** - * Update the network tables associated with the Scheduler object on the SmartDashboard - */ -void Scheduler::UpdateTable() { - CommandSet::iterator commandIter; - if (m_table != NULL) { - // Get the list of possible commands to cancel - m_table->RetrieveValue("Cancel", *toCancel); -// m_table->RetrieveValue("Ids", *ids); - - // cancel commands that have had the cancel buttons pressed - // on the SmartDashboad - if (toCancel->size() > 0) { - for (commandIter = m_commands.begin(); commandIter - != m_commands.end(); ++commandIter) { - for (unsigned i = 0; i < toCancel->size(); i++) { - Command *c = *commandIter; - if (c->GetID() == toCancel->get(i)) { - c->Cancel(); - } - } - } - toCancel->setSize(0); - m_table->PutValue("Cancel", *toCancel); - } - - // Set the running commands - if (m_runningCommandsChanged) { - commands->setSize(0); - ids->setSize(0); - for (commandIter = m_commands.begin(); commandIter != m_commands.end(); ++commandIter) { - Command *c = *commandIter; - commands->add(c->GetName()); - ids->add(c->GetID()); - } - m_table->PutValue("Names", *commands); - m_table->PutValue("Ids", *ids); - } - } -} - -std::string Scheduler::GetName() { - return "Scheduler"; -} - -std::string Scheduler::GetType() { - return "Scheduler"; -} - -std::string Scheduler::GetSmartDashboardType() { - return "Scheduler"; -} - -void Scheduler::InitTable(ITable *subTable) { - m_table = subTable; - commands = new StringArray(); - ids = new NumberArray(); - toCancel = new NumberArray(); - - m_table->PutValue("Names", *commands); - m_table->PutValue("Ids", *ids); - m_table->PutValue("Cancel", *toCancel); -} - -ITable * Scheduler::GetTable() { - return m_table; -} diff --git a/wpilibc/wpilibC++/lib/Commands/StartCommand.cpp b/wpilibc/wpilibC++/lib/Commands/StartCommand.cpp deleted file mode 100644 index 4e04514069..0000000000 --- a/wpilibc/wpilibC++/lib/Commands/StartCommand.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Commands/StartCommand.h" - -StartCommand::StartCommand(Command *commandToStart) : - Command("StartCommand") -{ - m_commandToFork = commandToStart; -} - -void StartCommand::Initialize() -{ - m_commandToFork->Start(); -} - -void StartCommand::Execute() -{ -} - -void StartCommand::End() -{ -} - -void StartCommand::Interrupted() -{ -} - -bool StartCommand::IsFinished() -{ - return true; -} diff --git a/wpilibc/wpilibC++/lib/Commands/Subsystem.cpp b/wpilibc/wpilibC++/lib/Commands/Subsystem.cpp deleted file mode 100644 index bdc0da836d..0000000000 --- a/wpilibc/wpilibC++/lib/Commands/Subsystem.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Commands/Subsystem.h" - -#include "Commands/Command.h" -#include "Commands/Scheduler.h" -#include "WPIErrors.h" - -/** - * Creates a subsystem with the given name - * @param name the name of the subsystem - */ -Subsystem::Subsystem(const char *name) : - m_currentCommand(NULL), - m_defaultCommand(NULL), - m_initializedDefaultCommand(false) -{ - m_name = name; - Scheduler::GetInstance()->RegisterSubsystem(this); - m_table = NULL; - m_currentCommandChanged = true; -} -/** - * Initialize the default command for this subsystem - * This is meant to be the place to call SetDefaultCommand in a subsystem and will be called - * on all the subsystems by the CommandBase method before the program starts running by using - * the list of all registered Subsystems inside the Scheduler. - * - * This should be overridden by a Subsystem that has a default Command - */ -void Subsystem::InitDefaultCommand() { - -} - -/** - * Sets the default command. If this is not called or is called with null, - * then there will be no default command for the subsystem. - * - *

WARNING: This should NOT be called in a constructor if the subsystem is a - * singleton.

- * - * @param command the default command (or null if there should be none) - */ -void Subsystem::SetDefaultCommand(Command *command) -{ - if (command == NULL) - { - m_defaultCommand = NULL; - } - else - { - bool found = false; - Command::SubsystemSet requirements = command->GetRequirements(); - Command::SubsystemSet::iterator iter = requirements.begin(); - for (; iter != requirements.end(); iter++) - { - if (*iter == this) - { - found = true; - break; - } - } - - if (!found) - { - wpi_setWPIErrorWithContext(CommandIllegalUse, "A default command must require the subsystem"); - return; - } - - m_defaultCommand = command; - } - if (m_table != NULL) - { - if (m_defaultCommand != NULL) - { - m_table->PutBoolean("hasDefault", true); - m_table->PutString("default", m_defaultCommand->GetName()); - } - else - { - m_table->PutBoolean("hasDefault", false); - } - } -} - -/** - * Returns the default command (or null if there is none). - * @return the default command - */ -Command *Subsystem::GetDefaultCommand() -{ - if (!m_initializedDefaultCommand) { - m_initializedDefaultCommand = true; - InitDefaultCommand(); - } - return m_defaultCommand; -} - -/** - * Sets the current command - * @param command the new current command - */ -void Subsystem::SetCurrentCommand(Command *command) -{ - m_currentCommand = command; - m_currentCommandChanged = true; -} - -/** - * Returns the command which currently claims this subsystem. - * @return the command which currently claims this subsystem - */ -Command *Subsystem::GetCurrentCommand() -{ - return m_currentCommand; -} - -/** - * Call this to alert Subsystem that the current command is actually the command. - * Sometimes, the {@link Subsystem} is told that it has no command while the {@link Scheduler} - * is going through the loop, only to be soon after given a new one. This will avoid that situation. - */ -void Subsystem::ConfirmCommand() -{ - if (m_currentCommandChanged) { - if (m_table != NULL) - { - if (m_currentCommand != NULL) - { - m_table->PutBoolean("hasCommand", true); - m_table->PutString("command", m_currentCommand->GetName()); - } - else - { - m_table->PutBoolean("hasCommand", false); - } - } - m_currentCommandChanged = false; - } -} - - - -std::string Subsystem::GetName() -{ - return m_name; -} - -std::string Subsystem::GetSmartDashboardType() -{ - return "Subsystem"; -} - -void Subsystem::InitTable(ITable* table) -{ - m_table = table; - if(m_table!=NULL){ - if (m_defaultCommand != NULL) { - m_table->PutBoolean("hasDefault", true); - m_table->PutString("default", m_defaultCommand->GetName()); - } else { - m_table->PutBoolean("hasDefault", false); - } - if (m_currentCommand != NULL) { - m_table->PutBoolean("hasCommand", true); - m_table->PutString("command", m_currentCommand->GetName()); - } else { - m_table->PutBoolean("hasCommand", false); - } - } -} - -ITable* Subsystem::GetTable(){ - return m_table; -} diff --git a/wpilibc/wpilibC++/lib/Commands/WaitCommand.cpp b/wpilibc/wpilibC++/lib/Commands/WaitCommand.cpp deleted file mode 100644 index 508db04471..0000000000 --- a/wpilibc/wpilibC++/lib/Commands/WaitCommand.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Commands/WaitCommand.h" -#include - -WaitCommand::WaitCommand(double timeout) : - Command(((std::stringstream&)(std::stringstream("Wait(") << timeout << ")")).str().c_str(), timeout) -{ -} - -WaitCommand::WaitCommand(const char *name, double timeout) : - Command(name, timeout) -{ -} - -void WaitCommand::Initialize() -{ -} - -void WaitCommand::Execute() -{ -} - -bool WaitCommand::IsFinished() -{ - return IsTimedOut(); -} - -void WaitCommand::End() -{ -} - -void WaitCommand::Interrupted() -{ -} diff --git a/wpilibc/wpilibC++/lib/Commands/WaitForChildren.cpp b/wpilibc/wpilibC++/lib/Commands/WaitForChildren.cpp deleted file mode 100644 index e16851332c..0000000000 --- a/wpilibc/wpilibC++/lib/Commands/WaitForChildren.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Commands/WaitForChildren.h" -#include "Commands/CommandGroup.h" - -WaitForChildren::WaitForChildren(double timeout) : - Command("WaitForChildren", timeout) -{ -} - -WaitForChildren::WaitForChildren(const char *name, double timeout) : - Command(name, timeout) -{ -} - -void WaitForChildren::Initialize() -{ -} - -void WaitForChildren::Execute() -{ -} - -void WaitForChildren::End() -{ -} - -void WaitForChildren::Interrupted() -{ -} - -bool WaitForChildren::IsFinished() -{ - return GetGroup() == NULL || GetGroup()->GetSize() == 0; -} diff --git a/wpilibc/wpilibC++/lib/LiveWindow/LiveWindowStatusListener.cpp b/wpilibc/wpilibC++/lib/LiveWindow/LiveWindowStatusListener.cpp deleted file mode 100644 index 5a80f902e8..0000000000 --- a/wpilibc/wpilibC++/lib/LiveWindow/LiveWindowStatusListener.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "LiveWindow/LiveWindowStatusListener.h" -#include "Commands/Scheduler.h" - -void LiveWindowStatusListener::ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew) { - -} - diff --git a/wpilibc/wpilibC++/lib/SmartDashboard/SendableChooser.cpp b/wpilibc/wpilibC++/lib/SmartDashboard/SendableChooser.cpp deleted file mode 100644 index 7c226dc576..0000000000 --- a/wpilibc/wpilibC++/lib/SmartDashboard/SendableChooser.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "SmartDashboard/SendableChooser.h" -#include "networktables2/type/StringArray.h" - -#include - -static const char *kDefault = "default"; -static const char *kOptions = "options"; -static const char *kSelected = "selected"; - -SendableChooser::SendableChooser() -{ - m_defaultChoice = ""; -} - -/** - * Adds the given object to the list of options. On the {@link SmartDashboard} on the desktop, - * the object will appear as the given name. - * @param name the name of the option - * @param object the option - */ -void SendableChooser::AddObject(const char *name, void *object) -{ - m_choices[name] = object; -} - -/** - * Add the given object to the list of options and marks it as the default. - * Functionally, this is very close to {@link SendableChooser#AddObject(const char *name, void *object) AddObject(...)} - * except that it will use this as the default option if none other is explicitly selected. - * @param name the name of the option - * @param object the option - */ -void SendableChooser::AddDefault(const char *name, void *object) -{ - m_defaultChoice = name; - AddObject(name, object); -} - -/** - * Returns the selected option. If there is none selected, it will return the default. If there is none selected - * and no default, then it will return {@code NULL}. - * @return the option selected - */ -void *SendableChooser::GetSelected() -{ - std::string selected = m_table->GetString(kSelected, m_defaultChoice); - if (selected == "") - return NULL; - else - return m_choices[selected]; -} - -void SendableChooser::InitTable(ITable* subtable) { - StringArray keys; - m_table = subtable; - if (m_table != NULL) { - std::map::iterator iter; - for (iter = m_choices.begin(); iter != m_choices.end(); iter++) { - keys.add(iter->first); - } - m_table->PutValue(kOptions, keys); - m_table->PutString(kDefault, m_defaultChoice); - } -} - -ITable* SendableChooser::GetTable() { - return m_table; -} - -std::string SendableChooser::GetSmartDashboardType() { - return "String Chooser"; -} diff --git a/wpilibc/wpilibC++Sim/src/Buttons/Button.cpp b/wpilibc/wpilibC++/src/Buttons/Button.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Buttons/Button.cpp rename to wpilibc/wpilibC++/src/Buttons/Button.cpp diff --git a/wpilibc/wpilibC++Sim/src/Buttons/ButtonScheduler.cpp b/wpilibc/wpilibC++/src/Buttons/ButtonScheduler.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Buttons/ButtonScheduler.cpp rename to wpilibc/wpilibC++/src/Buttons/ButtonScheduler.cpp diff --git a/wpilibc/wpilibC++Sim/src/Buttons/CancelButtonScheduler.cpp b/wpilibc/wpilibC++/src/Buttons/CancelButtonScheduler.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Buttons/CancelButtonScheduler.cpp rename to wpilibc/wpilibC++/src/Buttons/CancelButtonScheduler.cpp diff --git a/wpilibc/wpilibC++Sim/src/Buttons/HeldButtonScheduler.cpp b/wpilibc/wpilibC++/src/Buttons/HeldButtonScheduler.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Buttons/HeldButtonScheduler.cpp rename to wpilibc/wpilibC++/src/Buttons/HeldButtonScheduler.cpp diff --git a/wpilibc/wpilibC++Sim/src/Buttons/InternalButton.cpp b/wpilibc/wpilibC++/src/Buttons/InternalButton.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Buttons/InternalButton.cpp rename to wpilibc/wpilibC++/src/Buttons/InternalButton.cpp diff --git a/wpilibc/wpilibC++Sim/src/Buttons/JoystickButton.cpp b/wpilibc/wpilibC++/src/Buttons/JoystickButton.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Buttons/JoystickButton.cpp rename to wpilibc/wpilibC++/src/Buttons/JoystickButton.cpp diff --git a/wpilibc/wpilibC++Sim/src/Buttons/NetworkButton.cpp b/wpilibc/wpilibC++/src/Buttons/NetworkButton.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Buttons/NetworkButton.cpp rename to wpilibc/wpilibC++/src/Buttons/NetworkButton.cpp diff --git a/wpilibc/wpilibC++Sim/src/Buttons/PressedButtonScheduler.cpp b/wpilibc/wpilibC++/src/Buttons/PressedButtonScheduler.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Buttons/PressedButtonScheduler.cpp rename to wpilibc/wpilibC++/src/Buttons/PressedButtonScheduler.cpp diff --git a/wpilibc/wpilibC++Sim/src/Buttons/ReleasedButtonScheduler.cpp b/wpilibc/wpilibC++/src/Buttons/ReleasedButtonScheduler.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Buttons/ReleasedButtonScheduler.cpp rename to wpilibc/wpilibC++/src/Buttons/ReleasedButtonScheduler.cpp diff --git a/wpilibc/wpilibC++Sim/src/Buttons/ToggleButtonScheduler.cpp b/wpilibc/wpilibC++/src/Buttons/ToggleButtonScheduler.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Buttons/ToggleButtonScheduler.cpp rename to wpilibc/wpilibC++/src/Buttons/ToggleButtonScheduler.cpp diff --git a/wpilibc/wpilibC++Sim/src/Buttons/Trigger.cpp b/wpilibc/wpilibC++/src/Buttons/Trigger.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Buttons/Trigger.cpp rename to wpilibc/wpilibC++/src/Buttons/Trigger.cpp diff --git a/wpilibc/wpilibC++/lib/Commands/Command.cpp b/wpilibc/wpilibC++/src/Commands/Command.cpp similarity index 98% rename from wpilibc/wpilibC++/lib/Commands/Command.cpp rename to wpilibc/wpilibC++/src/Commands/Command.cpp index 42adcd6b64..7ad6e45d2a 100644 --- a/wpilibc/wpilibC++/lib/Commands/Command.cpp +++ b/wpilibc/wpilibC++/src/Commands/Command.cpp @@ -7,7 +7,7 @@ #include "Commands/Command.h" #include "Commands/CommandGroup.h" #include "Commands/Scheduler.h" -#include "DriverStation.h" +#include "RobotState.h" #include "Timer.h" #include "WPIErrors.h" @@ -198,7 +198,7 @@ void Command::Start() */ bool Command::Run() { - if (!m_runWhenDisabled && m_parent == NULL && DriverStation::GetInstance()->IsDisabled()) + if (!m_runWhenDisabled && m_parent == NULL && RobotState::IsDisabled()) Cancel(); if (IsCanceled()) diff --git a/wpilibc/wpilibC++Sim/src/Commands/CommandGroup.cpp b/wpilibc/wpilibC++/src/Commands/CommandGroup.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Commands/CommandGroup.cpp rename to wpilibc/wpilibC++/src/Commands/CommandGroup.cpp diff --git a/wpilibc/wpilibC++Sim/src/Commands/CommandGroupEntry.cpp b/wpilibc/wpilibC++/src/Commands/CommandGroupEntry.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Commands/CommandGroupEntry.cpp rename to wpilibc/wpilibC++/src/Commands/CommandGroupEntry.cpp diff --git a/wpilibc/wpilibC++Sim/src/Commands/PIDCommand.cpp b/wpilibc/wpilibC++/src/Commands/PIDCommand.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Commands/PIDCommand.cpp rename to wpilibc/wpilibC++/src/Commands/PIDCommand.cpp diff --git a/wpilibc/wpilibC++/lib/Commands/PIDSubsystem.cpp b/wpilibc/wpilibC++/src/Commands/PIDSubsystem.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Commands/PIDSubsystem.cpp rename to wpilibc/wpilibC++/src/Commands/PIDSubsystem.cpp diff --git a/wpilibc/wpilibC++Sim/src/Commands/PrintCommand.cpp b/wpilibc/wpilibC++/src/Commands/PrintCommand.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Commands/PrintCommand.cpp rename to wpilibc/wpilibC++/src/Commands/PrintCommand.cpp diff --git a/wpilibc/wpilibC++Sim/src/Commands/Scheduler.cpp b/wpilibc/wpilibC++/src/Commands/Scheduler.cpp similarity index 99% rename from wpilibc/wpilibC++Sim/src/Commands/Scheduler.cpp rename to wpilibc/wpilibC++/src/Commands/Scheduler.cpp index d88b944bbf..02eb9e9515 100644 --- a/wpilibc/wpilibC++Sim/src/Commands/Scheduler.cpp +++ b/wpilibc/wpilibC++/src/Commands/Scheduler.cpp @@ -8,6 +8,7 @@ #include "Buttons/ButtonScheduler.h" #include "Commands/Subsystem.h" +#include "HLUsageReporting.h" #include "HAL/cpp/Synchronized.hpp" #include "WPIErrors.h" #include @@ -21,6 +22,8 @@ Scheduler::Scheduler() : m_buttonsLock = initializeMutexNormal(); m_additionsLock = initializeMutexNormal(); + HLUsageReporting::ReportScheduler(); + m_table = NULL; m_enabled = true; } diff --git a/wpilibc/wpilibC++Sim/src/Commands/StartCommand.cpp b/wpilibc/wpilibC++/src/Commands/StartCommand.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Commands/StartCommand.cpp rename to wpilibc/wpilibC++/src/Commands/StartCommand.cpp diff --git a/wpilibc/wpilibC++Sim/src/Commands/Subsystem.cpp b/wpilibc/wpilibC++/src/Commands/Subsystem.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Commands/Subsystem.cpp rename to wpilibc/wpilibC++/src/Commands/Subsystem.cpp diff --git a/wpilibc/wpilibC++Sim/src/Commands/WaitCommand.cpp b/wpilibc/wpilibC++/src/Commands/WaitCommand.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Commands/WaitCommand.cpp rename to wpilibc/wpilibC++/src/Commands/WaitCommand.cpp diff --git a/wpilibc/wpilibC++Sim/src/Commands/WaitForChildren.cpp b/wpilibc/wpilibC++/src/Commands/WaitForChildren.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/Commands/WaitForChildren.cpp rename to wpilibc/wpilibC++/src/Commands/WaitForChildren.cpp diff --git a/wpilibc/wpilibC++/lib/Commands/WaitUntilCommand.cpp b/wpilibc/wpilibC++/src/Commands/WaitUntilCommand.cpp similarity index 92% rename from wpilibc/wpilibC++/lib/Commands/WaitUntilCommand.cpp rename to wpilibc/wpilibC++/src/Commands/WaitUntilCommand.cpp index 3d521b8156..5eed6e42cb 100644 --- a/wpilibc/wpilibC++/lib/Commands/WaitUntilCommand.cpp +++ b/wpilibc/wpilibC++/src/Commands/WaitUntilCommand.cpp @@ -5,7 +5,6 @@ /*----------------------------------------------------------------------------*/ #include "Commands/WaitUntilCommand.h" -#include "DriverStation.h" #include "Timer.h" /** @@ -39,7 +38,7 @@ void WaitUntilCommand::Execute() */ bool WaitUntilCommand::IsFinished() { - return DriverStation::GetInstance()->GetMatchTime() >= m_time; + return Timer::GetMatchTime() >= m_time; } void WaitUntilCommand::End() diff --git a/wpilibc/wpilibC++/lib/Error.cpp b/wpilibc/wpilibC++/src/Error.cpp similarity index 93% rename from wpilibc/wpilibC++/lib/Error.cpp rename to wpilibc/wpilibC++/src/Error.cpp index 9da8924c6e..f377e22450 100644 --- a/wpilibc/wpilibC++/lib/Error.cpp +++ b/wpilibc/wpilibC++/src/Error.cpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include "HAL/Task.hpp" //#include "NetworkCommunication/FRCComm.h" #include "Timer.h" @@ -71,7 +73,7 @@ void Error::Set(Code code, const char* contextMessage, const char* filename, con Report(); - if (m_suspendOnErrorEnabled) suspendTask(0); + if (m_suspendOnErrorEnabled) suspendTask(0); } void Error::Report() @@ -87,7 +89,7 @@ void Error::Report() // Print the error and send it to the DriverStation std::cout << error << std::endl; - HALSetErrorData(error.c_str(), error.size(), 100); + // TODO: Better logging HALSetErrorData(error.c_str(), error.size(), 100); } void Error::Clear() diff --git a/wpilibc/wpilibC++/lib/ErrorBase.cpp b/wpilibc/wpilibC++/src/ErrorBase.cpp similarity index 99% rename from wpilibc/wpilibC++/lib/ErrorBase.cpp rename to wpilibc/wpilibC++/src/ErrorBase.cpp index 414c15b883..f4f26f9d07 100644 --- a/wpilibc/wpilibC++/lib/ErrorBase.cpp +++ b/wpilibc/wpilibC++/src/ErrorBase.cpp @@ -6,7 +6,6 @@ #include "ErrorBase.h" #include "HAL/cpp/Synchronized.hpp" -#include "nivision.h" #define WPI_ERRORS_DEFINE_STRINGS #include "WPIErrors.h" diff --git a/wpilibc/wpilibC++/src/HLUsageReporting.cpp b/wpilibc/wpilibC++/src/HLUsageReporting.cpp new file mode 100644 index 0000000000..c0032984b7 --- /dev/null +++ b/wpilibc/wpilibC++/src/HLUsageReporting.cpp @@ -0,0 +1,20 @@ + +#include "HLUsageReporting.h" + +HLUsageReportingInterface* HLUsageReporting::impl = 0; + +void HLUsageReporting::SetImplementation(HLUsageReportingInterface* i) { + impl = i; +} + +void HLUsageReporting::ReportScheduler() { + if (impl != 0) { + impl->ReportScheduler(); + } +} + +void HLUsageReporting::ReportSmartDashboard() { + if (impl != 0) { + impl->ReportSmartDashboard(); + } +} diff --git a/wpilibc/wpilibC++/lib/LiveWindow/LiveWindow.cpp b/wpilibc/wpilibC++/src/LiveWindow/LiveWindow.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/LiveWindow/LiveWindow.cpp rename to wpilibc/wpilibC++/src/LiveWindow/LiveWindow.cpp diff --git a/wpilibc/wpilibC++Sim/src/LiveWindow/LiveWindowStatusListener.cpp b/wpilibc/wpilibC++/src/LiveWindow/LiveWindowStatusListener.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/LiveWindow/LiveWindowStatusListener.cpp rename to wpilibc/wpilibC++/src/LiveWindow/LiveWindowStatusListener.cpp diff --git a/wpilibc/wpilibC++/lib/Resource.cpp b/wpilibc/wpilibC++/src/Resource.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Resource.cpp rename to wpilibc/wpilibC++/src/Resource.cpp diff --git a/wpilibc/wpilibC++/src/RobotState.cpp b/wpilibc/wpilibC++/src/RobotState.cpp new file mode 100644 index 0000000000..44b7e4bfb1 --- /dev/null +++ b/wpilibc/wpilibC++/src/RobotState.cpp @@ -0,0 +1,42 @@ +#include "RobotState.h" + +RobotStateInterface* RobotState::impl = 0; + +void RobotState::SetImplementation(RobotStateInterface* i) { + impl = i; +} + +bool RobotState::IsDisabled() { + if (impl != 0) { + return impl->IsDisabled(); + } + return true; +} + +bool RobotState::IsEnabled() { + if (impl != 0) { + impl->IsEnabled(); + } + return false; +} + +bool RobotState::IsOperatorControl() { + if (impl != 0) { + impl->IsOperatorControl(); + } + return true; +} + +bool RobotState::IsAutonomous() { + if (impl != 0) { + impl->IsAutonomous(); + } + return false; +} + +bool RobotState::IsTest() { + if (impl != 0) { + impl->IsTest(); + } + return false; +} diff --git a/wpilibc/wpilibC++Sim/src/SmartDashboard/SendableChooser.cpp b/wpilibc/wpilibC++/src/SmartDashboard/SendableChooser.cpp similarity index 100% rename from wpilibc/wpilibC++Sim/src/SmartDashboard/SendableChooser.cpp rename to wpilibc/wpilibC++/src/SmartDashboard/SendableChooser.cpp diff --git a/wpilibc/wpilibC++/lib/SmartDashboard/SmartDashboard.cpp b/wpilibc/wpilibC++/src/SmartDashboard/SmartDashboard.cpp similarity index 98% rename from wpilibc/wpilibC++/lib/SmartDashboard/SmartDashboard.cpp rename to wpilibc/wpilibC++/src/SmartDashboard/SmartDashboard.cpp index 4c77b83e95..da4a63af03 100644 --- a/wpilibc/wpilibC++/lib/SmartDashboard/SmartDashboard.cpp +++ b/wpilibc/wpilibC++/src/SmartDashboard/SmartDashboard.cpp @@ -10,6 +10,7 @@ #include "SmartDashboard/NamedSendable.h" #include "WPIErrors.h" #include "networktables/NetworkTable.h" +#include "HLUsageReporting.h" ITable* SmartDashboard::m_table = NULL; std::map SmartDashboard::m_tablesToData; @@ -17,7 +18,7 @@ std::map SmartDashboard::m_tablesToData; void SmartDashboard::init(){ m_table = NetworkTable::GetTable("SmartDashboard"); - HALReport(HALUsageReporting::kResourceType_SmartDashboard, 0); + HLUsageReporting::ReportSmartDashboard(); } /** diff --git a/wpilibc/wpilibC++Devices/CMakeLists.txt b/wpilibc/wpilibC++Devices/CMakeLists.txt new file mode 100644 index 0000000000..c6a510786e --- /dev/null +++ b/wpilibc/wpilibC++Devices/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 2.8) +project(WPILibC++Devices) + +file(GLOB_RECURSE SRC_FILES src/*.cpp) +include_directories(include/ ${WPILIB_INCLUDES} ${HAL_API_INCLUDES} ${NWT_API_INCLUDES}) +add_library(WPILibAthena STATIC ${SRC_FILES}) +target_link_libraries(WPILibAthena WPILib HALAthena NetworkTables ${NI_LIBS}) +INSTALL(TARGETS WPILibAthena ARCHIVE DESTINATION src COMPONENT src) +INSTALL(DIRECTORY include DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT headers) +# lib/ c m gcc_s ld-linux +# usr/lib stdc++ +# ni_emb +# HAL NWT diff --git a/wpilibc/wpilibC++/include/ADXL345_I2C.h b/wpilibc/wpilibC++Devices/include/ADXL345_I2C.h similarity index 100% rename from wpilibc/wpilibC++/include/ADXL345_I2C.h rename to wpilibc/wpilibC++Devices/include/ADXL345_I2C.h diff --git a/wpilibc/wpilibC++/include/ADXL345_SPI.h b/wpilibc/wpilibC++Devices/include/ADXL345_SPI.h similarity index 100% rename from wpilibc/wpilibC++/include/ADXL345_SPI.h rename to wpilibc/wpilibC++Devices/include/ADXL345_SPI.h diff --git a/wpilibc/wpilibC++/include/AnalogAccelerometer.h b/wpilibc/wpilibC++Devices/include/AnalogAccelerometer.h similarity index 100% rename from wpilibc/wpilibC++/include/AnalogAccelerometer.h rename to wpilibc/wpilibC++Devices/include/AnalogAccelerometer.h diff --git a/wpilibc/wpilibC++/include/AnalogInput.h b/wpilibc/wpilibC++Devices/include/AnalogInput.h similarity index 100% rename from wpilibc/wpilibC++/include/AnalogInput.h rename to wpilibc/wpilibC++Devices/include/AnalogInput.h diff --git a/wpilibc/wpilibC++/include/AnalogOutput.h b/wpilibc/wpilibC++Devices/include/AnalogOutput.h similarity index 100% rename from wpilibc/wpilibC++/include/AnalogOutput.h rename to wpilibc/wpilibC++Devices/include/AnalogOutput.h diff --git a/wpilibc/wpilibC++/include/AnalogPotentiometer.h b/wpilibc/wpilibC++Devices/include/AnalogPotentiometer.h similarity index 100% rename from wpilibc/wpilibC++/include/AnalogPotentiometer.h rename to wpilibc/wpilibC++Devices/include/AnalogPotentiometer.h diff --git a/wpilibc/wpilibC++/include/AnalogTrigger.h b/wpilibc/wpilibC++Devices/include/AnalogTrigger.h similarity index 100% rename from wpilibc/wpilibC++/include/AnalogTrigger.h rename to wpilibc/wpilibC++Devices/include/AnalogTrigger.h diff --git a/wpilibc/wpilibC++/include/AnalogTriggerOutput.h b/wpilibc/wpilibC++Devices/include/AnalogTriggerOutput.h similarity index 100% rename from wpilibc/wpilibC++/include/AnalogTriggerOutput.h rename to wpilibc/wpilibC++Devices/include/AnalogTriggerOutput.h diff --git a/wpilibc/wpilibC++/include/BuiltInAccelerometer.h b/wpilibc/wpilibC++Devices/include/BuiltInAccelerometer.h similarity index 100% rename from wpilibc/wpilibC++/include/BuiltInAccelerometer.h rename to wpilibc/wpilibC++Devices/include/BuiltInAccelerometer.h diff --git a/wpilibc/wpilibC++/include/CAN/can_proto.h b/wpilibc/wpilibC++Devices/include/CAN/can_proto.h similarity index 100% rename from wpilibc/wpilibC++/include/CAN/can_proto.h rename to wpilibc/wpilibC++Devices/include/CAN/can_proto.h diff --git a/wpilibc/wpilibC++/include/CANJaguar.h b/wpilibc/wpilibC++Devices/include/CANJaguar.h similarity index 100% rename from wpilibc/wpilibC++/include/CANJaguar.h rename to wpilibc/wpilibC++Devices/include/CANJaguar.h diff --git a/wpilibc/wpilibC++/include/Compressor.h b/wpilibc/wpilibC++Devices/include/Compressor.h similarity index 100% rename from wpilibc/wpilibC++/include/Compressor.h rename to wpilibc/wpilibC++Devices/include/Compressor.h diff --git a/wpilibc/wpilibC++/include/Counter.h b/wpilibc/wpilibC++Devices/include/Counter.h similarity index 100% rename from wpilibc/wpilibC++/include/Counter.h rename to wpilibc/wpilibC++Devices/include/Counter.h diff --git a/wpilibc/wpilibC++/include/CounterBase.h b/wpilibc/wpilibC++Devices/include/CounterBase.h similarity index 100% rename from wpilibc/wpilibC++/include/CounterBase.h rename to wpilibc/wpilibC++Devices/include/CounterBase.h diff --git a/wpilibc/wpilibC++/include/DigitalInput.h b/wpilibc/wpilibC++Devices/include/DigitalInput.h similarity index 100% rename from wpilibc/wpilibC++/include/DigitalInput.h rename to wpilibc/wpilibC++Devices/include/DigitalInput.h diff --git a/wpilibc/wpilibC++/include/DigitalOutput.h b/wpilibc/wpilibC++Devices/include/DigitalOutput.h similarity index 100% rename from wpilibc/wpilibC++/include/DigitalOutput.h rename to wpilibc/wpilibC++Devices/include/DigitalOutput.h diff --git a/wpilibc/wpilibC++/include/DigitalSource.h b/wpilibc/wpilibC++Devices/include/DigitalSource.h similarity index 100% rename from wpilibc/wpilibC++/include/DigitalSource.h rename to wpilibc/wpilibC++Devices/include/DigitalSource.h diff --git a/wpilibc/wpilibC++/include/DoubleSolenoid.h b/wpilibc/wpilibC++Devices/include/DoubleSolenoid.h similarity index 100% rename from wpilibc/wpilibC++/include/DoubleSolenoid.h rename to wpilibc/wpilibC++Devices/include/DoubleSolenoid.h diff --git a/wpilibc/wpilibC++/include/DriverStation.h b/wpilibc/wpilibC++Devices/include/DriverStation.h similarity index 96% rename from wpilibc/wpilibC++/include/DriverStation.h rename to wpilibc/wpilibC++Devices/include/DriverStation.h index 5123f08c0d..6afe4a6f10 100644 --- a/wpilibc/wpilibC++/include/DriverStation.h +++ b/wpilibc/wpilibC++Devices/include/DriverStation.h @@ -6,6 +6,7 @@ #pragma once #include "SensorBase.h" +#include "RobotState.h" #include "Task.h" struct HALControlWord; @@ -14,7 +15,7 @@ class AnalogInput; /** * Provide access to the network communication data to / from the Driver Station. */ -class DriverStation : public SensorBase +class DriverStation : public SensorBase, public RobotStateInterface { public: enum Alliance @@ -90,7 +91,6 @@ protected: private: static void InitTask(DriverStation *ds); static DriverStation *m_instance; - static uint8_t m_updateNumber; void Run(); @@ -99,7 +99,6 @@ private: HALJoystickAxes m_joystickAxes[kJoystickPorts]; HALJoystickButtons m_joystickButtons[kJoystickPorts]; - uint8_t m_digitalOut; MUTEX_ID m_statusDataSemaphore; Task m_task; SEMAPHORE_ID m_newControlData; diff --git a/wpilibc/wpilibC++/include/Encoder.h b/wpilibc/wpilibC++Devices/include/Encoder.h similarity index 100% rename from wpilibc/wpilibC++/include/Encoder.h rename to wpilibc/wpilibC++Devices/include/Encoder.h diff --git a/wpilibc/wpilibC++/include/GearTooth.h b/wpilibc/wpilibC++Devices/include/GearTooth.h similarity index 100% rename from wpilibc/wpilibC++/include/GearTooth.h rename to wpilibc/wpilibC++Devices/include/GearTooth.h diff --git a/wpilibc/wpilibC++/include/Gyro.h b/wpilibc/wpilibC++Devices/include/Gyro.h similarity index 100% rename from wpilibc/wpilibC++/include/Gyro.h rename to wpilibc/wpilibC++Devices/include/Gyro.h diff --git a/wpilibc/wpilibC++/include/I2C.h b/wpilibc/wpilibC++Devices/include/I2C.h similarity index 100% rename from wpilibc/wpilibC++/include/I2C.h rename to wpilibc/wpilibC++Devices/include/I2C.h diff --git a/wpilibc/wpilibC++Devices/include/Internal/HardwareHLReporting.h b/wpilibc/wpilibC++Devices/include/Internal/HardwareHLReporting.h new file mode 100644 index 0000000000..aa7ebc8dd9 --- /dev/null +++ b/wpilibc/wpilibC++Devices/include/Internal/HardwareHLReporting.h @@ -0,0 +1,9 @@ + +#include "HLUsageReporting.h" + +class HardwareHLReporting : public HLUsageReportingInterface +{ +public: + virtual void ReportScheduler(); + virtual void ReportSmartDashboard(); +}; diff --git a/wpilibc/wpilibC++/include/InterruptableSensorBase.h b/wpilibc/wpilibC++Devices/include/InterruptableSensorBase.h similarity index 100% rename from wpilibc/wpilibC++/include/InterruptableSensorBase.h rename to wpilibc/wpilibC++Devices/include/InterruptableSensorBase.h diff --git a/wpilibc/wpilibC++/include/IterativeRobot.h b/wpilibc/wpilibC++Devices/include/IterativeRobot.h similarity index 100% rename from wpilibc/wpilibC++/include/IterativeRobot.h rename to wpilibc/wpilibC++Devices/include/IterativeRobot.h diff --git a/wpilibc/wpilibC++/include/Jaguar.h b/wpilibc/wpilibC++Devices/include/Jaguar.h similarity index 100% rename from wpilibc/wpilibC++/include/Jaguar.h rename to wpilibc/wpilibC++Devices/include/Jaguar.h diff --git a/wpilibc/wpilibC++/include/Joystick.h b/wpilibc/wpilibC++Devices/include/Joystick.h similarity index 100% rename from wpilibc/wpilibC++/include/Joystick.h rename to wpilibc/wpilibC++Devices/include/Joystick.h diff --git a/wpilibc/wpilibC++/include/MotorSafety.h b/wpilibc/wpilibC++Devices/include/MotorSafety.h similarity index 100% rename from wpilibc/wpilibC++/include/MotorSafety.h rename to wpilibc/wpilibC++Devices/include/MotorSafety.h diff --git a/wpilibc/wpilibC++/include/MotorSafetyHelper.h b/wpilibc/wpilibC++Devices/include/MotorSafetyHelper.h similarity index 100% rename from wpilibc/wpilibC++/include/MotorSafetyHelper.h rename to wpilibc/wpilibC++Devices/include/MotorSafetyHelper.h diff --git a/wpilibc/wpilibC++/include/NetworkCommunication/AICalibration.h b/wpilibc/wpilibC++Devices/include/NetworkCommunication/AICalibration.h similarity index 100% rename from wpilibc/wpilibC++/include/NetworkCommunication/AICalibration.h rename to wpilibc/wpilibC++Devices/include/NetworkCommunication/AICalibration.h diff --git a/wpilibc/wpilibC++/include/NetworkCommunication/CANInterfacePlugin.h b/wpilibc/wpilibC++Devices/include/NetworkCommunication/CANInterfacePlugin.h similarity index 100% rename from wpilibc/wpilibC++/include/NetworkCommunication/CANInterfacePlugin.h rename to wpilibc/wpilibC++Devices/include/NetworkCommunication/CANInterfacePlugin.h diff --git a/wpilibc/wpilibC++/include/NetworkCommunication/CANSessionMux.h b/wpilibc/wpilibC++Devices/include/NetworkCommunication/CANSessionMux.h similarity index 100% rename from wpilibc/wpilibC++/include/NetworkCommunication/CANSessionMux.h rename to wpilibc/wpilibC++Devices/include/NetworkCommunication/CANSessionMux.h diff --git a/wpilibc/wpilibC++/include/NetworkCommunication/FRCComm.h b/wpilibc/wpilibC++Devices/include/NetworkCommunication/FRCComm.h similarity index 100% rename from wpilibc/wpilibC++/include/NetworkCommunication/FRCComm.h rename to wpilibc/wpilibC++Devices/include/NetworkCommunication/FRCComm.h diff --git a/wpilibc/wpilibC++/include/NetworkCommunication/LoadOut.h b/wpilibc/wpilibC++Devices/include/NetworkCommunication/LoadOut.h similarity index 100% rename from wpilibc/wpilibC++/include/NetworkCommunication/LoadOut.h rename to wpilibc/wpilibC++Devices/include/NetworkCommunication/LoadOut.h diff --git a/wpilibc/wpilibC++/include/NetworkCommunication/UsageReporting.h b/wpilibc/wpilibC++Devices/include/NetworkCommunication/UsageReporting.h similarity index 100% rename from wpilibc/wpilibC++/include/NetworkCommunication/UsageReporting.h rename to wpilibc/wpilibC++Devices/include/NetworkCommunication/UsageReporting.h diff --git a/wpilibc/wpilibC++/include/NetworkCommunication/symModuleLink.h b/wpilibc/wpilibC++Devices/include/NetworkCommunication/symModuleLink.h similarity index 100% rename from wpilibc/wpilibC++/include/NetworkCommunication/symModuleLink.h rename to wpilibc/wpilibC++Devices/include/NetworkCommunication/symModuleLink.h diff --git a/wpilibc/wpilibC++Devices/include/Notifier.h b/wpilibc/wpilibC++Devices/include/Notifier.h new file mode 100644 index 0000000000..ad969360b1 --- /dev/null +++ b/wpilibc/wpilibC++Devices/include/Notifier.h @@ -0,0 +1,42 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2008. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ +/*----------------------------------------------------------------------------*/ +#pragma once + +#include "HAL/HAL.hpp" +#include "ErrorBase.h" +#include "HAL/cpp/Synchronized.hpp" + +typedef void (*TimerEventHandler)(void *param); + +class Notifier : public ErrorBase +{ +public: + Notifier(TimerEventHandler handler, void *param = NULL); + virtual ~Notifier(); + void StartSingle(double delay); + void StartPeriodic(double period); + void Stop(); +private: + static Notifier *timerQueueHead; + static ReentrantSemaphore queueSemaphore; + static void* m_notifier; + static int refcount; + + static void ProcessQueue(uint32_t mask, void *params); // process the timer queue on a timer event + static void UpdateAlarm(); // update the FPGA alarm since the queue has changed + void InsertInQueue(bool reschedule); // insert this Notifier in the timer queue + void DeleteFromQueue(); // delete this Notifier from the timer queue + TimerEventHandler m_handler; // address of the handler + void *m_param; // a parameter to pass to the handler + double m_period; // the relative time (either periodic or single) + double m_expirationTime; // absolute expiration time for the current event + Notifier *m_nextEvent; // next Nofifier event + bool m_periodic; // true if this is a periodic event + bool m_queued; // indicates if this entry is queued + SEMAPHORE_ID m_handlerSemaphore; // held by interrupt manager task while handler call is in progress + + DISALLOW_COPY_AND_ASSIGN(Notifier); +}; diff --git a/wpilibc/wpilibC++Devices/include/PIDController.h b/wpilibc/wpilibC++Devices/include/PIDController.h new file mode 100644 index 0000000000..ea96791dc3 --- /dev/null +++ b/wpilibc/wpilibC++Devices/include/PIDController.h @@ -0,0 +1,108 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2008. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ +/*----------------------------------------------------------------------------*/ +#pragma once + +#include "Base.h" +#include "Controller.h" +#include "LiveWindow/LiveWindow.h" +#include + +class PIDOutput; +class PIDSource; +class Notifier; + +/** + * Class implements a PID Control Loop. + * + * Creates a separate thread which reads the given PIDSource and takes + * care of the integral calculations, as well as writing the given + * PIDOutput + */ +class PIDController : public LiveWindowSendable, public Controller, public ITableListener +{ +public: + PIDController(float p, float i, float d, PIDSource *source, PIDOutput *output, float period = + 0.05); + PIDController(float p, float i, float d, float f, PIDSource *source, PIDOutput *output, + float period = 0.05); + virtual ~PIDController(); + virtual float Get(); + virtual void SetContinuous(bool continuous = true); + virtual void SetInputRange(float minimumInput, float maximumInput); + virtual void SetOutputRange(float mimimumOutput, float maximumOutput); + virtual void SetPID(float p, float i, float d); + virtual void SetPID(float p, float i, float d, float f); + virtual float GetP(); + virtual float GetI(); + virtual float GetD(); + virtual float GetF(); + + virtual void SetSetpoint(float setpoint); + virtual float GetSetpoint(); + + virtual float GetError(); + + virtual void SetTolerance(float percent); + virtual void SetAbsoluteTolerance(float absValue); + virtual void SetPercentTolerance(float percentValue); + virtual bool OnTarget(); + + virtual void Enable(); + virtual void Disable(); + virtual bool IsEnabled(); + + virtual void Reset(); + + virtual void InitTable(ITable* table); + +private: + float m_P; // factor for "proportional" control + float m_I; // factor for "integral" control + float m_D; // factor for "derivative" control + float m_F; // factor for "feed forward" control + float m_maximumOutput; // |maximum output| + float m_minimumOutput; // |minimum output| + float m_maximumInput; // maximum input - limit setpoint to this + float m_minimumInput; // minimum input - limit setpoint to this + bool m_continuous; // do the endpoints wrap around? eg. Absolute encoder + bool m_enabled; //is the pid controller enabled + bool m_destruct; // should the calculate thread stop running + float m_prevError; // the prior sensor input (used to compute velocity) + double m_totalError; //the sum of the errors for use in the integral calc + enum + { + kAbsoluteTolerance, + kPercentTolerance, + kNoTolerance + } m_toleranceType; + float m_tolerance; //the percetage or absolute error that is considered on target + float m_setpoint; + float m_error; + float m_result; + float m_period; + + PIDSource *m_pidInput; + PIDOutput *m_pidOutput; + + pthread_t m_controlLoop; + pthread_mutex_t m_mutex; + + void Initialize(float p, float i, float d, float f, PIDSource *source, PIDOutput *output, + float period = 0.05); + static void *CallCalculate(void *controller); + + virtual ITable* GetTable(); + virtual std::string GetSmartDashboardType(); + virtual void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew); + virtual void UpdateTable(); + virtual void StartLiveWindowMode(); + virtual void StopLiveWindowMode(); +protected: + ITable* m_table; + void Calculate(); + + DISALLOW_COPY_AND_ASSIGN(PIDController); +}; diff --git a/wpilibc/wpilibC++/include/PWM.h b/wpilibc/wpilibC++Devices/include/PWM.h similarity index 100% rename from wpilibc/wpilibC++/include/PWM.h rename to wpilibc/wpilibC++Devices/include/PWM.h diff --git a/wpilibc/wpilibC++/include/PowerDistributionPanel.h b/wpilibc/wpilibC++Devices/include/PowerDistributionPanel.h similarity index 100% rename from wpilibc/wpilibC++/include/PowerDistributionPanel.h rename to wpilibc/wpilibC++Devices/include/PowerDistributionPanel.h diff --git a/wpilibc/wpilibC++/include/Preferences.h b/wpilibc/wpilibC++Devices/include/Preferences.h similarity index 100% rename from wpilibc/wpilibC++/include/Preferences.h rename to wpilibc/wpilibC++Devices/include/Preferences.h diff --git a/wpilibc/wpilibC++/include/Relay.h b/wpilibc/wpilibC++Devices/include/Relay.h similarity index 100% rename from wpilibc/wpilibC++/include/Relay.h rename to wpilibc/wpilibC++Devices/include/Relay.h diff --git a/wpilibc/wpilibC++/include/RobotBase.h b/wpilibc/wpilibC++Devices/include/RobotBase.h similarity index 100% rename from wpilibc/wpilibC++/include/RobotBase.h rename to wpilibc/wpilibC++Devices/include/RobotBase.h diff --git a/wpilibc/wpilibC++/include/RobotDrive.h b/wpilibc/wpilibC++Devices/include/RobotDrive.h similarity index 100% rename from wpilibc/wpilibC++/include/RobotDrive.h rename to wpilibc/wpilibC++Devices/include/RobotDrive.h diff --git a/wpilibc/wpilibC++/include/SPI.h b/wpilibc/wpilibC++Devices/include/SPI.h similarity index 100% rename from wpilibc/wpilibC++/include/SPI.h rename to wpilibc/wpilibC++Devices/include/SPI.h diff --git a/wpilibc/wpilibC++/include/SafePWM.h b/wpilibc/wpilibC++Devices/include/SafePWM.h similarity index 100% rename from wpilibc/wpilibC++/include/SafePWM.h rename to wpilibc/wpilibC++Devices/include/SafePWM.h diff --git a/wpilibc/wpilibC++/include/SampleRobot.h b/wpilibc/wpilibC++Devices/include/SampleRobot.h similarity index 100% rename from wpilibc/wpilibC++/include/SampleRobot.h rename to wpilibc/wpilibC++Devices/include/SampleRobot.h diff --git a/wpilibc/wpilibC++/include/SerialPort.h b/wpilibc/wpilibC++Devices/include/SerialPort.h similarity index 100% rename from wpilibc/wpilibC++/include/SerialPort.h rename to wpilibc/wpilibC++Devices/include/SerialPort.h diff --git a/wpilibc/wpilibC++/include/Servo.h b/wpilibc/wpilibC++Devices/include/Servo.h similarity index 100% rename from wpilibc/wpilibC++/include/Servo.h rename to wpilibc/wpilibC++Devices/include/Servo.h diff --git a/wpilibc/wpilibC++/include/Solenoid.h b/wpilibc/wpilibC++Devices/include/Solenoid.h similarity index 100% rename from wpilibc/wpilibC++/include/Solenoid.h rename to wpilibc/wpilibC++Devices/include/Solenoid.h diff --git a/wpilibc/wpilibC++/include/SolenoidBase.h b/wpilibc/wpilibC++Devices/include/SolenoidBase.h similarity index 100% rename from wpilibc/wpilibC++/include/SolenoidBase.h rename to wpilibc/wpilibC++Devices/include/SolenoidBase.h diff --git a/wpilibc/wpilibC++/include/SpeedController.h b/wpilibc/wpilibC++Devices/include/SpeedController.h similarity index 100% rename from wpilibc/wpilibC++/include/SpeedController.h rename to wpilibc/wpilibC++Devices/include/SpeedController.h diff --git a/wpilibc/wpilibC++/include/Talon.h b/wpilibc/wpilibC++Devices/include/Talon.h similarity index 100% rename from wpilibc/wpilibC++/include/Talon.h rename to wpilibc/wpilibC++Devices/include/Talon.h diff --git a/wpilibc/wpilibC++Devices/include/Task.h b/wpilibc/wpilibC++Devices/include/Task.h new file mode 100644 index 0000000000..7377c9ecfa --- /dev/null +++ b/wpilibc/wpilibC++Devices/include/Task.h @@ -0,0 +1,52 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2008. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ +/*----------------------------------------------------------------------------*/ +#pragma once + +#include "ErrorBase.h" +#include "HAL/HAL.hpp" + +/** + * WPI task is a wrapper for the native Task object. + * All WPILib tasks are managed by a static task manager for simplified cleanup. + **/ +class Task : public ErrorBase +{ +public: + static const uint32_t kDefaultPriority = 101; + + Task(const char* name, FUNCPTR function, int32_t priority = kDefaultPriority, + uint32_t stackSize = 20000); + virtual ~Task(); + + bool Start(uint32_t arg0 = 0, uint32_t arg1 = 0, uint32_t arg2 = 0, uint32_t arg3 = 0, + uint32_t arg4 = 0, uint32_t arg5 = 0, uint32_t arg6 = 0, uint32_t arg7 = 0, + uint32_t arg8 = 0, uint32_t arg9 = 0); + bool Restart(); + bool Stop(); + + bool IsReady(); + bool IsSuspended(); + + bool Suspend(); + bool Resume(); + + bool Verify(); + + int32_t GetPriority(); + bool SetPriority(int32_t priority); + const char* GetName(); + TASK GetID(); + +private: + FUNCPTR m_function; + char* m_taskName; + TASK m_taskID; + uint32_t m_stackSize; + int m_priority; + bool HandleError(STATUS results); + DISALLOW_COPY_AND_ASSIGN(Task); +}; + diff --git a/wpilibc/wpilibC++Devices/include/Timer.h b/wpilibc/wpilibC++Devices/include/Timer.h new file mode 100644 index 0000000000..67d574f2d3 --- /dev/null +++ b/wpilibc/wpilibC++Devices/include/Timer.h @@ -0,0 +1,44 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2008. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ +/*----------------------------------------------------------------------------*/ +#pragma once + +#include "HAL/Semaphore.hpp" +#include "Base.h" + +typedef void (*TimerInterruptHandler)(void *param); + +void Wait(double seconds); +double GetClock(); +double GetTime(); + +/** + * Timer objects measure accumulated time in seconds. + * The timer object functions like a stopwatch. It can be started, stopped, and cleared. When the + * timer is running its value counts up in seconds. When stopped, the timer holds the current + * value. The implementation simply records the time when started and subtracts the current time + * whenever the value is requested. + */ +class Timer +{ +public: + Timer(); + virtual ~Timer(); + double Get(); + void Reset(); + void Start(); + void Stop(); + bool HasPeriodPassed(double period); + + static double GetFPGATimestamp(); + static double GetPPCTimestamp(); + +private: + double m_startTime; + double m_accumulatedTime; + bool m_running; + MUTEX_ID m_semaphore; + DISALLOW_COPY_AND_ASSIGN(Timer); +}; diff --git a/wpilibc/wpilibC++/include/Ultrasonic.h b/wpilibc/wpilibC++Devices/include/Ultrasonic.h similarity index 100% rename from wpilibc/wpilibC++/include/Ultrasonic.h rename to wpilibc/wpilibC++Devices/include/Ultrasonic.h diff --git a/wpilibc/wpilibC++/include/Victor.h b/wpilibc/wpilibC++Devices/include/Victor.h similarity index 100% rename from wpilibc/wpilibC++/include/Victor.h rename to wpilibc/wpilibC++Devices/include/Victor.h diff --git a/wpilibc/wpilibC++/include/WPILib.h b/wpilibc/wpilibC++Devices/include/WPILib.h similarity index 100% rename from wpilibc/wpilibC++/include/WPILib.h rename to wpilibc/wpilibC++Devices/include/WPILib.h diff --git a/wpilibc/wpilibC++/include/nivision.h b/wpilibc/wpilibC++Devices/include/nivision.h similarity index 100% rename from wpilibc/wpilibC++/include/nivision.h rename to wpilibc/wpilibC++Devices/include/nivision.h diff --git a/wpilibc/wpilibC++/include/pcre.h b/wpilibc/wpilibC++Devices/include/pcre.h similarity index 100% rename from wpilibc/wpilibC++/include/pcre.h rename to wpilibc/wpilibC++Devices/include/pcre.h diff --git a/wpilibc/wpilibC++/include/visa/visa.h b/wpilibc/wpilibC++Devices/include/visa/visa.h similarity index 100% rename from wpilibc/wpilibC++/include/visa/visa.h rename to wpilibc/wpilibC++Devices/include/visa/visa.h diff --git a/wpilibc/wpilibC++/include/visa/visatype.h b/wpilibc/wpilibC++Devices/include/visa/visatype.h similarity index 100% rename from wpilibc/wpilibC++/include/visa/visatype.h rename to wpilibc/wpilibC++Devices/include/visa/visatype.h diff --git a/wpilibc/wpilibC++/lib/ADXL345_I2C.cpp b/wpilibc/wpilibC++Devices/src/ADXL345_I2C.cpp similarity index 97% rename from wpilibc/wpilibC++/lib/ADXL345_I2C.cpp rename to wpilibc/wpilibC++Devices/src/ADXL345_I2C.cpp index 9d6593aed5..2e5fdd560c 100644 --- a/wpilibc/wpilibC++/lib/ADXL345_I2C.cpp +++ b/wpilibc/wpilibC++Devices/src/ADXL345_I2C.cpp @@ -5,8 +5,8 @@ /*----------------------------------------------------------------------------*/ #include "ADXL345_I2C.h" -//#include "NetworkCommunication/UsageReporting.h" #include "I2C.h" +#include "HAL/HAL.hpp" const uint8_t ADXL345_I2C::kAddress; const uint8_t ADXL345_I2C::kPowerCtlRegister; diff --git a/wpilibc/wpilibC++/lib/ADXL345_SPI.cpp b/wpilibc/wpilibC++Devices/src/ADXL345_SPI.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/ADXL345_SPI.cpp rename to wpilibc/wpilibC++Devices/src/ADXL345_SPI.cpp diff --git a/wpilibc/wpilibC++/lib/AnalogAccelerometer.cpp b/wpilibc/wpilibC++Devices/src/AnalogAccelerometer.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/AnalogAccelerometer.cpp rename to wpilibc/wpilibC++Devices/src/AnalogAccelerometer.cpp diff --git a/wpilibc/wpilibC++/lib/AnalogInput.cpp b/wpilibc/wpilibC++Devices/src/AnalogInput.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/AnalogInput.cpp rename to wpilibc/wpilibC++Devices/src/AnalogInput.cpp diff --git a/wpilibc/wpilibC++/lib/AnalogOutput.cpp b/wpilibc/wpilibC++Devices/src/AnalogOutput.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/AnalogOutput.cpp rename to wpilibc/wpilibC++Devices/src/AnalogOutput.cpp diff --git a/wpilibc/wpilibC++/lib/AnalogPotentiometer.cpp b/wpilibc/wpilibC++Devices/src/AnalogPotentiometer.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/AnalogPotentiometer.cpp rename to wpilibc/wpilibC++Devices/src/AnalogPotentiometer.cpp diff --git a/wpilibc/wpilibC++/lib/AnalogTrigger.cpp b/wpilibc/wpilibC++Devices/src/AnalogTrigger.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/AnalogTrigger.cpp rename to wpilibc/wpilibC++Devices/src/AnalogTrigger.cpp diff --git a/wpilibc/wpilibC++/lib/AnalogTriggerOutput.cpp b/wpilibc/wpilibC++Devices/src/AnalogTriggerOutput.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/AnalogTriggerOutput.cpp rename to wpilibc/wpilibC++Devices/src/AnalogTriggerOutput.cpp diff --git a/wpilibc/wpilibC++/lib/BuiltInAccelerometer.cpp b/wpilibc/wpilibC++Devices/src/BuiltInAccelerometer.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/BuiltInAccelerometer.cpp rename to wpilibc/wpilibC++Devices/src/BuiltInAccelerometer.cpp diff --git a/wpilibc/wpilibC++/lib/CANJaguar.cpp b/wpilibc/wpilibC++Devices/src/CANJaguar.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/CANJaguar.cpp rename to wpilibc/wpilibC++Devices/src/CANJaguar.cpp diff --git a/wpilibc/wpilibC++/lib/Compressor.cpp b/wpilibc/wpilibC++Devices/src/Compressor.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Compressor.cpp rename to wpilibc/wpilibC++Devices/src/Compressor.cpp diff --git a/wpilibc/wpilibC++/lib/Counter.cpp b/wpilibc/wpilibC++Devices/src/Counter.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Counter.cpp rename to wpilibc/wpilibC++Devices/src/Counter.cpp diff --git a/wpilibc/wpilibC++/lib/DigitalInput.cpp b/wpilibc/wpilibC++Devices/src/DigitalInput.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/DigitalInput.cpp rename to wpilibc/wpilibC++Devices/src/DigitalInput.cpp diff --git a/wpilibc/wpilibC++/lib/DigitalOutput.cpp b/wpilibc/wpilibC++Devices/src/DigitalOutput.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/DigitalOutput.cpp rename to wpilibc/wpilibC++Devices/src/DigitalOutput.cpp diff --git a/wpilibc/wpilibC++/lib/DigitalSource.cpp b/wpilibc/wpilibC++Devices/src/DigitalSource.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/DigitalSource.cpp rename to wpilibc/wpilibC++Devices/src/DigitalSource.cpp diff --git a/wpilibc/wpilibC++/lib/DoubleSolenoid.cpp b/wpilibc/wpilibC++Devices/src/DoubleSolenoid.cpp similarity index 99% rename from wpilibc/wpilibC++/lib/DoubleSolenoid.cpp rename to wpilibc/wpilibC++Devices/src/DoubleSolenoid.cpp index 3b6adc8330..e2587e305d 100644 --- a/wpilibc/wpilibC++/lib/DoubleSolenoid.cpp +++ b/wpilibc/wpilibC++Devices/src/DoubleSolenoid.cpp @@ -49,10 +49,9 @@ void DoubleSolenoid::InitSolenoid() CloneError(m_allocated); return; } - + m_forwardMask = 1 << m_forwardChannel; m_reverseMask = 1 << m_reverseChannel; - HALReport(HALUsageReporting::kResourceType_Solenoid, m_forwardChannel, m_moduleNumber); HALReport(HALUsageReporting::kResourceType_Solenoid, m_reverseChannel, m_moduleNumber); LiveWindow::GetInstance()->AddActuator("DoubleSolenoid", m_moduleNumber, m_forwardChannel, this); diff --git a/wpilibc/wpilibC++/lib/DriverStation.cpp b/wpilibc/wpilibC++Devices/src/DriverStation.cpp similarity index 97% rename from wpilibc/wpilibC++/lib/DriverStation.cpp rename to wpilibc/wpilibC++Devices/src/DriverStation.cpp index edec06d977..beda69ebad 100644 --- a/wpilibc/wpilibC++/lib/DriverStation.cpp +++ b/wpilibc/wpilibC++Devices/src/DriverStation.cpp @@ -8,6 +8,8 @@ #include "AnalogInput.h" #include "HAL/cpp/Synchronized.hpp" #include "Timer.h" +#include "NetworkCommunication/FRCComm.h" +#include "NetworkCommunication/UsageReporting.h" #include "MotorSafetyHelper.h" #include "Utility.h" #include "WPIErrors.h" @@ -31,8 +33,7 @@ DriverStation* DriverStation::m_instance = NULL; * This is only called once the first time GetInstance() is called */ DriverStation::DriverStation() - : m_digitalOut (0) - , m_statusDataSemaphore (initializeMutexNormal()) + : m_statusDataSemaphore (initializeMutexNormal()) , m_task ("DriverStation", (FUNCPTR)DriverStation::InitTask) , m_newControlData(0) , m_packetDataAvailableSem (0) @@ -43,6 +44,8 @@ DriverStation::DriverStation() , m_userInTeleop(false) , m_userInTest(false) { + memset(&m_controlWord, 0, sizeof(m_controlWord)); + // Create a new semaphore m_packetDataAvailableSem = initializeMutexNormal(); m_newControlData = initializeSemaphore(SEMAPHORE_EMPTY); diff --git a/wpilibc/wpilibC++/lib/Encoder.cpp b/wpilibc/wpilibC++Devices/src/Encoder.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Encoder.cpp rename to wpilibc/wpilibC++Devices/src/Encoder.cpp diff --git a/wpilibc/wpilibC++/lib/GearTooth.cpp b/wpilibc/wpilibC++Devices/src/GearTooth.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/GearTooth.cpp rename to wpilibc/wpilibC++Devices/src/GearTooth.cpp diff --git a/wpilibc/wpilibC++/lib/Gyro.cpp b/wpilibc/wpilibC++Devices/src/Gyro.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Gyro.cpp rename to wpilibc/wpilibC++Devices/src/Gyro.cpp diff --git a/wpilibc/wpilibC++/lib/I2C.cpp b/wpilibc/wpilibC++Devices/src/I2C.cpp similarity index 99% rename from wpilibc/wpilibC++/lib/I2C.cpp rename to wpilibc/wpilibC++Devices/src/I2C.cpp index 12551e24e7..fd07d83552 100644 --- a/wpilibc/wpilibC++/lib/I2C.cpp +++ b/wpilibc/wpilibC++Devices/src/I2C.cpp @@ -5,7 +5,7 @@ /*----------------------------------------------------------------------------*/ #include "I2C.h" -//#include "NetworkCommunication/UsageReporting.h" +#include "HAL/HAL.hpp" #include "HAL/Digital.hpp" #include "WPIErrors.h" diff --git a/wpilibc/wpilibC++Devices/src/Internal/HardwareHLReporting.cpp b/wpilibc/wpilibC++Devices/src/Internal/HardwareHLReporting.cpp new file mode 100644 index 0000000000..9c21b7a0fa --- /dev/null +++ b/wpilibc/wpilibC++Devices/src/Internal/HardwareHLReporting.cpp @@ -0,0 +1,12 @@ + +#include "Internal/HardwareHLReporting.h" +#include "HAL/HAL.hpp" + +void HardwareHLReporting::ReportScheduler() { + HALReport(HALUsageReporting::kResourceType_Command, + HALUsageReporting::kCommand_Scheduler); +} + +void HardwareHLReporting::ReportSmartDashboard() { + HALReport(HALUsageReporting::kResourceType_SmartDashboard, 0); +} diff --git a/wpilibc/wpilibC++/lib/InterruptableSensorBase.cpp b/wpilibc/wpilibC++Devices/src/InterruptableSensorBase.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/InterruptableSensorBase.cpp rename to wpilibc/wpilibC++Devices/src/InterruptableSensorBase.cpp diff --git a/wpilibc/wpilibC++/lib/IterativeRobot.cpp b/wpilibc/wpilibC++Devices/src/IterativeRobot.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/IterativeRobot.cpp rename to wpilibc/wpilibC++Devices/src/IterativeRobot.cpp diff --git a/wpilibc/wpilibC++/lib/Jaguar.cpp b/wpilibc/wpilibC++Devices/src/Jaguar.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Jaguar.cpp rename to wpilibc/wpilibC++Devices/src/Jaguar.cpp diff --git a/wpilibc/wpilibC++/lib/Joystick.cpp b/wpilibc/wpilibC++Devices/src/Joystick.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Joystick.cpp rename to wpilibc/wpilibC++Devices/src/Joystick.cpp diff --git a/wpilibc/wpilibC++/lib/MotorSafetyHelper.cpp b/wpilibc/wpilibC++Devices/src/MotorSafetyHelper.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/MotorSafetyHelper.cpp rename to wpilibc/wpilibC++Devices/src/MotorSafetyHelper.cpp diff --git a/wpilibc/wpilibC++/lib/Notifier.cpp b/wpilibc/wpilibC++Devices/src/Notifier.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Notifier.cpp rename to wpilibc/wpilibC++Devices/src/Notifier.cpp diff --git a/wpilibc/wpilibC++/lib/PIDController.cpp b/wpilibc/wpilibC++Devices/src/PIDController.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/PIDController.cpp rename to wpilibc/wpilibC++Devices/src/PIDController.cpp diff --git a/wpilibc/wpilibC++/lib/PWM.cpp b/wpilibc/wpilibC++Devices/src/PWM.cpp similarity index 99% rename from wpilibc/wpilibC++/lib/PWM.cpp rename to wpilibc/wpilibC++Devices/src/PWM.cpp index a9b0b018c9..3391990450 100644 --- a/wpilibc/wpilibC++/lib/PWM.cpp +++ b/wpilibc/wpilibC++Devices/src/PWM.cpp @@ -10,6 +10,7 @@ #include "Resource.h" #include "Utility.h" #include "WPIErrors.h" +#include "HAL/HAL.hpp" constexpr float PWM::kDefaultPwmPeriod; constexpr float PWM::kDefaultPwmCenter; diff --git a/wpilibc/wpilibC++/lib/PowerDistributionPanel.cpp b/wpilibc/wpilibC++Devices/src/PowerDistributionPanel.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/PowerDistributionPanel.cpp rename to wpilibc/wpilibC++Devices/src/PowerDistributionPanel.cpp diff --git a/wpilibc/wpilibC++/lib/Preferences.cpp b/wpilibc/wpilibC++Devices/src/Preferences.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Preferences.cpp rename to wpilibc/wpilibC++Devices/src/Preferences.cpp diff --git a/wpilibc/wpilibC++/lib/Relay.cpp b/wpilibc/wpilibC++Devices/src/Relay.cpp similarity index 99% rename from wpilibc/wpilibC++/lib/Relay.cpp rename to wpilibc/wpilibC++Devices/src/Relay.cpp index 911dc17d06..6cbe81d5a0 100644 --- a/wpilibc/wpilibC++/lib/Relay.cpp +++ b/wpilibc/wpilibC++Devices/src/Relay.cpp @@ -10,6 +10,7 @@ #include "Resource.h" #include "WPIErrors.h" #include "LiveWindow/LiveWindow.h" +#include "HAL/HAL.hpp" // Allocate each direction separately. static Resource *relayChannels = NULL; diff --git a/wpilibc/wpilibC++/lib/RobotBase.cpp b/wpilibc/wpilibC++Devices/src/RobotBase.cpp similarity index 96% rename from wpilibc/wpilibC++/lib/RobotBase.cpp rename to wpilibc/wpilibC++Devices/src/RobotBase.cpp index 9b1859fdda..9ec9ad4c0c 100644 --- a/wpilibc/wpilibC++/lib/RobotBase.cpp +++ b/wpilibc/wpilibC++Devices/src/RobotBase.cpp @@ -10,6 +10,9 @@ //#include "NetworkCommunication/FRCComm.h" //#include "NetworkCommunication/symModuleLink.h" //#include "NetworkCommunication/UsageReporting.h" +#include "RobotState.h" +#include "HLUsageReporting.h" +#include "Internal/HardwareHLReporting.h" #include "Utility.h" #include #include "HAL/HAL.hpp" @@ -149,6 +152,9 @@ void RobotBase::startRobotTask(FUNCPTR factory) printf("WPILib was compiled without -D'SVN_REV=nnnn'\n"); #endif + RobotState::SetImplementation(DriverStation::GetInstance()); + HLUsageReporting::SetImplementation(new HardwareHLReporting()); + #ifdef __vxworks // Check for startup code already running int32_t oldId = taskNameToId(const_cast("FRC_RobotTask")); diff --git a/wpilibc/wpilibC++/lib/RobotDrive.cpp b/wpilibc/wpilibC++Devices/src/RobotDrive.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/RobotDrive.cpp rename to wpilibc/wpilibC++Devices/src/RobotDrive.cpp diff --git a/wpilibc/wpilibC++/lib/SPI.cpp b/wpilibc/wpilibC++Devices/src/SPI.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/SPI.cpp rename to wpilibc/wpilibC++Devices/src/SPI.cpp diff --git a/wpilibc/wpilibC++/lib/SafePWM.cpp b/wpilibc/wpilibC++Devices/src/SafePWM.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/SafePWM.cpp rename to wpilibc/wpilibC++Devices/src/SafePWM.cpp diff --git a/wpilibc/wpilibC++/lib/SampleRobot.cpp b/wpilibc/wpilibC++Devices/src/SampleRobot.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/SampleRobot.cpp rename to wpilibc/wpilibC++Devices/src/SampleRobot.cpp diff --git a/wpilibc/wpilibC++/lib/SensorBase.cpp b/wpilibc/wpilibC++Devices/src/SensorBase.cpp similarity index 99% rename from wpilibc/wpilibC++/lib/SensorBase.cpp rename to wpilibc/wpilibC++Devices/src/SensorBase.cpp index a725418cd8..d403b148b5 100644 --- a/wpilibc/wpilibC++/lib/SensorBase.cpp +++ b/wpilibc/wpilibC++Devices/src/SensorBase.cpp @@ -8,6 +8,7 @@ #include "NetworkCommunication/LoadOut.h" #include "WPIErrors.h" +#include "HAL/HAL.hpp" const uint32_t SensorBase::kDigitalChannels; const uint32_t SensorBase::kAnalogInputs; diff --git a/wpilibc/wpilibC++/lib/SerialPort.cpp b/wpilibc/wpilibC++Devices/src/SerialPort.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/SerialPort.cpp rename to wpilibc/wpilibC++Devices/src/SerialPort.cpp diff --git a/wpilibc/wpilibC++/lib/Servo.cpp b/wpilibc/wpilibC++Devices/src/Servo.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Servo.cpp rename to wpilibc/wpilibC++Devices/src/Servo.cpp diff --git a/wpilibc/wpilibC++/lib/Solenoid.cpp b/wpilibc/wpilibC++Devices/src/Solenoid.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Solenoid.cpp rename to wpilibc/wpilibC++Devices/src/Solenoid.cpp diff --git a/wpilibc/wpilibC++/lib/SolenoidBase.cpp b/wpilibc/wpilibC++Devices/src/SolenoidBase.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/SolenoidBase.cpp rename to wpilibc/wpilibC++Devices/src/SolenoidBase.cpp diff --git a/wpilibc/wpilibC++/lib/Talon.cpp b/wpilibc/wpilibC++Devices/src/Talon.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Talon.cpp rename to wpilibc/wpilibC++Devices/src/Talon.cpp diff --git a/wpilibc/wpilibC++/lib/Task.cpp b/wpilibc/wpilibC++Devices/src/Task.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Task.cpp rename to wpilibc/wpilibC++Devices/src/Task.cpp diff --git a/wpilibc/wpilibC++/lib/Timer.cpp b/wpilibc/wpilibC++Devices/src/Timer.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Timer.cpp rename to wpilibc/wpilibC++Devices/src/Timer.cpp diff --git a/wpilibc/wpilibC++/lib/Ultrasonic.cpp b/wpilibc/wpilibC++Devices/src/Ultrasonic.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Ultrasonic.cpp rename to wpilibc/wpilibC++Devices/src/Ultrasonic.cpp diff --git a/wpilibc/wpilibC++/lib/Utility.cpp b/wpilibc/wpilibC++Devices/src/Utility.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Utility.cpp rename to wpilibc/wpilibC++Devices/src/Utility.cpp diff --git a/wpilibc/wpilibC++/lib/Victor.cpp b/wpilibc/wpilibC++Devices/src/Victor.cpp similarity index 100% rename from wpilibc/wpilibC++/lib/Victor.cpp rename to wpilibc/wpilibC++Devices/src/Victor.cpp diff --git a/wpilibc/wpilibC++IntegrationTests/CMakeLists.txt b/wpilibc/wpilibC++IntegrationTests/CMakeLists.txt index 038621b36a..e1546396b4 100644 --- a/wpilibc/wpilibC++IntegrationTests/CMakeLists.txt +++ b/wpilibc/wpilibC++IntegrationTests/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8) project(WPILibC++IntegrationTests) file(GLOB_RECURSE SRC_FILES src/*.cpp src/gtest/src/gtest-all.cc src/gtest/src/gtest_main.cc) -include_directories(include/ src/gtest/ src/gtest/include/ ../wpilibC++/include/ ${HAL_API_INCLUDES} ${NWT_API_INCLUDES}) +include_directories(include/ src/gtest/ src/gtest/include/ ../wpilibC++Devices/include/ ${WPILIB_INCLUDES} ${HAL_API_INCLUDES} ${NWT_API_INCLUDES}) add_executable(FRCUserProgram ${SRC_FILES}) -target_link_libraries(FRCUserProgram WPILibAthena HALAthena NetworkTables ${NI_LIBS}) +target_link_libraries(FRCUserProgram WPILib WPILibAthena WPILib HALAthena NetworkTables ${NI_LIBS}) diff --git a/wpilibc/wpilibC++IntegrationTests/src/NotifierTest.cpp b/wpilibc/wpilibC++IntegrationTests/src/NotifierTest.cpp new file mode 100644 index 0000000000..87cd2a9940 --- /dev/null +++ b/wpilibc/wpilibC++IntegrationTests/src/NotifierTest.cpp @@ -0,0 +1,39 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2014. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include "WPILib.h" +#include "gtest/gtest.h" +#include "TestBench.h" + + +unsigned notifierCounter; + +void notifierHandler(void *) +{ + notifierCounter++; +} + +/** + * Test if the Wait function works + */ +TEST(NotifierTest, DISABLED_TestTimerNotifications) { + std::cout << "NotifierTest..." << std::endl; + notifierCounter = 0; + std::cout << "notifier(notifierHandler, NULL)..." << std::endl; + Notifier notifier(notifierHandler, NULL); + std::cout << "Start Periodic..." << std::endl; + notifier.StartPeriodic(1.0); + + std::cout << "Wait..." << std::endl; + Wait(10.5); + std::cout << "...Wait" << std::endl; + + EXPECT_EQ(10u, notifierCounter) << "Received " << notifierCounter << " notifications in 10.5 seconds"; + std::cout << "Received " << notifierCounter << " notifications in 10.5 seconds"; + + std::cout << "...NotifierTest" << std::endl; +} diff --git a/wpilibc/wpilibC++IntegrationTests/src/command/CommandTest.cpp b/wpilibc/wpilibC++IntegrationTests/src/command/CommandTest.cpp index 2804506c61..80ab73f0fb 100644 --- a/wpilibc/wpilibC++IntegrationTests/src/command/CommandTest.cpp +++ b/wpilibc/wpilibC++IntegrationTests/src/command/CommandTest.cpp @@ -8,10 +8,13 @@ #include "WPILib.h" #include "command/MockCommand.h" #include "gtest/gtest.h" +#include "RobotState.h" +#include "DriverStation.h" class CommandTest : public testing::Test { protected: virtual void SetUp() { + RobotState::SetImplementation(DriverStation::GetInstance()); Scheduler::GetInstance()->SetEnabled(true); } diff --git a/wpilibc/wpilibC++Sim/CMakeLists.txt b/wpilibc/wpilibC++Sim/CMakeLists.txt index 58c8a02a69..f7d511febf 100644 --- a/wpilibc/wpilibC++Sim/CMakeLists.txt +++ b/wpilibc/wpilibC++Sim/CMakeLists.txt @@ -1,6 +1,10 @@ cmake_minimum_required(VERSION 2.8) project(WPILibSim) +get_filename_component(HAL_API_INCLUDES $ENV{ALLWPILIB}/hal/include REALPATH) +get_filename_component(NWT_API_INCLUDES $ENV{ALLWPILIB}/networktables/cpp/include REALPATH) +add_subdirectory(build/wpilibC++) + include (FindPkgConfig) if (PKG_CONFIG_FOUND) pkg_check_modules(GAZEBO gazebo) @@ -13,11 +17,12 @@ file(GLOB_RECURSE SRC_FILES src/*.cpp $ENV{ALLWPILIB}/networktables/cpp/lib/shar $ENV{ALLWPILIB}/hal/lib/Athena/Task.cpp $ENV{ALLWPILIB}/hal/lib/Athena/Semaphore.cpp $ENV{ALLWPILIB}/hal/lib/Athena/cpp/*.cpp) -include_directories(include/ $ENV{ALLWPILIB}/networktables/cpp/include +include_directories(include/ $ENV{ALLWPILIB}/wpilibc/wpilibC++/include + $ENV{ALLWPILIB}/networktables/cpp/include $ENV{ALLWPILIB}/hal/include ${Boost_INCLUDE_DIR} ${GAZEBO_INCLUDE_DIRS}) # ${NWT_API_INCLUDES} add_library(WPILibSim SHARED ${SRC_FILES}) -target_link_libraries(WPILibSim ${GAZEBO_LIBRARIES}) # NetworkTables +target_link_libraries(WPILibSim WPILib ${GAZEBO_LIBRARIES} -fPIC) # NetworkTables INSTALL(TARGETS WPILibSim LIBRARY DESTINATION src COMPONENT src) INSTALL(DIRECTORY include DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT headers) # ni_emb diff --git a/wpilibc/wpilibC++Sim/Makefile b/wpilibc/wpilibC++Sim/Makefile index 4d3bd2978a..34200d408d 100644 --- a/wpilibc/wpilibC++Sim/Makefile +++ b/wpilibc/wpilibC++Sim/Makefile @@ -5,6 +5,7 @@ allwpilib = ../.. all: mkdir -p $(build.dir) + cp -r $(allwpilib)/wpilibc/wpilibC++ build cd ${build.dir} && ALLWPILIB=$(allwpilib) cmake .. && make clean: diff --git a/wpilibc/wpilibC++Sim/include/Buttons/Button.h b/wpilibc/wpilibC++Sim/include/Buttons/Button.h deleted file mode 100644 index c4911118ab..0000000000 --- a/wpilibc/wpilibC++Sim/include/Buttons/Button.h +++ /dev/null @@ -1,35 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __BUTTON_H__ -#define __BUTTON_H__ - -#include "Buttons/Trigger.h" -#include "Commands/Command.h" - -/** - * This class provides an easy way to link commands to OI inputs. - * - * It is very easy to link a button to a command. For instance, you could - * link the trigger button of a joystick to a "score" command. - * - * This class represents a subclass of Trigger that is specifically aimed at - * buttons on an operator interface as a common use case of the more generalized - * Trigger objects. This is a simple wrapper around Trigger with the method names - * renamed to fit the Button object use. - * - * @author brad - */ -class Button : public Trigger { -public: - virtual void WhenPressed(Command *command); - virtual void WhileHeld(Command *command); - virtual void WhenReleased(Command *command); - virtual void CancelWhenPressed(Command *command); - virtual void ToggleWhenPressed(Command *command); -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Buttons/ButtonScheduler.h b/wpilibc/wpilibC++Sim/include/Buttons/ButtonScheduler.h deleted file mode 100644 index 96d0a0ee11..0000000000 --- a/wpilibc/wpilibC++Sim/include/Buttons/ButtonScheduler.h +++ /dev/null @@ -1,27 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __BUTTON_SCHEDULER_H__ -#define __BUTTON_SCHEDULER_H__ - -class Trigger; -class Command; - -class ButtonScheduler -{ -public: - ButtonScheduler(bool last, Trigger *button, Command *orders); - virtual ~ButtonScheduler() {} - virtual void Execute() = 0; - void Start(); - -protected: - bool m_pressedLast; - Trigger *m_button; - Command *m_command; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Buttons/CancelButtonScheduler.h b/wpilibc/wpilibC++Sim/include/Buttons/CancelButtonScheduler.h deleted file mode 100644 index 0491213164..0000000000 --- a/wpilibc/wpilibC++Sim/include/Buttons/CancelButtonScheduler.h +++ /dev/null @@ -1,25 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __CANCEL_BUTTON_SCHEDULER_H__ -#define __CANCEL_BUTTON_SCHEDULER_H__ - -#include "Buttons/ButtonScheduler.h" - -class Trigger; -class Command; - -class CancelButtonScheduler : public ButtonScheduler -{ -public: - CancelButtonScheduler(bool last, Trigger *button, Command *orders); - virtual ~CancelButtonScheduler() {} - virtual void Execute(); -private: - bool pressedLast; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Buttons/HeldButtonScheduler.h b/wpilibc/wpilibC++Sim/include/Buttons/HeldButtonScheduler.h deleted file mode 100644 index 3bca0d5417..0000000000 --- a/wpilibc/wpilibC++Sim/include/Buttons/HeldButtonScheduler.h +++ /dev/null @@ -1,23 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __HELD_BUTTON_SCHEDULER_H__ -#define __HELD_BUTTON_SCHEDULER_H__ - -#include "Buttons/ButtonScheduler.h" - -class Trigger; -class Command; - -class HeldButtonScheduler : public ButtonScheduler -{ -public: - HeldButtonScheduler(bool last, Trigger *button, Command *orders); - virtual ~HeldButtonScheduler() {} - virtual void Execute(); -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Buttons/InternalButton.h b/wpilibc/wpilibC++Sim/include/Buttons/InternalButton.h deleted file mode 100644 index e61cf0a636..0000000000 --- a/wpilibc/wpilibC++Sim/include/Buttons/InternalButton.h +++ /dev/null @@ -1,29 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __INTERNAL_BUTTON_H__ -#define __INTERNAL_BUTTON_H__ - -#include "Buttons/Button.h" - -class InternalButton : public Button -{ -public: - InternalButton(); - InternalButton(bool inverted); - virtual ~InternalButton() {} - - void SetInverted(bool inverted); - void SetPressed(bool pressed); - - virtual bool Get(); - -private: - bool m_pressed; - bool m_inverted; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Buttons/JoystickButton.h b/wpilibc/wpilibC++Sim/include/Buttons/JoystickButton.h deleted file mode 100644 index cb5f0c482c..0000000000 --- a/wpilibc/wpilibC++Sim/include/Buttons/JoystickButton.h +++ /dev/null @@ -1,26 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __JOYSTICK_BUTTON_H__ -#define __JOYSTICK_BUTTON_H__ - -#include "GenericHID.h" -#include "Buttons/Button.h" - -class JoystickButton : public Button -{ -public: - JoystickButton(GenericHID *joystick, int buttonNumber); - virtual ~JoystickButton() {} - - virtual bool Get(); - -private: - GenericHID *m_joystick; - int m_buttonNumber; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Buttons/NetworkButton.h b/wpilibc/wpilibC++Sim/include/Buttons/NetworkButton.h deleted file mode 100644 index 874a768a48..0000000000 --- a/wpilibc/wpilibC++Sim/include/Buttons/NetworkButton.h +++ /dev/null @@ -1,28 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __NETWORK_BUTTON_H__ -#define __NETWORK_BUTTON_H__ - -#include "Buttons/Button.h" -#include - -class NetworkButton : public Button -{ -public: - NetworkButton(const char *tableName, const char *field); - NetworkButton(ITable* table, const char *field); - virtual ~NetworkButton() {} - - virtual bool Get(); - -private: - ITable* m_netTable; - std::string m_field; - -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Buttons/PressedButtonScheduler.h b/wpilibc/wpilibC++Sim/include/Buttons/PressedButtonScheduler.h deleted file mode 100644 index a69320bdc7..0000000000 --- a/wpilibc/wpilibC++Sim/include/Buttons/PressedButtonScheduler.h +++ /dev/null @@ -1,23 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __PRESSED_BUTTON_SCHEDULER_H__ -#define __PRESSED_BUTTON_SCHEDULER_H__ - -#include "Buttons/ButtonScheduler.h" - -class Trigger; -class Command; - -class PressedButtonScheduler : public ButtonScheduler -{ -public: - PressedButtonScheduler(bool last, Trigger *button, Command *orders); - virtual ~PressedButtonScheduler() {} - virtual void Execute(); -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Buttons/ReleasedButtonScheduler.h b/wpilibc/wpilibC++Sim/include/Buttons/ReleasedButtonScheduler.h deleted file mode 100644 index 198a1d3eb7..0000000000 --- a/wpilibc/wpilibC++Sim/include/Buttons/ReleasedButtonScheduler.h +++ /dev/null @@ -1,23 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __RELEASED_BUTTON_SCHEDULER_H__ -#define __RELEASED_BUTTON_SCHEDULER_H__ - -#include "Buttons/ButtonScheduler.h" - -class Trigger; -class Command; - -class ReleasedButtonScheduler : public ButtonScheduler -{ -public: - ReleasedButtonScheduler(bool last, Trigger *button, Command *orders); - virtual ~ReleasedButtonScheduler() {} - virtual void Execute(); -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Buttons/ToggleButtonScheduler.h b/wpilibc/wpilibC++Sim/include/Buttons/ToggleButtonScheduler.h deleted file mode 100644 index e0987e5a7d..0000000000 --- a/wpilibc/wpilibC++Sim/include/Buttons/ToggleButtonScheduler.h +++ /dev/null @@ -1,25 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __TOGGLE_BUTTON_SCHEDULER_H__ -#define __TOGGLE_BUTTON_SCHEDULER_H__ - -#include "Buttons/ButtonScheduler.h" - -class Trigger; -class Command; - -class ToggleButtonScheduler : public ButtonScheduler -{ -public: - ToggleButtonScheduler(bool last, Trigger *button, Command *orders); - virtual ~ToggleButtonScheduler() {} - virtual void Execute(); -private: - bool pressedLast; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Buttons/Trigger.h b/wpilibc/wpilibC++Sim/include/Buttons/Trigger.h deleted file mode 100644 index 509fc826d8..0000000000 --- a/wpilibc/wpilibC++Sim/include/Buttons/Trigger.h +++ /dev/null @@ -1,49 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __TRIGGER_H__ -#define __TRIGGER_H__ - -#include "SmartDashboard/Sendable.h" - -class Command; - -/** - * This class provides an easy way to link commands to inputs. - * - * It is very easy to link a polled input to a command. For instance, you could - * link the trigger button of a joystick to a "score" command or an encoder reaching - * a particular value. - * - * It is encouraged that teams write a subclass of Trigger if they want to have - * something unusual (for instance, if they want to react to the user holding - * a button while the robot is reading a certain sensor input). For this, they - * only have to write the {@link Trigger#Get()} method to get the full functionality - * of the Trigger class. - * - * @author Brad Miller, Joe Grinstead - */ -class Trigger : public Sendable -{ -public: - Trigger(); - virtual ~Trigger() {} - bool Grab(); - virtual bool Get() = 0; - void WhenActive(Command *command); - void WhileActive(Command *command); - void WhenInactive(Command *command); - void CancelWhenActive(Command *command); - void ToggleWhenActive(Command *command); - - virtual void InitTable(ITable* table); - virtual ITable* GetTable(); - virtual std::string GetSmartDashboardType(); -protected: - ITable* m_table; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Commands/Command.h b/wpilibc/wpilibC++Sim/include/Commands/Command.h deleted file mode 100644 index 5a9a77f788..0000000000 --- a/wpilibc/wpilibC++Sim/include/Commands/Command.h +++ /dev/null @@ -1,164 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __COMMAND_H__ -#define __COMMAND_H__ - -#include "ErrorBase.h" -#include "SmartDashboard/NamedSendable.h" -#include -#include - -class CommandGroup; -class Subsystem; - -/** - * The Command class is at the very core of the entire command framework. - * Every command can be started with a call to {@link Command#Start() Start()}. - * Once a command is started it will call {@link Command#Initialize() Initialize()}, and then - * will repeatedly call {@link Command#Execute() Execute()} until the {@link Command#IsFinished() IsFinished()} - * returns true. Once it does, {@link Command#End() End()} will be called. - * - *

However, if at any point while it is running {@link Command#Cancel() Cancel()} is called, then - * the command will be stopped and {@link Command#Interrupted() Interrupted()} will be called.

- * - *

If a command uses a {@link Subsystem}, then it should specify that it does so by - * calling the {@link Command#Requires(Subsystem) Requires(...)} method - * in its constructor. Note that a Command may have multiple requirements, and - * {@link Command#Requires(Subsystem) Requires(...)} should be - * called for each one.

- * - *

If a command is running and a new command with shared requirements is started, - * then one of two things will happen. If the active command is interruptible, - * then {@link Command#Cancel() Cancel()} will be called and the command will be removed - * to make way for the new one. If the active command is not interruptible, the - * other one will not even be started, and the active one will continue functioning.

- * - * @see CommandGroup - * @see Subsystem - */ -class Command : public ErrorBase, public NamedSendable, public ITableListener -{ - friend class CommandGroup; - friend class Scheduler; -public: - Command(); - Command(const char *name); - Command(double timeout); - Command(const char *name, double timeout); - virtual ~Command(); - double TimeSinceInitialized(); - void Requires(Subsystem *s); - bool IsCanceled(); - void Start(); - bool Run(); - void Cancel(); - bool IsRunning(); - bool IsInterruptible(); - void SetInterruptible(bool interruptible); - bool DoesRequire(Subsystem *subsystem); - typedef std::set SubsystemSet; - SubsystemSet GetRequirements(); - CommandGroup *GetGroup(); - void SetRunWhenDisabled(bool run); - bool WillRunWhenDisabled(); - int GetID(); - - -protected: - void SetTimeout(double timeout); - bool IsTimedOut(); - bool AssertUnlocked(const char *message); - void SetParent(CommandGroup *parent); - /** - * The initialize method is called the first time this Command is run after - * being started. - */ - virtual void Initialize() = 0; - /** - * The execute method is called repeatedly until this Command either finishes - * or is canceled. - */ - virtual void Execute() = 0; - /** - * Returns whether this command is finished. - * If it is, then the command will be removed - * and {@link Command#end() end()} will be called. - * - *

It may be useful for a team to reference the {@link Command#isTimedOut() isTimedOut()} method - * for time-sensitive commands.

- * @return whether this command is finished. - * @see Command#isTimedOut() isTimedOut() - */ - virtual bool IsFinished() = 0; - /** - * Called when the command ended peacefully. This is where you may want - * to wrap up loose ends, like shutting off a motor that was being used - * in the command. - */ - virtual void End() = 0; - /** - * Called when the command ends because somebody called {@link Command#cancel() cancel()} - * or another command shared the same requirements as this one, and booted - * it out. - * - *

This is where you may want - * to wrap up loose ends, like shutting off a motor that was being used - * in the command.

- * - *

Generally, it is useful to simply call the {@link Command#end() end()} method - * within this method

- */ - virtual void Interrupted() = 0; - virtual void _Initialize(); - virtual void _Interrupted(); - virtual void _Execute(); - virtual void _End(); - virtual void _Cancel(); - -private: - void InitCommand(const char *name, double timeout); - void LockChanges(); - /*synchronized*/ void Removed(); - void StartRunning(); - void StartTiming(); - - /** The name of this command */ - std::string m_name; - /** The time since this command was initialized */ - double m_startTime; - /** The time (in seconds) before this command "times out" (or -1 if no timeout) */ - double m_timeout; - /** Whether or not this command has been initialized */ - bool m_initialized; - /** The requirements (or null if no requirements) */ - SubsystemSet m_requirements; - /** Whether or not it is running */ - bool m_running; - /** Whether or not it is interruptible*/ - bool m_interruptible; - /** Whether or not it has been canceled */ - bool m_canceled; - /** Whether or not it has been locked */ - bool m_locked; - /** Whether this command should run when the robot is disabled */ - bool m_runWhenDisabled; - /** The {@link CommandGroup} this is in */ - CommandGroup *m_parent; - int m_commandID; - static int m_commandCounter; - -public: - virtual std::string GetName(); - virtual void InitTable(ITable* table); - virtual ITable* GetTable(); - virtual std::string GetSmartDashboardType(); - virtual void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew); -protected: - ITable* m_table; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Commands/CommandGroup.h b/wpilibc/wpilibC++Sim/include/Commands/CommandGroup.h deleted file mode 100644 index 87c299f7cb..0000000000 --- a/wpilibc/wpilibC++Sim/include/Commands/CommandGroup.h +++ /dev/null @@ -1,71 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __COMMAND_GROUP_H__ -#define __COMMAND_GROUP_H__ - -#include "Commands/Command.h" -#include "Commands/CommandGroupEntry.h" -#include -#include - -/** - * A {@link CommandGroup} is a list of commands which are executed in sequence. - * - *

Commands in a {@link CommandGroup} are added using the {@link CommandGroup#AddSequential(Command) AddSequential(...)} method - * and are called sequentially. - * {@link CommandGroup CommandGroups} are themselves {@link Command Commands} - * and can be given to other {@link CommandGroup CommandGroups}.

- * - *

{@link CommandGroup CommandGroups} will carry all of the requirements of their {@link Command subcommands}. Additional - * requirements can be specified by calling {@link CommandGroup#Requires(Subsystem) Requires(...)} - * normally in the constructor.

- * - *

CommandGroups can also execute commands in parallel, simply by adding them - * using {@link CommandGroup#AddParallel(Command) AddParallel(...)}.

- * - * @see Command - * @see Subsystem - */ -class CommandGroup : public Command -{ -public: - CommandGroup(); - CommandGroup(const char *name); - virtual ~CommandGroup(); - - void AddSequential(Command *command); - void AddSequential(Command *command, double timeout); - void AddParallel(Command *command); - void AddParallel(Command *command, double timeout); - bool IsInterruptible(); - int GetSize(); - -protected: - virtual void Initialize(); - virtual void Execute(); - virtual bool IsFinished(); - virtual void End(); - virtual void Interrupted(); - virtual void _Initialize(); - virtual void _Interrupted(); - virtual void _Execute(); - virtual void _End(); - -private: - void CancelConflicts(Command *command); - - typedef std::vector CommandVector; - /** The commands in this group (stored in entries) */ - CommandVector m_commands; - typedef std::list CommandList; - /** The active children in this group (stored in entries) */ - CommandList m_children; - /** The current command, -1 signifies that none have been run */ - int m_currentCommandIndex; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Commands/CommandGroupEntry.h b/wpilibc/wpilibC++Sim/include/Commands/CommandGroupEntry.h deleted file mode 100644 index d2be6a8ad4..0000000000 --- a/wpilibc/wpilibC++Sim/include/Commands/CommandGroupEntry.h +++ /dev/null @@ -1,27 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __COMMAND_GROUP_ENTRY_H__ -#define __COMMAND_GROUP_ENTRY_H__ - -class Command; - -class CommandGroupEntry -{ -public: - typedef enum {kSequence_InSequence, kSequence_BranchPeer, kSequence_BranchChild} Sequence; - - CommandGroupEntry(); - CommandGroupEntry(Command *command, Sequence state); - CommandGroupEntry(Command *command, Sequence state, double timeout); - bool IsTimedOut(); - - double m_timeout; - Command *m_command; - Sequence m_state; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Commands/PIDCommand.h b/wpilibc/wpilibC++Sim/include/Commands/PIDCommand.h deleted file mode 100644 index be44f0656d..0000000000 --- a/wpilibc/wpilibC++Sim/include/Commands/PIDCommand.h +++ /dev/null @@ -1,56 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __PID_COMMAND_H__ -#define __PID_COMMAND_H__ - -#include "Commands/Command.h" -#include "PIDSource.h" -#include "PIDOutput.h" - -class PIDController; - -class PIDCommand : public Command, public PIDOutput, public PIDSource -{ -public: - PIDCommand(const char *name, double p, double i, double d); - PIDCommand(const char *name, double p, double i, double d, double period); - PIDCommand(const char *name, double p, double i, double d, double f, double perioid); - PIDCommand(double p, double i, double d); - PIDCommand(double p, double i, double d, double period); - PIDCommand(double p, double i, double d, double f, double period); - virtual ~PIDCommand(); - - void SetSetpointRelative(double deltaSetpoint); - - // PIDOutput interface - virtual void PIDWrite(float output); - - // PIDSource interface - virtual double PIDGet(); -protected: - PIDController *GetPIDController(); - virtual void _Initialize(); - virtual void _Interrupted(); - virtual void _End(); - void SetSetpoint(double setpoint); - double GetSetpoint(); - double GetPosition(); - - virtual double ReturnPIDInput() = 0; - virtual void UsePIDOutput(double output) = 0; - -private: - /** The internal {@link PIDController} */ - PIDController *m_controller; - -public: - virtual void InitTable(ITable* table); - virtual std::string GetSmartDashboardType(); -}; - -#endif - diff --git a/wpilibc/wpilibC++Sim/include/Commands/PIDSubsystem.h b/wpilibc/wpilibC++Sim/include/Commands/PIDSubsystem.h deleted file mode 100644 index 6b9d138c08..0000000000 --- a/wpilibc/wpilibC++Sim/include/Commands/PIDSubsystem.h +++ /dev/null @@ -1,70 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __PID_SUBSYSTEM_H__ -#define __PID_SUBSYSTEM_H__ - -#include "Commands/Subsystem.h" -#include "PIDController.h" -#include "PIDSource.h" -#include "PIDOutput.h" - -/** - * This class is designed to handle the case where there is a {@link Subsystem} - * which uses a single {@link PIDController} almost constantly (for instance, - * an elevator which attempts to stay at a constant height). - * - *

It provides some convenience methods to run an internal {@link PIDController}. - * It also allows access to the internal {@link PIDController} in order to give total control - * to the programmer.

- * - */ -class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource -{ -public: - PIDSubsystem(const char *name, double p, double i, double d); - PIDSubsystem(const char *name, double p, double i, double d, double f); - PIDSubsystem(const char *name, double p, double i, double d, double f, double period); - PIDSubsystem(double p, double i, double d); - PIDSubsystem(double p, double i, double d, double f); - PIDSubsystem(double p, double i, double d, double f, double period); - virtual ~PIDSubsystem(); - - void Enable(); - void Disable(); - - // PIDOutput interface - virtual void PIDWrite(float output); - - // PIDSource interface - virtual double PIDGet(); - void SetSetpoint(double setpoint); - void SetSetpointRelative(double deltaSetpoint); - void SetInputRange(float minimumInput, float maximumInput); - double GetSetpoint(); - double GetPosition(); - - virtual void SetAbsoluteTolerance(float absValue); - virtual void SetPercentTolerance(float percent); - virtual bool OnTarget(); - -protected: - PIDController *GetPIDController(); - - virtual double ReturnPIDInput() = 0; - virtual void UsePIDOutput(double output) = 0; - -private: - /** The internal {@link PIDController} */ - PIDController *m_controller; - -public: - virtual void InitTable(ITable* table); - virtual std::string GetSmartDashboardType(); -}; - -#endif - diff --git a/wpilibc/wpilibC++Sim/include/Commands/PrintCommand.h b/wpilibc/wpilibC++Sim/include/Commands/PrintCommand.h deleted file mode 100644 index b6342f5014..0000000000 --- a/wpilibc/wpilibC++Sim/include/Commands/PrintCommand.h +++ /dev/null @@ -1,30 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __PRINT_COMMAND_H__ -#define __PRINT_COMMAND_H__ - -#include "Commands/Command.h" -#include - -class PrintCommand : public Command -{ -public: - PrintCommand(const char *message); - virtual ~PrintCommand() {} - -protected: - virtual void Initialize(); - virtual void Execute(); - virtual bool IsFinished(); - virtual void End(); - virtual void Interrupted(); - -private: - std::string m_message; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Commands/Scheduler.h b/wpilibc/wpilibC++Sim/include/Commands/Scheduler.h deleted file mode 100644 index 0fada5fe58..0000000000 --- a/wpilibc/wpilibC++Sim/include/Commands/Scheduler.h +++ /dev/null @@ -1,71 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __SCHEDULER_H__ -#define __SCHEDULER_H__ - -#include "Commands/Command.h" -#include "ErrorBase.h" -#include "SmartDashboard/NamedSendable.h" -#include "networktables/NetworkTable.h" -#include "networktables2/type/NumberArray.h" -#include "networktables2/type/StringArray.h" -#include "SmartDashboard/SmartDashboard.h" -#include "HAL/Semaphore.hpp" -#include -#include -#include -#include - -class ButtonScheduler; -class Subsystem; - -class Scheduler : public ErrorBase, public NamedSendable -{ -public: - static Scheduler *GetInstance(); - - void AddCommand(Command* command); - void AddButton(ButtonScheduler* button); - void RegisterSubsystem(Subsystem *subsystem); - void Run(); - void Remove(Command *command); - void RemoveAll(); - void SetEnabled(bool enabled); - - void UpdateTable(); - std::string GetSmartDashboardType(); - void InitTable(ITable *subTable); - ITable * GetTable(); - std::string GetName(); - std::string GetType(); - -private: - Scheduler(); - virtual ~Scheduler(); - - void ProcessCommandAddition(Command *command); - - static Scheduler *_instance; - Command::SubsystemSet m_subsystems; - MUTEX_ID m_buttonsLock; - typedef std::vector ButtonVector; - ButtonVector m_buttons; - typedef std::vector CommandVector; - MUTEX_ID m_additionsLock; - CommandVector m_additions; - typedef std::set CommandSet; - CommandSet m_commands; - bool m_adding; - bool m_enabled; - StringArray *commands; - NumberArray *ids; - NumberArray *toCancel; - ITable *m_table; - bool m_runningCommandsChanged; -}; -#endif - diff --git a/wpilibc/wpilibC++Sim/include/Commands/StartCommand.h b/wpilibc/wpilibC++Sim/include/Commands/StartCommand.h deleted file mode 100644 index 1ea6dcf429..0000000000 --- a/wpilibc/wpilibC++Sim/include/Commands/StartCommand.h +++ /dev/null @@ -1,29 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __START_COMMAND_H__ -#define __START_COMMAND_H__ - -#include "Commands/Command.h" - -class StartCommand : public Command -{ -public: - StartCommand(Command *commandToStart); - virtual ~StartCommand() {} - -protected: - virtual void Initialize(); - virtual void Execute(); - virtual bool IsFinished(); - virtual void End(); - virtual void Interrupted(); - -private: - Command *m_commandToFork; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Commands/Subsystem.h b/wpilibc/wpilibC++Sim/include/Commands/Subsystem.h deleted file mode 100644 index 1bc1fd2859..0000000000 --- a/wpilibc/wpilibC++Sim/include/Commands/Subsystem.h +++ /dev/null @@ -1,48 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __SUBSYSTEM_H__ -#define __SUBSYSTEM_H__ - -#include "ErrorBase.h" -#include "SmartDashboard/NamedSendable.h" -#include - - -class Command; - -class Subsystem : public ErrorBase, public NamedSendable -{ - friend class Scheduler; -public: - Subsystem(const char *name); - virtual ~Subsystem() {} - - void SetDefaultCommand(Command *command); - Command *GetDefaultCommand(); - void SetCurrentCommand(Command *command); - Command *GetCurrentCommand(); - virtual void InitDefaultCommand(); - -private: - void ConfirmCommand(); - - Command *m_currentCommand; - bool m_currentCommandChanged; - Command *m_defaultCommand; - std::string m_name; - bool m_initializedDefaultCommand; - -public: - virtual std::string GetName(); - virtual void InitTable(ITable* table); - virtual ITable* GetTable(); - virtual std::string GetSmartDashboardType(); -protected: - ITable* m_table; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Commands/WaitCommand.h b/wpilibc/wpilibC++Sim/include/Commands/WaitCommand.h deleted file mode 100644 index 036bae80b1..0000000000 --- a/wpilibc/wpilibC++Sim/include/Commands/WaitCommand.h +++ /dev/null @@ -1,27 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __WAIT_COMMAND_H__ -#define __WAIT_COMMAND_H__ - -#include "Commands/Command.h" - -class WaitCommand : public Command -{ -public: - WaitCommand(double timeout); - WaitCommand(const char *name, double timeout); - virtual ~WaitCommand() {} - -protected: - virtual void Initialize(); - virtual void Execute(); - virtual bool IsFinished(); - virtual void End(); - virtual void Interrupted(); -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Commands/WaitForChildren.h b/wpilibc/wpilibC++Sim/include/Commands/WaitForChildren.h deleted file mode 100644 index 2f4e3eae9b..0000000000 --- a/wpilibc/wpilibC++Sim/include/Commands/WaitForChildren.h +++ /dev/null @@ -1,27 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __WAIT_FOR_CHILDREN_H__ -#define __WAIT_FOR_CHILDREN_H__ - -#include "Commands/Command.h" - -class WaitForChildren : public Command -{ -public: - WaitForChildren(double timeout); - WaitForChildren(const char *name, double timeout); - virtual ~WaitForChildren() {} - -protected: - virtual void Initialize(); - virtual void Execute(); - virtual bool IsFinished(); - virtual void End(); - virtual void Interrupted(); -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Commands/WaitUntilCommand.h b/wpilibc/wpilibC++Sim/include/Commands/WaitUntilCommand.h deleted file mode 100644 index b816ccf73c..0000000000 --- a/wpilibc/wpilibC++Sim/include/Commands/WaitUntilCommand.h +++ /dev/null @@ -1,30 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __WAIT_UNTIL_COMMAND_H__ -#define __WAIT_UNTIL_COMMAND_H__ - -#include "Commands/Command.h" - -class WaitUntilCommand : public Command -{ -public: - WaitUntilCommand(double time); - WaitUntilCommand(const char *name, double time); - virtual ~WaitUntilCommand() {} - -protected: - virtual void Initialize(); - virtual void Execute(); - virtual bool IsFinished(); - virtual void End(); - virtual void Interrupted(); - -private: - double m_time; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/Controller.h b/wpilibc/wpilibC++Sim/include/Controller.h deleted file mode 100644 index 99eba88055..0000000000 --- a/wpilibc/wpilibC++Sim/include/Controller.h +++ /dev/null @@ -1,34 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ -#pragma once - -#include -#include -#include -#include - -/** - * Interface for Controllers - * Common interface for controllers. Controllers run control loops, the most common - * are PID controllers and their variants, but this includes anything that is controlling - * an actuator in a separate thread. - */ -class Controller -{ -public: - virtual ~Controller() {}; - - /** - * Allows the control loop to run - */ - virtual void Enable() = 0; - - /** - * Stops the control loop from running until explicitly re-enabled by calling enable() - */ - virtual void Disable() = 0; -}; - diff --git a/wpilibc/wpilibC++Sim/include/DriverStation.h b/wpilibc/wpilibC++Sim/include/DriverStation.h index 92f9e1d4aa..31a4c085da 100644 --- a/wpilibc/wpilibC++Sim/include/DriverStation.h +++ b/wpilibc/wpilibC++Sim/include/DriverStation.h @@ -8,6 +8,7 @@ #include "simulation/msgs/msgs.h" #include #include "SensorBase.h" +#include "RobotState.h" #include "Task.h" struct HALCommonControlData; @@ -18,7 +19,7 @@ using namespace gazebo; /** * Provide access to the network communication data to / from the Driver Station. */ -class DriverStation : public SensorBase +class DriverStation : public SensorBase, public RobotStateInterface { public: enum Alliance diff --git a/wpilibc/wpilibC++Sim/include/Error.h b/wpilibc/wpilibC++Sim/include/Error.h deleted file mode 100644 index f73ae23af8..0000000000 --- a/wpilibc/wpilibC++Sim/include/Error.h +++ /dev/null @@ -1,58 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ -#pragma once - -#include "Base.h" -#include -#include - -// Forward declarations -class ErrorBase; - -/** - * Error object represents a library error. - */ -class Error -{ -public: - typedef int32_t Code; - - Error(); - ~Error(); - void Clone(Error &error); - Code GetCode() const; - const char *GetMessage() const; - const char *GetFilename() const; - const char *GetFunction() const; - uint32_t GetLineNumber() const; - const ErrorBase* GetOriginatingObject() const; - double GetTime() const; - void Clear(); - void Set(Code code, const char* contextMessage, const char* filename, const char *function, - uint32_t lineNumber, const ErrorBase* originatingObject); - static void EnableStackTrace(bool enable) - { - m_stackTraceEnabled = enable; - } - static void EnableSuspendOnError(bool enable) - { - m_suspendOnErrorEnabled = enable; - } - -private: - void Report(); - - Code m_code; - std::string m_message; - std::string m_filename; - std::string m_function; - uint32_t m_lineNumber; - const ErrorBase* m_originatingObject; - double m_timestamp; - - static bool m_stackTraceEnabled; - static bool m_suspendOnErrorEnabled;DISALLOW_COPY_AND_ASSIGN(Error); -}; diff --git a/wpilibc/wpilibC++Sim/include/ErrorBase.h b/wpilibc/wpilibC++Sim/include/ErrorBase.h deleted file mode 100644 index ca3933c28f..0000000000 --- a/wpilibc/wpilibC++Sim/include/ErrorBase.h +++ /dev/null @@ -1,64 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ -#pragma once - -#include "Base.h" -#include "Error.h" -#include "HAL/Semaphore.hpp" - -#define wpi_setErrnoErrorWithContext(context) (this->SetErrnoError((context), __FILE__, __FUNCTION__, __LINE__)) -#define wpi_setErrnoError() (wpi_setErrnoErrorWithContext("")) -#define wpi_setImaqErrorWithContext(code, context) (this->SetImaqError((code), (context), __FILE__, __FUNCTION__, __LINE__)) -#define wpi_setErrorWithContext(code, context) (this->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__)) -#define wpi_setError(code) (wpi_setErrorWithContext(code, "")) -#define wpi_setStaticErrorWithContext(object, code, context) (object->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__)) -#define wpi_setStaticError(object, code) (wpi_setStaticErrorWithContext(object, code, "")) -#define wpi_setGlobalErrorWithContext(code, context) (ErrorBase::SetGlobalError((code), (context), __FILE__, __FUNCTION__, __LINE__)) -#define wpi_setGlobalError(code) (wpi_setGlobalErrorWithContext(code, "")) -#define wpi_setWPIErrorWithContext(error, context) (this->SetWPIError((wpi_error_s_##error), (context), __FILE__, __FUNCTION__, __LINE__)) -#define wpi_setWPIError(error) (wpi_setWPIErrorWithContext(error, "")) -#define wpi_setStaticWPIErrorWithContext(object, error, context) (object->SetWPIError((wpi_error_s_##error), (context), __FILE__, __FUNCTION__, __LINE__)) -#define wpi_setStaticWPIError(object, error) (wpi_setStaticWPIErrorWithContext(object, error, "")) -#define wpi_setGlobalWPIErrorWithContext(error, context) (ErrorBase::SetGlobalWPIError((wpi_error_s_##error), (context), __FILE__, __FUNCTION__, __LINE__)) -#define wpi_setGlobalWPIError(error) (wpi_setGlobalWPIErrorWithContext(error, "")) - -/** - * Base class for most objects. - * ErrorBase is the base class for most objects since it holds the generated error - * for that object. In addition, there is a single instance of a global error object - */ -class ErrorBase -{ -//TODO: Consider initializing instance variables and cleanup in destructor -public: - virtual ~ErrorBase(); - virtual Error& GetError(); - virtual const Error& GetError() const; - virtual void SetErrnoError(const char *contextMessage, const char* filename, - const char* function, uint32_t lineNumber) const; - virtual void SetImaqError(int success, const char *contextMessage, const char* filename, - const char* function, uint32_t lineNumber) const; - virtual void SetError(Error::Code code, const char *contextMessage, const char* filename, - const char* function, uint32_t lineNumber) const; - virtual void SetWPIError(const char *errorMessage, const char *contextMessage, - const char* filename, const char* function, uint32_t lineNumber) const; - virtual void CloneError(ErrorBase *rhs) const; - virtual void ClearError() const; - virtual bool StatusIsFatal() const; - static void SetGlobalError(Error::Code code, const char *contextMessage, const char* filename, - const char* function, uint32_t lineNumber); - static void SetGlobalWPIError(const char *errorMessage, const char *contextMessage, - const char* filename, const char* function, uint32_t lineNumber); - static Error& GetGlobalError(); -protected: - mutable Error m_error; - // TODO: Replace globalError with a global list of all errors. - static MUTEX_ID _globalErrorMutex; - static Error _globalError; - ErrorBase(); -private: - DISALLOW_COPY_AND_ASSIGN(ErrorBase); -}; diff --git a/wpilibc/wpilibC++Sim/include/GenericHID.h b/wpilibc/wpilibC++Sim/include/GenericHID.h deleted file mode 100644 index ac3518942f..0000000000 --- a/wpilibc/wpilibC++Sim/include/GenericHID.h +++ /dev/null @@ -1,36 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ -#pragma once - -#include - -/** GenericHID Interface - */ -class GenericHID -{ -public: - enum JoystickHand - { - kLeftHand = 0, - kRightHand = 1 - }; - - virtual ~GenericHID() - { - } - - virtual float GetX(JoystickHand hand = kRightHand) = 0; - virtual float GetY(JoystickHand hand = kRightHand) = 0; - virtual float GetZ() = 0; - virtual float GetTwist() = 0; - virtual float GetThrottle() = 0; - virtual float GetRawAxis(uint32_t axis) = 0; - - virtual bool GetTrigger(JoystickHand hand = kRightHand) = 0; - virtual bool GetTop(JoystickHand hand = kRightHand) = 0; - virtual bool GetBumper(JoystickHand hand = kRightHand) = 0; - virtual bool GetRawButton(uint32_t button) = 0; -}; diff --git a/wpilibc/wpilibC++Sim/include/LiveWindow/LiveWindow.h b/wpilibc/wpilibC++Sim/include/LiveWindow/LiveWindow.h deleted file mode 100644 index 93f9cca4cd..0000000000 --- a/wpilibc/wpilibC++Sim/include/LiveWindow/LiveWindow.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef _LIVE_WINDOW_H -#define _LIVE_WINDOW_H - -#include "LiveWindow/LiveWindowSendable.h" -#include "tables/ITable.h" -#include "Commands/Scheduler.h" -#include -#include - -struct LiveWindowComponent -{ - std::string subsystem; - std::string name; - bool isSensor; - - LiveWindowComponent() - {}//WTF? - LiveWindowComponent(std::string subsystem, std::string name, bool isSensor) - { - this->subsystem = subsystem; - this->name = name; - this->isSensor = isSensor; - } -}; - -/** - * The LiveWindow class is the public interface for putting sensors and actuators - * on the LiveWindow. - * - * @author Brad Miller - */ -class LiveWindow { -public: - static LiveWindow * GetInstance(); - void Run(); - void AddSensor(const char *subsystem, const char *name, LiveWindowSendable *component); - void AddActuator(const char *subsystem, const char *name, LiveWindowSendable *component); - void AddSensor(std::string type, int channel, LiveWindowSendable *component); - void AddActuator(std::string type, int channel, LiveWindowSendable *component); - void AddActuator(std::string type, int module, int channel, LiveWindowSendable *component); - - bool IsEnabled() { return m_enabled; } - void SetEnabled(bool enabled); - -protected: - LiveWindow(); - virtual ~LiveWindow(); - -private: - void UpdateValues(); - void Initialize(); - void InitializeLiveWindowComponents(); - - std::vector m_sensors; - std::map m_components; - - static LiveWindow *m_instance; - ITable *m_liveWindowTable; - ITable *m_statusTable; - - Scheduler *m_scheduler; - - bool m_enabled; - bool m_firstTime; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/LiveWindow/LiveWindowSendable.h b/wpilibc/wpilibC++Sim/include/LiveWindow/LiveWindowSendable.h deleted file mode 100644 index abc4f7ed4c..0000000000 --- a/wpilibc/wpilibC++Sim/include/LiveWindow/LiveWindowSendable.h +++ /dev/null @@ -1,40 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) Patrick Plenefisch 2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef LIVEWINDOWSENDABLE_H_ -#define LIVEWINDOWSENDABLE_H_ - -#include "SmartDashboard/Sendable.h" - -/** - * Live Window Sendable is a special type of object sendable to the live window. - * - * @author Patrick Plenefisch - */ -class LiveWindowSendable: public Sendable -{ -public: - /** - * Update the table for this sendable object with the latest - * values. - */ - virtual void UpdateTable() = 0; - - /** - * Start having this sendable object automatically respond to - * value changes reflect the value on the table. - */ - virtual void StartLiveWindowMode() = 0; - - /** - * Stop having this sendable object automatically respond to value - * changes. - */ - virtual void StopLiveWindowMode() = 0; -}; - - -#endif /* LIVEWINDOWSENDABLE_H_ */ diff --git a/wpilibc/wpilibC++Sim/include/LiveWindow/LiveWindowStatusListener.h b/wpilibc/wpilibC++Sim/include/LiveWindow/LiveWindowStatusListener.h deleted file mode 100644 index 7c701e3fce..0000000000 --- a/wpilibc/wpilibC++Sim/include/LiveWindow/LiveWindowStatusListener.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _LIVE_WINDOW_STATUS_LISTENER_H -#define _LIVE_WINDOW_STATUS_LISTENER_H - -#include "tables/ITable.h" -#include "tables/ITableListener.h" - -class LiveWindowStatusListener : public ITableListener { -public: - virtual void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew); -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/PIDOutput.h b/wpilibc/wpilibC++Sim/include/PIDOutput.h deleted file mode 100644 index a2e2c95de6..0000000000 --- a/wpilibc/wpilibC++Sim/include/PIDOutput.h +++ /dev/null @@ -1,20 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ -#pragma once - -#include "Base.h" - -/** - * PIDOutput interface is a generic output for the PID class. - * PWMs use this class. - * Users implement this interface to allow for a PIDController to - * read directly from the inputs - */ -class PIDOutput -{ -public: - virtual void PIDWrite(float output) = 0; -}; diff --git a/wpilibc/wpilibC++Sim/include/PIDSource.h b/wpilibc/wpilibC++Sim/include/PIDSource.h deleted file mode 100644 index e81bd286df..0000000000 --- a/wpilibc/wpilibC++Sim/include/PIDSource.h +++ /dev/null @@ -1,18 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ -#pragma once - -/** - * PIDSource interface is a generic sensor source for the PID class. - * All sensors that can be used with the PID class will implement the PIDSource that - * returns a standard value that will be used in the PID code. - */ -class PIDSource -{ -public: - enum PIDSourceParameter {kDistance, kRate, kAngle}; - virtual double PIDGet() = 0; -}; diff --git a/wpilibc/wpilibC++Sim/include/Resource.h b/wpilibc/wpilibC++Sim/include/Resource.h deleted file mode 100644 index 797bd669ef..0000000000 --- a/wpilibc/wpilibC++Sim/include/Resource.h +++ /dev/null @@ -1,39 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ -#pragma once - -#include "ErrorBase.h" -#include "HAL/cpp/Synchronized.hpp" - -/** - * The Resource class is a convenient way to track allocated resources. - * It tracks them as indicies in the range [0 .. elements - 1]. - * E.g. the library uses this to track hardware channel allocation. - * - * The Resource class does not allocate the hardware channels or other - * resources; it just tracks which indices were marked in use by - * Allocate and not yet freed by Free. - */ -class Resource : public ErrorBase -{ -public: - virtual ~Resource(); - static void CreateResourceObject(Resource **r, uint32_t elements); - uint32_t Allocate(const char *resourceDesc); - uint32_t Allocate(uint32_t index, const char *resourceDesc); - void Free(uint32_t index); - -private: - explicit Resource(uint32_t size); - - bool *m_isAllocated; - ReentrantSemaphore m_allocateLock; - uint32_t m_size; - - static ReentrantSemaphore m_createLock; - - DISALLOW_COPY_AND_ASSIGN(Resource); -}; diff --git a/wpilibc/wpilibC++Sim/include/SensorBase.h b/wpilibc/wpilibC++Sim/include/SensorBase.h deleted file mode 100644 index ef4e296ce9..0000000000 --- a/wpilibc/wpilibC++Sim/include/SensorBase.h +++ /dev/null @@ -1,54 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ -#pragma once - -#include "ErrorBase.h" -#include -#include "Base.h" - -/** - * Base class for all sensors. - * Stores most recent status information as well as containing utility functions for checking - * channels and error processing. - */ -class SensorBase : public ErrorBase -{ -public: - SensorBase(); - virtual ~SensorBase(); - static void DeleteSingletons(); - - static uint32_t GetDefaultSolenoidModule() - { - return 1; - } - - static bool CheckSolenoidModule(uint8_t moduleNumber); - static bool CheckDigitalChannel(uint32_t channel); - static bool CheckRelayChannel(uint32_t channel); - static bool CheckPWMChannel(uint32_t channel); - static bool CheckAnalogInput(uint32_t channel); - static bool CheckAnalogOutput(uint32_t channel); - static bool CheckSolenoidChannel(uint32_t channel); - static bool CheckPDPChannel(uint32_t channel); - - static const uint32_t kDigitalChannels = 20; - static const uint32_t kAnalogInputs = 8; - static const uint32_t kAnalogOutputs = 2; - static const uint32_t kSolenoidChannels = 8; - static const uint32_t kSolenoidModules = 2; - static const uint32_t kPwmChannels = 20; - static const uint32_t kRelayChannels = 8; - static const uint32_t kPDPChannels = 16; - static const uint32_t kChassisSlots = 8; -protected: - void AddToSingletonList(); - -private: - DISALLOW_COPY_AND_ASSIGN(SensorBase); - static SensorBase *m_singletonList; - SensorBase *m_nextSingleton; -}; diff --git a/wpilibc/wpilibC++Sim/include/SmartDashboard/NamedSendable.h b/wpilibc/wpilibC++Sim/include/SmartDashboard/NamedSendable.h deleted file mode 100644 index 8be059b3f0..0000000000 --- a/wpilibc/wpilibC++Sim/include/SmartDashboard/NamedSendable.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * NamedSendable.h - * - * Created on: Oct 19, 2012 - * Author: Mitchell Wills - */ - -#ifndef NAMEDSENDABLE_H_ -#define NAMEDSENDABLE_H_ - - -#include -#include "SmartDashboard/Sendable.h" - -/** - * The interface for sendable objects that gives the sendable a default name in the Smart Dashboard - * - */ -class NamedSendable : public Sendable -{ -public: - - /** - * @return the name of the subtable of SmartDashboard that the Sendable object will use - */ - virtual std::string GetName() = 0; -}; - -#endif /* NAMEDSENDABLE_H_ */ diff --git a/wpilibc/wpilibC++Sim/include/SmartDashboard/Sendable.h b/wpilibc/wpilibC++Sim/include/SmartDashboard/Sendable.h deleted file mode 100644 index e5c86985fb..0000000000 --- a/wpilibc/wpilibC++Sim/include/SmartDashboard/Sendable.h +++ /dev/null @@ -1,33 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __SMART_DASHBOARD_DATA__ -#define __SMART_DASHBOARD_DATA__ - -#include -#include "tables/ITable.h" - -class Sendable -{ -public: - /** - * Initializes a table for this sendable object. - * @param subtable The table to put the values in. - */ - virtual void InitTable(ITable* subtable) = 0; - - /** - * @return the table that is currently associated with the sendable - */ - virtual ITable* GetTable() = 0; - - /** - * @return the string representation of the named data type that will be used by the smart dashboard for this sendable - */ - virtual std::string GetSmartDashboardType() = 0; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/SmartDashboard/SendableChooser.h b/wpilibc/wpilibC++Sim/include/SmartDashboard/SendableChooser.h deleted file mode 100644 index 7a119b4fb6..0000000000 --- a/wpilibc/wpilibC++Sim/include/SmartDashboard/SendableChooser.h +++ /dev/null @@ -1,47 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __SENDABLE_CHOOSER_H__ -#define __SENDABLE_CHOOSER_H__ - -#include "SmartDashboard/Sendable.h" -#include "tables/ITable.h" -#include -#include - -/** - * The {@link SendableChooser} class is a useful tool for presenting a selection of options - * to the {@link SmartDashboard}. - * - *

For instance, you may wish to be able to select between multiple autonomous modes. - * You can do this by putting every possible {@link Command} you want to run as an autonomous into - * a {@link SendableChooser} and then put it into the {@link SmartDashboard} to have a list of options - * appear on the laptop. Once autonomous starts, simply ask the {@link SendableChooser} what the selected - * value is.

- * - * @see SmartDashboard - */ -class SendableChooser : public Sendable -{ -public: - SendableChooser(); - virtual ~SendableChooser() {}; - - void AddObject(const char *name, void *object); - void AddDefault(const char *name, void *object); - void *GetSelected(); - - virtual void InitTable(ITable* subtable); - virtual ITable* GetTable(); - virtual std::string GetSmartDashboardType(); - -private: - std::string m_defaultChoice; - std::map m_choices; - ITable *m_table; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/include/SmartDashboard/SmartDashboard.h b/wpilibc/wpilibC++Sim/include/SmartDashboard/SmartDashboard.h deleted file mode 100644 index 5c6d3cda04..0000000000 --- a/wpilibc/wpilibC++Sim/include/SmartDashboard/SmartDashboard.h +++ /dev/null @@ -1,56 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef __SMART_DASHBOARD_H__ -#define __SMART_DASHBOARD_H__ - -#include "ErrorBase.h" -#include -#include -#include "Base.h" -#include "SmartDashboard/Sendable.h" -#include "SmartDashboard/NamedSendable.h" -#include "tables/ITable.h" - - -class SmartDashboard : public ErrorBase -{ -public: - static void init(); - - static void PutData(std::string key, Sendable *data); - static void PutData(NamedSendable *value); - //static Sendable* GetData(std::string keyName); - - static void PutBoolean(std::string keyName, bool value); - static bool GetBoolean(std::string keyName); - - static void PutNumber(std::string keyName, double value); - static double GetNumber(std::string keyName); - - static void PutString(std::string keyName, std::string value); - static int GetString(std::string keyName, char *value, unsigned int valueLen); - static std::string GetString(std::string keyName); - - static void PutValue(std::string keyName, ComplexData& value); - static void RetrieveValue(std::string keyName, ComplexData& value); -private: - SmartDashboard(); - virtual ~SmartDashboard(); - DISALLOW_COPY_AND_ASSIGN(SmartDashboard); - - /** The {@link NetworkTable} used by {@link SmartDashboard} */ - static ITable* m_table; - - /** - * A map linking tables in the SmartDashboard to the {@link SmartDashboardData} objects - * they came from. - */ - static std::map m_tablesToData; -}; - -#endif - diff --git a/wpilibc/wpilibC++Sim/include/WPIErrors.h b/wpilibc/wpilibC++Sim/include/WPIErrors.h deleted file mode 100644 index 3968c7d8c1..0000000000 --- a/wpilibc/wpilibC++Sim/include/WPIErrors.h +++ /dev/null @@ -1,76 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ -#pragma once - -#ifdef WPI_ERRORS_DEFINE_STRINGS -#define S(label, offset, message) const char *wpi_error_s_##label = message ; -#else -#define S(label, offset, message) extern const char *wpi_error_s_##label; -#endif - -/* - * Fatal errors - */ -S(ModuleIndexOutOfRange, -1, "Allocating module that is out of range or not found"); -S(ChannelIndexOutOfRange, -1, "Allocating channel that is out of range"); -S(NotAllocated, -2, "Attempting to free unallocated resource"); -S(ResourceAlreadyAllocated, -3, "Attempted to reuse an allocated resource"); -S(NoAvailableResources, -4, "No available resources to allocate"); -S(NullParameter, -5, "A pointer parameter to a method is NULL"); -S(Timeout, -6, "A timeout has been exceeded"); -S(CompassManufacturerError, -7, "Compass manufacturer doesn't match HiTechnic"); -S(CompassTypeError, -8, "Compass type doesn't match expected type for HiTechnic compass"); -S(IncompatibleMode, -9, "The object is in an incompatible mode"); -S(AnalogTriggerLimitOrderError, -10, "AnalogTrigger limits error. Lower limit > Upper Limit"); -S(AnalogTriggerPulseOutputError, -11, "Attempted to read AnalogTrigger pulse output."); -S(TaskError, -12, "Task can't be started"); -S(TaskIDError, -13, "Task error: Invalid ID."); -S(TaskDeletedError, -14, "Task error: Task already deleted."); -S(TaskOptionsError, -15, "Task error: Invalid options."); -S(TaskMemoryError, -16, "Task can't be started due to insufficient memory."); -S(TaskPriorityError, -17, "Task error: Invalid priority [1-255]."); -S(DriveUninitialized, -18, "RobotDrive not initialized for the C interface"); -S(CompressorNonMatching, -19, "Compressor slot/channel doesn't match previous instance"); -S(CompressorAlreadyDefined, -20, "Creating a second compressor instance"); -S(CompressorUndefined, -21, "Using compressor functions without defining compressor"); -S(InconsistentArrayValueAdded, -22, "When packing data into an array to the dashboard, not all values added were of the same type."); -S(MismatchedComplexTypeClose, -23, "When packing data to the dashboard, a Close for a complex type was called without a matching Open."); -S(DashboardDataOverflow, -24, "When packing data to the dashboard, too much data was packed and the buffer overflowed."); -S(DashboardDataCollision, -25, "The same buffer was used for packing data and for printing."); -S(EnhancedIOMissing, -26, "IO is not attached or Enhanced IO is not enabled."); -S(LineNotOutput, -27, "Cannot SetDigitalOutput for a line not configured for output."); -S(ParameterOutOfRange, -28, "A parameter is out of range."); -S(SPIClockRateTooLow, -29, "SPI clock rate was below the minimum supported"); -S(JaguarVersionError, -30, "Jaguar firmware version error"); -S(JaguarMessageNotFound, -31, "Jaguar message not found"); -S(NetworkTablesReadError, -40, "Error reading NetworkTables socket"); -S(NetworkTablesBufferFull, -41, "Buffer full writing to NetworkTables socket"); -S(NetworkTablesWrongType, -42, "The wrong type was read from the NetworkTables entry"); -S(NetworkTablesCorrupt, -43, "NetworkTables data stream is corrupt"); -S(SmartDashboardMissingKey, -43, "SmartDashboard data does not exist"); -S(CommandIllegalUse, -50, "Illegal use of Command"); -S(UnsupportedInSimulation, -80, "Unsupported in simulation"); - -/* - * Warnings - */ -S(SampleRateTooHigh, 1, "Analog module sample rate is too high"); -S(VoltageOutOfRange, 2, "Voltage to convert to raw value is out of range [-10; 10]"); -S(CompressorTaskError, 3, "Compressor task won't start"); -S(LoopTimingError, 4, "Digital module loop timing is not the expected value"); -S(NonBinaryDigitalValue, 5, "Digital output value is not 0 or 1"); -S(IncorrectBatteryChannel, 6, "Battery measurement channel is not correct value"); -S(BadJoystickIndex, 7, "Joystick index is out of range, should be 1-4"); -S(BadJoystickAxis, 8, "Joystick axis is out of range"); -S(InvalidMotorIndex, 9, "Motor index is out of range, should be 0-3"); -S(DriverStationTaskError, 10, "Driver Station task won't start"); -S(EnhancedIOPWMPeriodOutOfRange, 11, "Driver Station Enhanced IO PWM Output period out of range."); -S(SPIWriteNoMOSI, 12, "Cannot write to SPI port with no MOSI output"); -S(SPIReadNoMISO, 13, "Cannot read from SPI port with no MISO input"); -S(SPIReadNoData, 14, "No data available to read from SPI"); -S(IncompatibleState, 15, "Incompatible State: The operation cannot be completed"); - -#undef S diff --git a/wpilibc/wpilibC++Sim/include/interfaces/Potentiometer.h b/wpilibc/wpilibC++Sim/include/interfaces/Potentiometer.h deleted file mode 100644 index f5f45674cb..0000000000 --- a/wpilibc/wpilibC++Sim/include/interfaces/Potentiometer.h +++ /dev/null @@ -1,27 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#ifndef INTERFACES_POTENTIOMETER_H -#define INTERFACES_POTENTIOMETER_H - -#include "PIDSource.h" - -/** - * Interface for potentiometers. - */ -class Potentiometer : public PIDSource -{ -public: - virtual ~Potentiometer() {}; - /** - * Common interface for getting the current value of a potentiometer. - * - * @return The current set speed. Value is between -1.0 and 1.0. - */ - virtual double Get() = 0; -}; - -#endif diff --git a/wpilibc/wpilibC++Sim/src/AnalogInput.cpp b/wpilibc/wpilibC++Sim/src/AnalogInput.cpp index 568c5d7ad4..a947f6b5d4 100644 --- a/wpilibc/wpilibC++Sim/src/AnalogInput.cpp +++ b/wpilibc/wpilibC++Sim/src/AnalogInput.cpp @@ -13,7 +13,7 @@ */ void AnalogInput::InitAnalogInput(uint32_t channel) { - m_table = NULL; + m_table = NULL; m_channel = channel; char buffer[50]; diff --git a/wpilibc/wpilibC++Sim/src/Commands/Command.cpp b/wpilibc/wpilibC++Sim/src/Commands/Command.cpp deleted file mode 100644 index f6a5bd1c9c..0000000000 --- a/wpilibc/wpilibC++Sim/src/Commands/Command.cpp +++ /dev/null @@ -1,475 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Commands/Command.h" -#include "Commands/CommandGroup.h" -#include "Commands/Scheduler.h" -#include "DriverStation.h" -#include "Timer.h" -#include "WPIErrors.h" - -static const char *kName = "name"; -static const char *kRunning = "running"; -static const char *kIsParented = "isParented"; - -int Command::m_commandCounter = 0; - -void Command::InitCommand(const char *name, double timeout) -{ - m_commandID = m_commandCounter++; - m_timeout = timeout; - m_locked = false; - m_startTime = -1; - m_initialized = false; - m_running = false; - m_interruptible = true; - m_canceled = false; - m_runWhenDisabled = false; - m_parent = NULL; - if (name == NULL) - { - // Don't have a way to find the subclass name like java, so use the address - char buf[32]; - snprintf(buf, 32, "Command_%p", this); - m_name = buf; - } - else - { - m_name = name; - } - m_table = NULL; -} - -/** - * Creates a new command. - * The name of this command will be default. - */ -Command::Command() -{ - InitCommand(NULL, -1.0); -} - -/** - * Creates a new command with the given name and no timeout. - * @param name the name for this command - */ -Command::Command(const char *name) -{ - if (name == NULL) - wpi_setWPIErrorWithContext(NullParameter, "name"); - InitCommand(name, -1.0); -} - -/** - * Creates a new command with the given timeout and a default name. - * @param timeout the time (in seconds) before this command "times out" - * @see Command#isTimedOut() isTimedOut() - */ -Command::Command(double timeout) -{ - if (timeout < 0.0) - wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0"); - InitCommand(NULL, timeout); -} - -/** - * Creates a new command with the given name and timeout. - * @param name the name of the command - * @param timeout the time (in seconds) before this command "times out" - * @see Command#isTimedOut() isTimedOut() - */ -Command::Command(const char *name, double timeout) -{ - if (name == NULL) - wpi_setWPIErrorWithContext(NullParameter, "name"); - if (timeout < 0.0) - wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0"); - InitCommand(name, timeout); -} - -Command::~Command() -{//TODO deal with cleaning up all listeners - /*if (m_table != NULL){ - m_table->RemoveChangeListener(kRunning, this); - }*/ -} - -/** - * Get the ID (sequence number) for this command - * The ID is a unique sequence number that is incremented for each command. - * @return the ID of this command - */ -int Command::GetID() { - return m_commandID; -} - -/** - * Sets the timeout of this command. - * @param timeout the timeout (in seconds) - * @see Command#isTimedOut() isTimedOut() - */ -void Command::SetTimeout(double timeout) -{ - if (timeout < 0.0) - wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0"); - else - m_timeout = timeout; -} - -/** - * Returns the time since this command was initialized (in seconds). - * This function will work even if there is no specified timeout. - * @return the time since this command was initialized (in seconds). - */ -double Command::TimeSinceInitialized() -{ - if (m_startTime < 0.0) - return 0.0; - else - return Timer::GetFPGATimestamp() - m_startTime; -} - -/** - * This method specifies that the given {@link Subsystem} is used by this command. - * This method is crucial to the functioning of the Command System in general. - * - *

Note that the recommended way to call this method is in the constructor.

- * - * @param subsystem the {@link Subsystem} required - * @see Subsystem - */ -void Command::Requires(Subsystem *subsystem) -{ - if (!AssertUnlocked("Can not add new requirement to command")) - return; - - if (subsystem != NULL) - m_requirements.insert(subsystem); - else - wpi_setWPIErrorWithContext(NullParameter, "subsystem"); -} - -/** - * Called when the command has been removed. - * This will call {@link Command#interrupted() interrupted()} or {@link Command#end() end()}. - */ -void Command::Removed() -{ - if (m_initialized) - { - if (IsCanceled()) - { - Interrupted(); - _Interrupted(); - } - else - { - End(); - _End(); - } - } - m_initialized = false; - m_canceled = false; - m_running = false; - if (m_table != NULL) - m_table->PutBoolean(kRunning, false); -} - -/** - * Starts up the command. Gets the command ready to start. - *

Note that the command will eventually start, however it will not necessarily - * do so immediately, and may in fact be canceled before initialize is even called.

- */ -void Command::Start() -{ - LockChanges(); - if (m_parent != NULL) - wpi_setWPIErrorWithContext(CommandIllegalUse, "Can not start a command that is part of a command group"); - - Scheduler::GetInstance()->AddCommand(this); -} - -/** - * The run method is used internally to actually run the commands. - * @return whether or not the command should stay within the {@link Scheduler}. - */ -bool Command::Run() -{ - if (!m_runWhenDisabled && m_parent == NULL && false) // XXX: BROKEN! && DriverStation::GetInstance()->IsDisabled()) - Cancel(); - - if (IsCanceled()) - return false; - - if (!m_initialized) - { - m_initialized = true; - StartTiming(); - _Initialize(); - Initialize(); - } - _Execute(); - Execute(); - return !IsFinished(); -} - -void Command::_Initialize() -{ -} - -void Command::_Interrupted() -{ -} - -void Command::_Execute() -{ -} - -void Command::_End() -{ -} - -/** - * Called to indicate that the timer should start. - * This is called right before {@link Command#initialize() initialize()} is, inside the - * {@link Command#run() run()} method. - */ -void Command::StartTiming() -{ - m_startTime = Timer::GetFPGATimestamp(); -} - -/** - * Returns whether or not the {@link Command#timeSinceInitialized() timeSinceInitialized()} - * method returns a number which is greater than or equal to the timeout for the command. - * If there is no timeout, this will always return false. - * @return whether the time has expired - */ -bool Command::IsTimedOut() -{ - return m_timeout != -1 && TimeSinceInitialized() >= m_timeout; -} - -/** - * Returns the requirements (as an std::set of {@link Subsystem Subsystems} pointers) of this command - * @return the requirements (as an std::set of {@link Subsystem Subsystems} pointers) of this command - */ -Command::SubsystemSet Command::GetRequirements() -{ - return m_requirements; -} - -/** - * Prevents further changes from being made - */ -void Command::LockChanges() -{ - m_locked = true; -} - -/** - * If changes are locked, then this will generate a CommandIllegalUse error. - * @param message the message to report on error (it is appended by a default message) - * @return true if assert passed, false if assert failed - */ -bool Command::AssertUnlocked(const char *message) -{ - if (m_locked) - { - char buf[128]; - snprintf(buf, 128, "%s after being started or being added to a command group", message); - wpi_setWPIErrorWithContext(CommandIllegalUse, buf); - return false; - } - return true; -} - -/** - * Sets the parent of this command. No actual change is made to the group. - * @param parent the parent - */ -void Command::SetParent(CommandGroup *parent) -{ - if (parent == NULL) - { - wpi_setWPIErrorWithContext(NullParameter, "parent"); - } - else if (m_parent != NULL) - { - wpi_setWPIErrorWithContext(CommandIllegalUse, "Can not give command to a command group after already being put in a command group"); - } - else - { - LockChanges(); - m_parent = parent; - if (m_table != NULL) - { - m_table->PutBoolean(kIsParented, true); - } - } -} - -/** - * This is used internally to mark that the command has been started. - * The lifecycle of a command is: - * - * startRunning() is called. - * run() is called (multiple times potentially) - * removed() is called - * - * It is very important that startRunning and removed be called in order or some assumptions - * of the code will be broken. - */ -void Command::StartRunning() -{ - m_running = true; - m_startTime = -1; - if (m_table != NULL) - m_table->PutBoolean(kRunning, true); -} - -/** - * Returns whether or not the command is running. - * This may return true even if the command has just been canceled, as it may - * not have yet called {@link Command#interrupted()}. - * @return whether or not the command is running - */ -bool Command::IsRunning() -{ - return m_running; -} - -/** - * This will cancel the current command. - *

This will cancel the current command eventually. It can be called multiple times. - * And it can be called when the command is not running. If the command is running though, - * then the command will be marked as canceled and eventually removed.

- *

A command can not be canceled - * if it is a part of a command group, you must cancel the command group instead.

- */ -void Command::Cancel() -{ - if (m_parent != NULL) - wpi_setWPIErrorWithContext(CommandIllegalUse, "Can not cancel a command that is part of a command group"); - - _Cancel(); -} - -/** - * This works like cancel(), except that it doesn't throw an exception if it is a part - * of a command group. Should only be called by the parent command group. - */ -void Command::_Cancel() -{ - if (IsRunning()) - m_canceled = true; -} - -/** - * Returns whether or not this has been canceled. - * @return whether or not this has been canceled - */ -bool Command::IsCanceled() -{ - return m_canceled; -} - -/** - * Returns whether or not this command can be interrupted. - * @return whether or not this command can be interrupted - */ -bool Command::IsInterruptible() -{ - return m_interruptible; -} - -/** - * Sets whether or not this command can be interrupted. - * @param interruptible whether or not this command can be interrupted - */ -void Command::SetInterruptible(bool interruptible) -{ - m_interruptible = interruptible; -} - -/** - * Checks if the command requires the given {@link Subsystem}. - * @param system the system - * @return whether or not the subsystem is required (false if given NULL) - */ -bool Command::DoesRequire(Subsystem *system) -{ - return m_requirements.count(system) > 0; -} - -/** - * Returns the {@link CommandGroup} that this command is a part of. - * Will return null if this {@link Command} is not in a group. - * @return the {@link CommandGroup} that this command is a part of (or null if not in group) - */ -CommandGroup *Command::GetGroup() -{ - return m_parent; -} - -/** - * Sets whether or not this {@link Command} should run when the robot is disabled. - * - *

By default a command will not run when the robot is disabled, and will in fact be canceled.

- * @param run whether or not this command should run when the robot is disabled - */ -void Command::SetRunWhenDisabled(bool run) -{ - m_runWhenDisabled = run; -} - -/** - * Returns whether or not this {@link Command} will run when the robot is disabled, or if it will cancel itself. - * @return whether or not this {@link Command} will run when the robot is disabled, or if it will cancel itself - */ -bool Command::WillRunWhenDisabled() -{ - return m_runWhenDisabled; -} - -std::string Command::GetName() -{ - return m_name; -} - -std::string Command::GetSmartDashboardType() -{ - return "Command"; -} - -void Command::InitTable(ITable* table) -{ - if(m_table!=NULL) - m_table->RemoveTableListener(this); - m_table = table; - if(m_table!=NULL){ - m_table->PutString(kName, GetName()); - m_table->PutBoolean(kRunning, IsRunning()); - m_table->PutBoolean(kIsParented, m_parent != NULL); - m_table->AddTableListener(kRunning, this, false); - } -} - -ITable* Command::GetTable(){ - return m_table; -} - -void Command::ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew) -{ - if (value.b){ - if(!IsRunning()) - Start(); - } - else{ - if(IsRunning()) - Cancel(); - } -} diff --git a/wpilibc/wpilibC++Sim/src/Commands/PIDSubsystem.cpp b/wpilibc/wpilibC++Sim/src/Commands/PIDSubsystem.cpp deleted file mode 100644 index b0937257e4..0000000000 --- a/wpilibc/wpilibC++Sim/src/Commands/PIDSubsystem.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Commands/PIDSubsystem.h" -#include "PIDController.h" -#include "float.h" - -// XXX max and min are not used? - -/** - * Instantiates a {@link PIDSubsystem} that will use the given p, i and d values. - * @param name the name - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - */ -PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d) : - Subsystem(name) -{ - m_controller = new PIDController(p, i, d, this, this); -} - -/** - * Instantiates a {@link PIDSubsystem} that will use the given p, i and d values. - * @param name the name - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - * @param f the feedforward value - */ -PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d, double f) : - Subsystem(name) -{ - m_controller = new PIDController(p, i, d, f, this, this); -} - -/** - * Instantiates a {@link PIDSubsystem} that will use the given p, i and d values. It will also space the time - * between PID loop calculations to be equal to the given period. - * @param name the name - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - * @param f the feedfoward value - * @param period the time (in seconds) between calculations - */ -PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d, double f, - double period) : - Subsystem(name) -{ - m_controller = new PIDController(p, i, d, f, this, this, period); -} - -/** - * Instantiates a {@link PIDSubsystem} that will use the given p, i and d values. - * It will use the class name as its name. - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - */ -PIDSubsystem::PIDSubsystem(double p, double i, double d) : - Subsystem("PIDSubsystem") -{ - m_controller = new PIDController(p, i, d, this, this); -} - -/** - * Instantiates a {@link PIDSubsystem} that will use the given p, i and d values. - * It will use the class name as its name. - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - * @param f the feedforward value - */ -PIDSubsystem::PIDSubsystem(double p, double i, double d, double f) : - Subsystem("PIDSubsystem") -{ - m_controller = new PIDController(p, i, d, f, this, this); -} - -/** - * Instantiates a {@link PIDSubsystem} that will use the given p, i and d values. - * It will use the class name as its name. - * It will also space the time - * between PID loop calculations to be equal to the given period. - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - * @param f the feedforward value - * @param period the time (in seconds) between calculations - */ -PIDSubsystem::PIDSubsystem(double p, double i, double d, double f, double period) : - Subsystem("PIDSubsystem") -{ - m_controller = new PIDController(p, i, d, f, this, this, period); -} - -PIDSubsystem::~PIDSubsystem() -{ - delete m_controller; -} - -/** - * Enables the internal {@link PIDController} - */ -void PIDSubsystem::Enable() -{ - m_controller->Enable(); -} - -/** - * Disables the internal {@link PIDController} - */ -void PIDSubsystem::Disable() -{ - m_controller->Disable(); -} - - -/** - * Returns the {@link PIDController} used by this {@link PIDSubsystem}. - * Use this if you would like to fine tune the pid loop. - * - * @return the {@link PIDController} used by this {@link PIDSubsystem} - */ -PIDController *PIDSubsystem::GetPIDController() -{ - return m_controller; -} - -/** - * Sets the setpoint to the given value. If {@link PIDCommand#SetRange(double, double) SetRange(...)} - * was called, - * then the given setpoint - * will be trimmed to fit within the range. - * @param setpoint the new setpoint - */ -void PIDSubsystem::SetSetpoint(double setpoint) -{ - m_controller->SetSetpoint(setpoint); -} - -/** - * Adds the given value to the setpoint. - * If {@link PIDCommand#SetRange(double, double) SetRange(...)} was used, - * then the bounds will still be honored by this method. - * @param deltaSetpoint the change in the setpoint - */ -void PIDSubsystem::SetSetpointRelative(double deltaSetpoint) -{ - SetSetpoint(GetSetpoint() + deltaSetpoint); -} - -/** - * Return the current setpoint - * @return The current setpoint - */ -double PIDSubsystem::GetSetpoint() -{ - return m_controller->GetSetpoint(); -} - -/** - * Sets the maximum and minimum values expected from the input. - * - * @param minimumInput the minimum value expected from the input - * @param maximumInput the maximum value expected from the output - */ -void PIDSubsystem::SetInputRange(float minimumInput, float maximumInput) -{ - m_controller->SetInputRange(minimumInput, maximumInput); -} - -/* - * Set the absolute error which is considered tolerable for use with - * OnTarget. - * @param percentage error which is tolerable - */ -void PIDSubsystem::SetAbsoluteTolerance(float absValue) { - m_controller->SetAbsoluteTolerance(absValue); -} - -/* - * Set the percentage error which is considered tolerable for use with - * OnTarget. - * @param percentage error which is tolerable - */ -void PIDSubsystem::SetPercentTolerance(float percent) { - m_controller->SetPercentTolerance(percent); -} - -/* - * Return true if the error is within the percentage of the total input range, - * determined by SetTolerance. This asssumes that the maximum and minimum input - * were set using SetInput. Use OnTarget() in the IsFinished() method of commands - * that use this subsystem. - * - * Currently this just reports on target as the actual value passes through the setpoint. - * Ideally it should be based on being within the tolerance for some period of time. - * - * @return true if the error is within the percentage tolerance of the input range - */ -bool PIDSubsystem::OnTarget() -{ - return m_controller->OnTarget(); -} - -/** - * Returns the current position - * @return the current position - */ -double PIDSubsystem::GetPosition() -{ - return ReturnPIDInput(); -} - -void PIDSubsystem::PIDWrite(float output) -{ - UsePIDOutput(output); -} - -double PIDSubsystem::PIDGet() -{ - return ReturnPIDInput(); -} - - -std::string PIDSubsystem::GetSmartDashboardType(){ - return "PIDCommand"; -} -void PIDSubsystem::InitTable(ITable* table){ - m_controller->InitTable(table); - Subsystem::InitTable(table); -} diff --git a/wpilibc/wpilibC++Sim/src/Commands/WaitUntilCommand.cpp b/wpilibc/wpilibC++Sim/src/Commands/WaitUntilCommand.cpp deleted file mode 100644 index 3d521b8156..0000000000 --- a/wpilibc/wpilibC++Sim/src/Commands/WaitUntilCommand.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "Commands/WaitUntilCommand.h" -#include "DriverStation.h" -#include "Timer.h" - -/** - * A {@link WaitCommand} will wait until a certain match time before finishing. - * This will wait until the game clock reaches some value, then continue to the - * next command. - * @see CommandGroup - */ -WaitUntilCommand::WaitUntilCommand(double time) : - Command("WaitUntilCommand", time) -{ - m_time = time; -} - -WaitUntilCommand::WaitUntilCommand(const char *name, double time) : - Command(name, time) -{ - m_time = time; -} - -void WaitUntilCommand::Initialize() -{ -} - -void WaitUntilCommand::Execute() -{ -} - -/** - * Check if we've reached the actual finish time. - */ -bool WaitUntilCommand::IsFinished() -{ - return DriverStation::GetInstance()->GetMatchTime() >= m_time; -} - -void WaitUntilCommand::End() -{ -} - -void WaitUntilCommand::Interrupted() -{ -} diff --git a/wpilibc/wpilibC++Sim/src/Error.cpp b/wpilibc/wpilibC++Sim/src/Error.cpp index c9494bda55..cf05a89f15 100644 --- a/wpilibc/wpilibC++Sim/src/Error.cpp +++ b/wpilibc/wpilibC++Sim/src/Error.cpp @@ -6,13 +6,12 @@ #include "Error.h" -#include "HAL/cpp/StackTrace.hpp" #include #include #include "Timer.h" #include "Utility.h" -bool Error::m_stackTraceEnabled = false; + bool Error::m_suspendOnErrorEnabled = false; Error::Error() @@ -99,11 +98,8 @@ void Error::Report() delete [] error; - if (m_stackTraceEnabled) - { - printf("---------------------------\n"); - printCurrentStackTrace(); - } + // printf("---------------------------\n"); + // printCurrentStackTrace(); } void Error::Clear() diff --git a/wpilibc/wpilibC++Sim/src/ErrorBase.cpp b/wpilibc/wpilibC++Sim/src/ErrorBase.cpp deleted file mode 100644 index c973798c10..0000000000 --- a/wpilibc/wpilibC++Sim/src/ErrorBase.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "ErrorBase.h" -#include "HAL/cpp/Synchronized.hpp" -#include "HAL/cpp/StackTrace.hpp" -#define WPI_ERRORS_DEFINE_STRINGS -#include "WPIErrors.h" - -#include -#include - -MUTEX_ID ErrorBase::_globalErrorMutex = initializeMutexNormal(); -Error ErrorBase::_globalError; -/** - * @brief Initialize the instance status to 0 for now. - */ -ErrorBase::ErrorBase() -{} - -ErrorBase::~ErrorBase() -{} - -/** - * @brief Retrieve the current error. - * Get the current error information associated with this sensor. - */ -Error& ErrorBase::GetError() -{ - return m_error; -} - -const Error& ErrorBase::GetError() const -{ - return m_error; -} - -/** - * @brief Clear the current error information associated with this sensor. - */ -void ErrorBase::ClearError() const -{ - m_error.Clear(); -} - -/** - * @brief Set error information associated with a C library call that set an error to the "errno" global variable. - * - * @param contextMessage A custom message from the code that set the error. - * @param filename Filename of the error source - * @param function Function of the error source - * @param lineNumber Line number of the error source - */ -void ErrorBase::SetErrnoError(const char *contextMessage, - const char* filename, const char* function, uint32_t lineNumber) const -{ - char err[256]; - int errNo = errno; - if (errNo == 0) - { - sprintf(err, "OK: %s", contextMessage); - } - else - { - char *statName = new char[256 + 1]; // TODO: MAX_SYS_SYM_LEN or linux equivalent. - if (getErrnoToName(errNo, statName)) - snprintf(err, 256, "%s (0x%08X): %s", statName, errNo, contextMessage); - else - snprintf(err, 256, "Unknown errno 0x%08X: %s", errNo, contextMessage); - delete [] statName; - } - - // Set the current error information for this object. - m_error.Set(-1, err, filename, function, lineNumber, this); - - // Update the global error if there is not one already set. - Synchronized mutex(_globalErrorMutex); - if (_globalError.GetCode() == 0) { - _globalError.Clone(m_error); - } -} - -/** - * @brief Set the current error information associated from the nivision Imaq API. - * - * @param success The return from the function - * @param contextMessage A custom message from the code that set the error. - * @param filename Filename of the error source - * @param function Function of the error source - * @param lineNumber Line number of the error source - */ -void ErrorBase::SetImaqError(int success, const char *contextMessage, const char* filename, const char* function, uint32_t lineNumber) const -{ - // If there was an error - if (success <= 0) { - //TODO: ??? char err[256]; - // XXX: sprintf(err, "%s: %s", contextMessage, imaqGetErrorText(imaqGetLastError())); - - // Set the current error information for this object. - // XXX: m_error.Set(imaqGetLastError(), err, filename, function, lineNumber, this); - - // Update the global error if there is not one already set. - Synchronized mutex(_globalErrorMutex); - if (_globalError.GetCode() == 0) { - _globalError.Clone(m_error); - } - } -} - -/** - * @brief Set the current error information associated with this sensor. - * - * @param code The error code - * @param contextMessage A custom message from the code that set the error. - * @param filename Filename of the error source - * @param function Function of the error source - * @param lineNumber Line number of the error source - */ -void ErrorBase::SetError(Error::Code code, const char *contextMessage, - const char* filename, const char* function, uint32_t lineNumber) const -{ - // If there was an error - if (code != 0) { - // Set the current error information for this object. - m_error.Set(code, contextMessage, filename, function, lineNumber, this); - - // Update the global error if there is not one already set. - Synchronized mutex(_globalErrorMutex); - if (_globalError.GetCode() == 0) { - _globalError.Clone(m_error); - } - } -} - -/** - * @brief Set the current error information associated with this sensor. - * - * @param errorMessage The error message from WPIErrors.h - * @param contextMessage A custom message from the code that set the error. - * @param filename Filename of the error source - * @param function Function of the error source - * @param lineNumber Line number of the error source - */ -void ErrorBase::SetWPIError(const char *errorMessage, const char *contextMessage, - const char* filename, const char* function, uint32_t lineNumber) const -{ - char err[256]; - sprintf(err, "%s: %s", errorMessage, contextMessage); - - // Set the current error information for this object. - m_error.Set(-1, err, filename, function, lineNumber, this); - - // Update the global error if there is not one already set. - Synchronized mutex(_globalErrorMutex); - if (_globalError.GetCode() == 0) { - _globalError.Clone(m_error); - } -} - -void ErrorBase::CloneError(ErrorBase *rhs) const -{ - m_error.Clone(rhs->GetError()); -} - -/** -@brief Check if the current error code represents a fatal error. - -@return true if the current error is fatal. -*/ -bool ErrorBase::StatusIsFatal() const -{ - return m_error.GetCode() < 0; -} - -void ErrorBase::SetGlobalError(Error::Code code, const char *contextMessage, - const char* filename, const char* function, uint32_t lineNumber) -{ - // If there was an error - if (code != 0) { - Synchronized mutex(_globalErrorMutex); - - // Set the current error information for this object. - _globalError.Set(code, contextMessage, filename, function, lineNumber, NULL); - } -} - -void ErrorBase::SetGlobalWPIError(const char *errorMessage, const char *contextMessage, - const char* filename, const char* function, uint32_t lineNumber) -{ - char err[256]; - sprintf(err, "%s: %s", errorMessage, contextMessage); - - Synchronized mutex(_globalErrorMutex); - if (_globalError.GetCode() != 0) { - _globalError.Clear(); - } - _globalError.Set(-1, err, filename, function, lineNumber, NULL); -} - -/** - * Retrieve the current global error. -*/ -Error& ErrorBase::GetGlobalError() -{ - Synchronized mutex(_globalErrorMutex); - return _globalError; -} - diff --git a/wpilibc/wpilibC++Sim/src/LiveWindow/LiveWindow.cpp b/wpilibc/wpilibC++Sim/src/LiveWindow/LiveWindow.cpp deleted file mode 100644 index 6d28f0d79a..0000000000 --- a/wpilibc/wpilibC++Sim/src/LiveWindow/LiveWindow.cpp +++ /dev/null @@ -1,200 +0,0 @@ -#include "LiveWindow/LiveWindow.h" -#include "networktables/NetworkTable.h" -#include -#include - -LiveWindow* LiveWindow::m_instance = NULL; - -/** - * Get an instance of the LiveWindow main class - * This is a singleton to guarantee that there is only a single instance regardless of - * how many times GetInstance is called. - */ -LiveWindow * LiveWindow::GetInstance() -{ - if (m_instance == NULL) - { - m_instance = new LiveWindow(); - } - return m_instance; -} - -/** - * LiveWindow constructor. - * Allocate the necessary tables. - */ -LiveWindow::LiveWindow() -{ - m_enabled = false; - m_liveWindowTable = NetworkTable::GetTable("LiveWindow"); - m_statusTable = m_liveWindowTable->GetSubTable("~STATUS~"); - m_scheduler = Scheduler::GetInstance(); -} - -/** - * Change the enabled status of LiveWindow - * If it changes to enabled, start livewindow running otherwise stop it - */ -void LiveWindow::SetEnabled(bool enabled) -{ - if (m_enabled == enabled) - return; - if (enabled) - { - if (m_firstTime) - { - InitializeLiveWindowComponents(); - m_firstTime = false; - } - m_scheduler->SetEnabled(false); - m_scheduler->RemoveAll(); - for (std::map::iterator it = - m_components.begin(); it != m_components.end(); ++it) - { - it->first->StartLiveWindowMode(); - } - } - else - { - for (std::map::iterator it = - m_components.begin(); it != m_components.end(); ++it) - { - it->first->StopLiveWindowMode(); - } - m_scheduler->SetEnabled(true); - } - m_enabled = enabled; - m_statusTable->PutBoolean("LW Enabled", m_enabled); -} - -LiveWindow::~LiveWindow() -{ -} - -/** - * Add a Sensor associated with the subsystem and with call it by the given name. - * @param subsystem The subsystem this component is part of. - * @param name The name of this component. - * @param component A LiveWindowSendable component that represents a sensor. - */ -void LiveWindow::AddSensor(const char *subsystem, const char *name, - LiveWindowSendable *component) -{ - m_components[component].subsystem = subsystem; - m_components[component].name = name; - m_components[component].isSensor = true; -} - -/** - * Add an Actuator associated with the subsystem and with call it by the given name. - * @param subsystem The subsystem this component is part of. - * @param name The name of this component. - * @param component A LiveWindowSendable component that represents a actuator. - */ -void LiveWindow::AddActuator(const char *subsystem, const char *name, - LiveWindowSendable *component) -{ - m_components[component].subsystem = subsystem; - m_components[component].name = name; - m_components[component].isSensor = false; -} - -/** - * INTERNAL - */ -void LiveWindow::AddSensor(std::string type, int channel, LiveWindowSendable *component) -{ - std::ostringstream oss; - oss << type << "[" << channel << "]"; - std::string types(oss.str()); - char* cc = new char[types.size() + 1]; - types.copy(cc, types.size()); - cc[types.size()]='\0'; - AddSensor("Ungrouped", cc, component); - if (std::find(m_sensors.begin(), m_sensors.end(), component) == m_sensors.end()) - m_sensors.push_back(component); -} - -/** - * INTERNAL - */ -void LiveWindow::AddActuator(std::string type, int channel, LiveWindowSendable *component) -{ - std::ostringstream oss; - oss << type << "[" << channel << "]"; - std::string types(oss.str()); - char* cc = new char[types.size() + 1]; - types.copy(cc, types.size()); - cc[types.size()]='\0'; - AddActuator("Ungrouped", cc, component); -} - -/** - * INTERNAL - */ -void LiveWindow::AddActuator(std::string type, int module, int channel, LiveWindowSendable *component) -{ - std::ostringstream oss; - oss << type << "[" << module << "," << channel << "]"; - std::string types(oss.str()); - char* cc = new char[types.size() + 1]; - types.copy(cc, types.size()); - cc[types.size()]='\0'; - AddActuator("Ungrouped", cc, component); -} - -/** - * Tell all the sensors to update (send) their values - * Actuators are handled through callbacks on their value changing from the - * SmartDashboard widgets. - */ -void LiveWindow::UpdateValues() -{ - for (unsigned int i = 0; i < m_sensors.size(); i++) - { - m_sensors[i]->UpdateTable(); - } -} - -/** - * This method is called periodically to cause the sensors to send new values - * to the SmartDashboard. - */ -void LiveWindow::Run() -{ - if (m_enabled) - { - UpdateValues(); - } -} - -/** - * Initialize all the LiveWindow elements the first time we enter LiveWindow mode. - * By holding off creating the NetworkTable entries, it allows them to be redefined - * before the first time in LiveWindow mode. This allows default sensor and actuator - * values to be created that are replaced with the custom names from users calling - * addActuator and addSensor. - */ -void LiveWindow::InitializeLiveWindowComponents() -{ - for (std::map::iterator it = - m_components.begin(); it != m_components.end(); ++it) - { - LiveWindowSendable *component = it->first; - LiveWindowComponent c = it->second; - std::string subsystem = c.subsystem; - std::string name = c.name; - m_liveWindowTable->GetSubTable(subsystem)->PutString("~TYPE~", - "LW Subsystem"); - ITable *table = m_liveWindowTable->GetSubTable(subsystem)->GetSubTable( - name); - table->PutString("~TYPE~", component->GetSmartDashboardType()); - table->PutString("Name", name); - table->PutString("Subsystem", subsystem); - component->InitTable(table); - if (c.isSensor) - { - m_sensors.push_back(component); - } - } -} diff --git a/wpilibc/wpilibC++Sim/src/PIDController.cpp b/wpilibc/wpilibC++Sim/src/PIDController.cpp index e34e822781..d55cfdbf0d 100644 --- a/wpilibc/wpilibC++Sim/src/PIDController.cpp +++ b/wpilibc/wpilibC++Sim/src/PIDController.cpp @@ -61,10 +61,6 @@ void PIDController::Initialize(float Kp, float Ki, float Kd, float Kf, float period) { m_table = NULL; - - m_semaphore = initializeMutexRecursive(); - - m_controlLoop = new Notifier(PIDController::CallCalculate, this); m_P = Kp; m_I = Ki; @@ -91,6 +87,9 @@ void PIDController::Initialize(float Kp, float Ki, float Kd, float Kf, m_pidOutput = output; m_period = period; + + m_semaphore = initializeMutexRecursive(); + m_controlLoop = new Notifier(PIDController::CallCalculate, this); m_controlLoop->StartPeriodic(m_period); static int32_t instances = 0; diff --git a/wpilibc/wpilibC++Sim/src/RobotBase.cpp b/wpilibc/wpilibC++Sim/src/RobotBase.cpp index aa40f949d5..9a9f5f1e79 100644 --- a/wpilibc/wpilibC++Sim/src/RobotBase.cpp +++ b/wpilibc/wpilibC++Sim/src/RobotBase.cpp @@ -5,6 +5,7 @@ /*----------------------------------------------------------------------------*/ #include "RobotBase.h" +#include "RobotState.h" #include "Utility.h" #include @@ -33,6 +34,7 @@ RobotBase &RobotBase::getInstance() RobotBase::RobotBase() { m_ds = DriverStation::GetInstance(); + RobotState::SetImplementation(DriverStation::GetInstance()); } /** diff --git a/wpilibc/wpilibC++Sim/src/SmartDashboard/SmartDashboard.cpp b/wpilibc/wpilibC++Sim/src/SmartDashboard/SmartDashboard.cpp deleted file mode 100644 index 8976278053..0000000000 --- a/wpilibc/wpilibC++Sim/src/SmartDashboard/SmartDashboard.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2011. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ -/*----------------------------------------------------------------------------*/ - -#include "SmartDashboard/SmartDashboard.h" - -#include "SmartDashboard/NamedSendable.h" -#include "WPIErrors.h" -#include "networktables/NetworkTable.h" - -ITable* SmartDashboard::m_table = NULL; -std::map SmartDashboard::m_tablesToData; - -void SmartDashboard::init(){ - m_table = NetworkTable::GetTable("SmartDashboard"); -} - -/** - * Maps the specified key to the specified value in this table. - * The key can not be NULL. - * The value can be retrieved by calling the get method with a key that is equal to the original key. - * @param keyName the key - * @param value the value - */ -void SmartDashboard::PutData(std::string key, Sendable *data) -{ - if (data == NULL) - { - wpi_setGlobalWPIErrorWithContext(NullParameter, "value"); - return; - } - ITable* dataTable = m_table->GetSubTable(key); - dataTable->PutString("~TYPE~", data->GetSmartDashboardType()); - data->InitTable(dataTable); - m_tablesToData[dataTable] = data; -} - -/** - * Maps the specified key (where the key is the name of the {@link SmartDashboardNamedData} - * to the specified value in this table. - * The value can be retrieved by calling the get method with a key that is equal to the original key. - * @param value the value - */ -void SmartDashboard::PutData(NamedSendable *value) -{ - if (value == NULL) - { - wpi_setGlobalWPIErrorWithContext(NullParameter, "value"); - return; - } - PutData(value->GetName(), value); -} - -/** - * Returns the value at the specified key. - * @param keyName the key - * @return the value - */ -/*Sendable *SmartDashboard::GetData(std::string key) -{ - ITable* subtable = m_table->GetSubTable(key); - Sendable *data = m_tablesToData[subtable]; - if (data == NULL) - { - wpi_setGlobalWPIErrorWithContext(SmartDashboardMissingKey, key.c_str()); - return NULL; - } - return data; -}*/ - -/** - * Maps the specified key to the specified complex value (such as an array) in this table. - * The key can not be NULL. - * The value can be retrieved by calling the RetrieveValue method with a key that is equal to the original key. - * @param keyName the key - * @param value the value - */ -void SmartDashboard::PutValue(std::string keyName, ComplexData& value) -{ - m_table->PutValue(keyName, value); -} - -/** - * Retrieves the complex value (such as an array) in this table into the complex data object - * The key can not be NULL. - * @param keyName the key - * @param value the object to retrieve the value into - */ -void SmartDashboard::RetrieveValue(std::string keyName, ComplexData& value) -{ - m_table->RetrieveValue(keyName, value); -} - -/** - * Maps the specified key to the specified value in this table. - * The key can not be NULL. - * The value can be retrieved by calling the get method with a key that is equal to the original key. - * @param keyName the key - * @param value the value - */ -void SmartDashboard::PutBoolean(std::string keyName, bool value) -{ - m_table->PutBoolean(keyName, value); -} - -/** - * Returns the value at the specified key. - * @param keyName the key - * @return the value - */ -bool SmartDashboard::GetBoolean(std::string keyName) -{ - return m_table->GetBoolean(keyName); -} - -/** - * Maps the specified key to the specified value in this table. - * The key can not be NULL. - * The value can be retrieved by calling the get method with a key that is equal to the original key. - * @param keyName the key - * @param value the value - */ -void SmartDashboard::PutNumber(std::string keyName, double value){ - m_table->PutNumber(keyName, value); -} - -/** - * Returns the value at the specified key. - * @param keyName the key - * @return the value - */ -double SmartDashboard::GetNumber(std::string keyName) -{ - return m_table->GetNumber(keyName); -} - -/** - * Maps the specified key to the specified value in this table. - * Neither the key nor the value can be NULL. - * The value can be retrieved by calling the get method with a key that is equal to the original key. - * @param keyName the key - * @param value the value - */ -void SmartDashboard::PutString(std::string keyName, std::string value) -{ - m_table->PutString(keyName, value); -} - -/** - * Returns the value at the specified key. - * @param keyName the key - * @param value the buffer to fill with the value - * @param valueLen the size of the buffer pointed to by value - * @return the length of the string - */ -int SmartDashboard::GetString(std::string keyName, char *outBuffer, unsigned int bufferLen){ - std::string value = m_table->GetString(keyName); - unsigned int i; - for(i = 0; iGetString(keyName); -} diff --git a/wpilibc/wpilibC++Sim/src/Utility.cpp b/wpilibc/wpilibC++Sim/src/Utility.cpp index f393e089a4..b881de1622 100644 --- a/wpilibc/wpilibC++Sim/src/Utility.cpp +++ b/wpilibc/wpilibC++Sim/src/Utility.cpp @@ -6,7 +6,6 @@ #include "Utility.h" -#include "HAL/cpp/StackTrace.hpp" #include "Task.h" #include "Timer.h" #include @@ -36,11 +35,11 @@ void wpi_suspendOnAssertEnabled(bool enabled) static void wpi_handleTracing() { - if (stackTraceEnabled) - { - printf("\n---------------------------\n"); - printCurrentStackTrace(); - } + // if (stackTraceEnabled) + // { + // printf("\n---------------------------\n"); + // printCurrentStackTrace(); + // } printf("\n"); }