From b6475d050360186e0d95c7523237d220a411a6ea Mon Sep 17 00:00:00 2001 From: Patrick Plenefisch Date: Thu, 25 Sep 2014 20:36:59 -0400 Subject: [PATCH] Renaming and merging WPILibC++ into Devices and simulator files Change-Id: I6f4b94d1f2cbf4196ebcef8bc45799a97bcde1d8 --- CMakeLists.txt | 5 +- ni-libraries/libwpi_2015.so | 2 +- wpilibc/wpilibC++/CMakeLists.txt | 10 +- wpilibc/wpilibC++/include/Notifier.h | 3 +- wpilibc/wpilibC++/include/PIDController.h | 7 +- wpilibc/wpilibC++Devices/CMakeLists.txt | 6 +- .../wpilibC++Devices/include/DriverStation.h | 1 + wpilibc/wpilibC++Devices/include/Notifier.h | 42 ------- .../wpilibC++Devices/include/PIDController.h | 108 ------------------ wpilibc/wpilibC++Devices/include/Task.h | 52 --------- wpilibc/wpilibC++Devices/include/Timer.h | 44 ------- wpilibc/wpilibC++Devices/src/Notifier.cpp | 1 + .../wpilibC++Devices/src/PIDController.cpp | 1 + wpilibc/wpilibC++Devices/src/Preferences.cpp | 1 + wpilibc/wpilibC++Devices/src/Task.cpp | 1 + .../wpilibC++IntegrationTests/CMakeLists.txt | 4 +- .../src/NotifierTest.cpp | 3 +- wpilibc/wpilibC++Sim/CMakeLists.txt | 31 ++--- wpilibc/wpilibC++Sim/Makefile | 4 +- wpilibc/wpilibC++Sim/include/Notifier.h | 44 ------- wpilibc/wpilibC++Sim/include/PIDController.h | 107 ----------------- wpilibc/wpilibC++Sim/include/Task.h | 52 --------- wpilibc/wpilibC++Sim/include/Timer.h | 50 -------- wpilibc/wpilibC++Sim/include/Utility.h | 26 ----- .../wpilibC++Sim/include/simulation/simTime.h | 7 ++ wpilibc/wpilibC++Sim/src/PIDController.cpp | 3 +- wpilibc/wpilibC++Sim/src/Solenoid.cpp | 1 + wpilibc/wpilibC++Sim/src/Timer.cpp | 1 + wpilibc/wpilibC++Sim/src/Utility.cpp | 1 + 29 files changed, 56 insertions(+), 562 deletions(-) delete mode 100644 wpilibc/wpilibC++Devices/include/Notifier.h delete mode 100644 wpilibc/wpilibC++Devices/include/PIDController.h delete mode 100644 wpilibc/wpilibC++Devices/include/Task.h delete mode 100644 wpilibc/wpilibC++Devices/include/Timer.h delete mode 100644 wpilibc/wpilibC++Sim/include/Notifier.h delete mode 100644 wpilibc/wpilibC++Sim/include/PIDController.h delete mode 100644 wpilibc/wpilibC++Sim/include/Task.h delete mode 100644 wpilibc/wpilibC++Sim/include/Timer.h delete mode 100644 wpilibc/wpilibC++Sim/include/Utility.h create mode 100644 wpilibc/wpilibC++Sim/include/simulation/simTime.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 83533f6c84..eadd0a44bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,16 @@ cmake_minimum_required(VERSION 2.8) project(All-WPILib) set(CMAKE_BUILD_TYPE Debug) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=2 -Wall -Wextra -Wno-unused-parameter -fPIC") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -fPIC") SET(CMAKE_SKIP_BUILD_RPATH TRUE) file(GLOB_RECURSE NI_LIBS ni-libraries/*.so*) +list(REMOVE_ITEM NI_LIBS ${CMAKE_CURRENT_SOURCE_DIR}/ni-libraries/libwpi.so ${CMAKE_CURRENT_SOURCE_DIR}/ni-libraries/libwpi_2015.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) +file(GLOB_RECURSE COM_SRC_FILES wpilibc/wpilibC++/src/*.cpp) + add_subdirectory(hal) add_subdirectory(networktables/cpp) add_subdirectory(wpilibc) diff --git a/ni-libraries/libwpi_2015.so b/ni-libraries/libwpi_2015.so index 8920c0e6e5..e799af29aa 100644 --- a/ni-libraries/libwpi_2015.so +++ b/ni-libraries/libwpi_2015.so @@ -1,3 +1,3 @@ /* GNU ld script */ OUTPUT_FORMAT(elf32-littlearm) -GROUP ( AS_NEEDED ( -lWPILib -lWPILibAthena -lHALAthena -lNetworkTables -lFRC_NetworkCommunication -li2c -lni_emb -lNiFpgaLv -lNiFpga -lnirio_emb_can -lNiRioSrv -lni_rtlog -lRoboRIO_FRC_ChipObject -lspi -lvisa -ldl -lpthread ) ) +GROUP ( AS_NEEDED ( -lwpilib_nonshared -lHALAthena -lNetworkTables -lFRC_NetworkCommunication -li2c -lni_emb -lNiFpgaLv -lNiFpga -lnirio_emb_can -lNiRioSrv -lni_rtlog -lRoboRIO_FRC_ChipObject -lspi -lvisa -ldl -lpthread -lrt ) ) diff --git a/wpilibc/wpilibC++/CMakeLists.txt b/wpilibc/wpilibC++/CMakeLists.txt index 6be77a1fa6..4af3fc914e 100644 --- a/wpilibc/wpilibC++/CMakeLists.txt +++ b/wpilibc/wpilibC++/CMakeLists.txt @@ -1,13 +1,5 @@ cmake_minimum_required(VERSION 2.8) project(WPILibC++) -file(GLOB_RECURSE SRC_FILES src/*.cpp) -include_directories(include/ ${NWT_API_INCLUDES} ${HAL_API_INCLUDES}) -add_library(WPILib STATIC ${SRC_FILES}) -target_link_libraries(WPILib) -INSTALL(TARGETS WPILib ARCHIVE DESTINATION lib COMPONENT lib) 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/Notifier.h b/wpilibc/wpilibC++/include/Notifier.h index 4bd89879f3..13c3e091df 100644 --- a/wpilibc/wpilibC++/include/Notifier.h +++ b/wpilibc/wpilibC++/include/Notifier.h @@ -9,7 +9,7 @@ #include "Task.h" #include "HAL/cpp/Synchronized.hpp" -typedef void (*TimerEventHandler)(void *param); +typedef void *(*TimerEventHandler)(void *param); class Notifier : public ErrorBase { @@ -22,6 +22,7 @@ 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 diff --git a/wpilibc/wpilibC++/include/PIDController.h b/wpilibc/wpilibC++/include/PIDController.h index cf7732f475..0b591dcd36 100644 --- a/wpilibc/wpilibC++/include/PIDController.h +++ b/wpilibc/wpilibC++/include/PIDController.h @@ -69,6 +69,7 @@ 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 @@ -88,12 +89,16 @@ private: PIDSource *m_pidInput; PIDOutput *m_pidOutput; +#ifndef FRC_SIMULATOR pthread_t m_controlLoop; +#else + Notifier* m_controlLoop; +#endif 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); + static void *CallCalculate(void *controller); virtual ITable* GetTable(); virtual std::string GetSmartDashboardType(); diff --git a/wpilibc/wpilibC++Devices/CMakeLists.txt b/wpilibc/wpilibC++Devices/CMakeLists.txt index 595b5a2e31..f73522cc50 100644 --- a/wpilibc/wpilibC++Devices/CMakeLists.txt +++ b/wpilibc/wpilibC++Devices/CMakeLists.txt @@ -3,9 +3,9 @@ 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 lib COMPONENT lib) +add_library(wpilib_nonshared STATIC ${SRC_FILES} ${COM_SRC_FILES}) +target_link_libraries(wpilib_nonshared HALAthena NetworkTables ${NI_LIBS}) +INSTALL(TARGETS wpilib_nonshared ARCHIVE DESTINATION lib COMPONENT lib) INSTALL(DIRECTORY include DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT headers) # lib/ c m gcc_s ld-linux # usr/lib stdc++ diff --git a/wpilibc/wpilibC++Devices/include/DriverStation.h b/wpilibc/wpilibC++Devices/include/DriverStation.h index 6afe4a6f10..9151c8d897 100644 --- a/wpilibc/wpilibC++Devices/include/DriverStation.h +++ b/wpilibc/wpilibC++Devices/include/DriverStation.h @@ -8,6 +8,7 @@ #include "SensorBase.h" #include "RobotState.h" #include "Task.h" +#include "HAL/HAL.hpp" struct HALControlWord; class AnalogInput; diff --git a/wpilibc/wpilibC++Devices/include/Notifier.h b/wpilibc/wpilibC++Devices/include/Notifier.h deleted file mode 100644 index ad969360b1..0000000000 --- a/wpilibc/wpilibC++Devices/include/Notifier.h +++ /dev/null @@ -1,42 +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 "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 deleted file mode 100644 index ea96791dc3..0000000000 --- a/wpilibc/wpilibC++Devices/include/PIDController.h +++ /dev/null @@ -1,108 +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 "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++Devices/include/Task.h b/wpilibc/wpilibC++Devices/include/Task.h deleted file mode 100644 index 7377c9ecfa..0000000000 --- a/wpilibc/wpilibC++Devices/include/Task.h +++ /dev/null @@ -1,52 +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/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 deleted file mode 100644 index 67d574f2d3..0000000000 --- a/wpilibc/wpilibC++Devices/include/Timer.h +++ /dev/null @@ -1,44 +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 "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++Devices/src/Notifier.cpp b/wpilibc/wpilibC++Devices/src/Notifier.cpp index 667495cc4a..46ac430535 100644 --- a/wpilibc/wpilibC++Devices/src/Notifier.cpp +++ b/wpilibc/wpilibC++Devices/src/Notifier.cpp @@ -8,6 +8,7 @@ #include "Timer.h" #include "Utility.h" #include "WPIErrors.h" +#include "HAL/HAL.hpp" Notifier *Notifier::timerQueueHead = NULL; ReentrantSemaphore Notifier::queueSemaphore; diff --git a/wpilibc/wpilibC++Devices/src/PIDController.cpp b/wpilibc/wpilibC++Devices/src/PIDController.cpp index 55f0e58c1a..492adfe763 100644 --- a/wpilibc/wpilibC++Devices/src/PIDController.cpp +++ b/wpilibc/wpilibC++Devices/src/PIDController.cpp @@ -12,6 +12,7 @@ #include #include "HAL/cpp/Synchronized.hpp" #include "Timer.h" +#include "HAL/HAL.hpp" static const char *kP = "p"; static const char *kI = "i"; diff --git a/wpilibc/wpilibC++Devices/src/Preferences.cpp b/wpilibc/wpilibC++Devices/src/Preferences.cpp index 52901a0c70..5ac0c5ee7f 100644 --- a/wpilibc/wpilibC++Devices/src/Preferences.cpp +++ b/wpilibc/wpilibC++Devices/src/Preferences.cpp @@ -9,6 +9,7 @@ //#include "NetworkCommunication/UsageReporting.h" #include "HAL/cpp/Synchronized.hpp" #include "WPIErrors.h" +#include "HAL/HAL.hpp" #include #include diff --git a/wpilibc/wpilibC++Devices/src/Task.cpp b/wpilibc/wpilibC++Devices/src/Task.cpp index 2c794e8e7c..8665664449 100644 --- a/wpilibc/wpilibC++Devices/src/Task.cpp +++ b/wpilibc/wpilibC++Devices/src/Task.cpp @@ -11,6 +11,7 @@ #include #include #include +#include "HAL/HAL.hpp" const uint32_t Task::kDefaultPriority; diff --git a/wpilibc/wpilibC++IntegrationTests/CMakeLists.txt b/wpilibc/wpilibC++IntegrationTests/CMakeLists.txt index 98d1c644d8..74814c45a9 100644 --- a/wpilibc/wpilibC++IntegrationTests/CMakeLists.txt +++ b/wpilibc/wpilibC++IntegrationTests/CMakeLists.txt @@ -3,6 +3,6 @@ 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++Devices/include/ ${WPILIB_INCLUDES} ${HAL_API_INCLUDES} ${NWT_API_INCLUDES}) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -Wno-unused-variable") add_executable(FRCUserProgram ${SRC_FILES}) -target_link_libraries(FRCUserProgram WPILib WPILibAthena WPILib HALAthena NetworkTables ${NI_LIBS} rt) +target_link_libraries(FRCUserProgram wpilib_nonshared HALAthena NetworkTables ${NI_LIBS}) diff --git a/wpilibc/wpilibC++IntegrationTests/src/NotifierTest.cpp b/wpilibc/wpilibC++IntegrationTests/src/NotifierTest.cpp index 87cd2a9940..072a8dc4f1 100644 --- a/wpilibc/wpilibC++IntegrationTests/src/NotifierTest.cpp +++ b/wpilibc/wpilibC++IntegrationTests/src/NotifierTest.cpp @@ -12,9 +12,10 @@ unsigned notifierCounter; -void notifierHandler(void *) +void *notifierHandler(void *) { notifierCounter++; + return nullptr; } /** diff --git a/wpilibc/wpilibC++Sim/CMakeLists.txt b/wpilibc/wpilibC++Sim/CMakeLists.txt index c396adae45..2c6b8394ce 100644 --- a/wpilibc/wpilibC++Sim/CMakeLists.txt +++ b/wpilibc/wpilibC++Sim/CMakeLists.txt @@ -1,11 +1,11 @@ cmake_minimum_required(VERSION 2.8) project(WPILibSim) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=2 -Wall -Wextra -Wno-unused-parameter -fPIC -std=c++1y") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=2 -Wall -Wextra -Wno-unused-parameter -fPIC -std=c++1y -DFRC_SIMULATOR") -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++) +get_filename_component(HAL_API_INCLUDES ../../hal/include REALPATH) +get_filename_component(NWT_API_INCLUDES ../../networktables/cpp/include REALPATH) +add_subdirectory(../wpilibC++ wpilibC++) include (FindPkgConfig) if (PKG_CONFIG_FOUND) @@ -14,17 +14,20 @@ endif() find_package(gazebo REQUIRED) -file(GLOB_RECURSE SRC_FILES src/*.cpp $ENV{ALLWPILIB}/networktables/cpp/lib/share/*.cpp - $ENV{ALLWPILIB}/networktables/cpp/lib/Athena/*.cpp - $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}/wpilibc/wpilibC++/include - $ENV{ALLWPILIB}/networktables/cpp/include - $ENV{ALLWPILIB}/hal/include +file(GLOB_RECURSE SRC_FILES src/*.cpp ../../networktables/cpp/lib/share/*.cpp + ../../networktables/cpp/lib/Athena/*.cpp + ../../hal/lib/Athena/Task.cpp + ../../hal/lib/Athena/Semaphore.cpp + ../../hal/lib/Athena/cpp/Synchronized.cpp) + +file(GLOB_RECURSE COM_SRC_FILES ../wpilibC++/src/*.cpp) + +include_directories(include/ ../../wpilibc/wpilibC++/include + ../../networktables/cpp/include + ../../hal/include ${Boost_INCLUDE_DIR} ${GAZEBO_INCLUDE_DIRS}) # ${NWT_API_INCLUDES} -add_library(WPILibSim SHARED ${SRC_FILES}) -target_link_libraries(WPILibSim WPILib ${GAZEBO_LIBRARIES} -fPIC) # NetworkTables +add_library(WPILibSim SHARED ${SRC_FILES} ${COM_SRC_FILES}) +target_link_libraries(WPILibSim ${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 f698aee000..47bf75f1c2 100644 --- a/wpilibc/wpilibC++Sim/Makefile +++ b/wpilibc/wpilibC++Sim/Makefile @@ -1,12 +1,10 @@ prefix = /usr lib.dir = $(prefix)/lib build.dir = build -allwpilib = ../.. all: mkdir -p $(build.dir) - cp -r $(allwpilib)/wpilibc/wpilibC++ build - cd ${build.dir} && ALLWPILIB=$(allwpilib) cmake .. && make + cd ${build.dir} && cmake .. && make clean: rm -rf $(build.dir) diff --git a/wpilibc/wpilibC++Sim/include/Notifier.h b/wpilibc/wpilibC++Sim/include/Notifier.h deleted file mode 100644 index 4bd89879f3..0000000000 --- a/wpilibc/wpilibC++Sim/include/Notifier.h +++ /dev/null @@ -1,44 +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 "Task.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 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); - - static Task *task; - static void Run(); -}; diff --git a/wpilibc/wpilibC++Sim/include/PIDController.h b/wpilibc/wpilibC++Sim/include/PIDController.h deleted file mode 100644 index 1790d9b174..0000000000 --- a/wpilibc/wpilibC++Sim/include/PIDController.h +++ /dev/null @@ -1,107 +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 "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 - 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; - - MUTEX_ID m_semaphore; - - PIDSource *m_pidInput; - PIDOutput *m_pidOutput; - Notifier *m_controlLoop; - - 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++Sim/include/Task.h b/wpilibc/wpilibC++Sim/include/Task.h deleted file mode 100644 index ca1754a50d..0000000000 --- a/wpilibc/wpilibC++Sim/include/Task.h +++ /dev/null @@ -1,52 +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/Task.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++Sim/include/Timer.h b/wpilibc/wpilibC++Sim/include/Timer.h deleted file mode 100644 index 40a6f65db5..0000000000 --- a/wpilibc/wpilibC++Sim/include/Timer.h +++ /dev/null @@ -1,50 +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 "HAL/Semaphore.hpp" -#include "Base.h" - -typedef void (*TimerInterruptHandler)(void *param); - -void Wait(double seconds); -double GetClock(); -double GetTime(); - -namespace wpilib { namespace internal { - extern double simTime; - extern MULTIWAIT_ID time_wait; - // transport::SubscriberPtr time_sub; -}} - -/** - * 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++Sim/include/Utility.h b/wpilibc/wpilibC++Sim/include/Utility.h deleted file mode 100644 index 25c56e0006..0000000000 --- a/wpilibc/wpilibC++Sim/include/Utility.h +++ /dev/null @@ -1,26 +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 - -#define wpi_assert(condition) wpi_assert_impl(condition, #condition, NULL, __FILE__, __LINE__, __FUNCTION__) -#define wpi_assertWithMessage(condition, message) wpi_assert_impl(condition, #condition, message, __FILE__, __LINE__, __FUNCTION__) - -#define wpi_assertEqual(a, b) wpi_assertEqual_impl(a, b, NULL, __FILE__, __LINE__, __FUNCTION__) -#define wpi_assertEqualWithMessage(a, b, message) wpi_assertEqual_impl(a, b, message, __FILE__, __LINE__, __FUNCTION__) - -#define wpi_assertNotEqual(a, b) wpi_assertNotEqual_impl(a, b, NULL, __FILE__, __LINE__, __FUNCTION__) -#define wpi_assertNotEqualWithMessage(a, b, message) wpi_assertNotEqual_impl(a, b, message, __FILE__, __LINE__, __FUNCTION__) - -bool wpi_assert_impl(bool conditionValue, const char *conditionText, const char *message, const char *fileName, uint32_t lineNumber, const char *funcName); -bool wpi_assertEqual_impl(int valueA, int valueB, const char *message, const char *fileName,uint32_t lineNumber, const char *funcName); -bool wpi_assertNotEqual_impl(int valueA, int valueB, const char *message, const char *fileName,uint32_t lineNumber, const char *funcName); - -void wpi_suspendOnAssertEnabled(bool enabled); -void wpi_stackTraceOnAssertEnable(bool enabled); - -uint32_t GetFPGATime(); diff --git a/wpilibc/wpilibC++Sim/include/simulation/simTime.h b/wpilibc/wpilibC++Sim/include/simulation/simTime.h new file mode 100644 index 0000000000..7b4bf90690 --- /dev/null +++ b/wpilibc/wpilibC++Sim/include/simulation/simTime.h @@ -0,0 +1,7 @@ +#pragma once + +namespace wpilib { namespace internal { + extern double simTime; + extern MULTIWAIT_ID time_wait; + // transport::SubscriberPtr time_sub; +}} diff --git a/wpilibc/wpilibC++Sim/src/PIDController.cpp b/wpilibc/wpilibC++Sim/src/PIDController.cpp index d55cfdbf0d..6087ce6760 100644 --- a/wpilibc/wpilibC++Sim/src/PIDController.cpp +++ b/wpilibc/wpilibC++Sim/src/PIDController.cpp @@ -115,10 +115,11 @@ PIDController::~PIDController() * This method is static and called by the Notifier class. * @param controller the address of the PID controller object to use in the background loop */ -void PIDController::CallCalculate(void *controller) +void *PIDController::CallCalculate(void *controller) { PIDController *control = (PIDController*) controller; control->Calculate(); + return nullptr; } /** diff --git a/wpilibc/wpilibC++Sim/src/Solenoid.cpp b/wpilibc/wpilibC++Sim/src/Solenoid.cpp index f35ab4de7a..bf29282192 100644 --- a/wpilibc/wpilibC++Sim/src/Solenoid.cpp +++ b/wpilibc/wpilibC++Sim/src/Solenoid.cpp @@ -7,6 +7,7 @@ #include "Solenoid.h" #include "WPIErrors.h" #include "LiveWindow/LiveWindow.h" +#include "simulation/simTime.h" /** * Common function to implement constructor behavior. diff --git a/wpilibc/wpilibC++Sim/src/Timer.cpp b/wpilibc/wpilibC++Sim/src/Timer.cpp index 9c5ff5a86f..3e221a3f14 100644 --- a/wpilibc/wpilibC++Sim/src/Timer.cpp +++ b/wpilibc/wpilibC++Sim/src/Timer.cpp @@ -9,6 +9,7 @@ #include #include "HAL/cpp/Synchronized.hpp" +#include "simulation/simTime.h" #include "Utility.h" /** diff --git a/wpilibc/wpilibC++Sim/src/Utility.cpp b/wpilibc/wpilibC++Sim/src/Utility.cpp index c565221bec..e1bf26d554 100644 --- a/wpilibc/wpilibC++Sim/src/Utility.cpp +++ b/wpilibc/wpilibC++Sim/src/Utility.cpp @@ -8,6 +8,7 @@ #include "Task.h" #include "Timer.h" +#include "simulation/simTime.h" #include #include