mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Fixes to deal with the switch to .hpp files in the HAL and other misc problems due to rebasing. Added Omar's changes to the compressor interface Fixes to make C++ plugin compile on linux. Added import of the WPILibSim code from the graduate class. It shows up as wpilibJavaSim to follow the convention set by wpilibJava, wpilibJavaJNI and wpilibJavaFinal. Fixed wpilibJavaSim artifactId to mirror the new convention. Modified the build of the java plugin to pull in the simulation dependencies. Added stacktrace printing. Fixed support for creating projects. Added support for the isReal() and isSimulation() methods along with the AnalogPotentiometer object to support simulating GearsBot. Added support for a "WPILib Simulate" button. Added GearsBot to the built in examples. Added support for specifying the world file during project creation and switched the default from BluntObjectBot to GearsBot. Removed unused import. Added file browser for world files. Added support for debugging in simulation. Change simulate icon to be a Gazebo icon. Switched over to the gazebo messaging system. Updated location of default world file. Reverted cmake change. Fixed bug in WPILibJSim, added better logging and cleaned up code. Made the frc_gazebo_plugin build using raw cmake instead of catkin, breaking the final ROS dependencies. Added installation to frc_gazebo_plugin Makefile. Fixed running of simulation to actually use frcsim. Initial commit of simulation library for C++. Has the minimal subset of features necessary for having a Simple Robot run in teleoperated mode. Added notes for generating protobuf messages. Import of the debuild process into the main repository. Moved frc_gazebo_plugin under simulation and removed the gazebo folder. Updated the gazebo plugin to remove excessive printing and limit motor signal to [-1,1]. Updated WPILibJSim to support latching messages and to sleep for 20ms in iterative robot. Reduced delay between starting frcsim and the users program to 1 second. Updated GearsBot example. Fixed a few minor issues for demoable state. Added simulator support for Victors, Jaguars and Talons. Added NetworkTables, SmartDashboard and LiveWindow to the simulator. Added AnalogPotentiometer for simulation. Added support for simulating encoders. Added simulation support for Gyro. Added IterativeRobot, Fixed Timers, Notifiers, PIDControllers and other minor fixes + cleanup. Added RobotDrive support to simulation. Separated out JavaGazebo so that SimDS will be able to reuse it. Separated out SimDS into its own application.. Fixes so that the SimDS is distributed and runs properly for Java with the eclipse plugins. Added DriverStation support to WPILibCSim Cleanup of DriverStation, WaitUntilCommand and AnalogPotentiometer for WPILibCSim. Cleanup of includes for WPILibCSim Added AnalogPotentiometer to the real WPILibC. Added AnalogPotentiometer to the real WPILibC. Added GearsBot example to C++ eclipse plugin. WPILibCSim fixes to work with launching from the plugin. Package libwpilibsim in a deb file. Added includes to plugin distribution. Added support for external-limit-switches to Gazebo, Java and C++. Added support for Gazebo Rangefinders and Analog channels to read their values in C++ and Java. Added support for internal limit switches. Updated GearsBot programs to use limit switches + range finders. Added disabling of motors when robot is disabled to more closely mimic the real robot. Fixes to deal with the switch to .hpp files in the HAL and other misc problems due to rebasing. Change-Id: I624c5f4d0f28282616a7c92083575bf68adcdce2
105 lines
3.2 KiB
C++
105 lines
3.2 KiB
C++
/*----------------------------------------------------------------------------*/
|
|
/* 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"
|
|
|
|
// 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&)
|
|
|
|
#define CRITICAL_REGION(s) { Synchronized _sync(s);
|
|
#define END_REGION }
|
|
// TODO: is this Better?
|
|
#define SYNCHRONIZE(s) for (Synchronized _sync(s), int _i=0;i < 1; i++)
|
|
|
|
class Synchronized;
|
|
|
|
/**
|
|
* Wrap a vxWorks semaphore (SEM_ID) for easier use in C++. For a static
|
|
* instance, the constructor runs at program load time before main() can spawn
|
|
* any tasks. Use that to fix race conditions in setup code.
|
|
*
|
|
* This uses a semM semaphore which is "reentrant" in the sense that the owning
|
|
* task can "take" the semaphore more than once. It will need to "give" the
|
|
* semaphore the same number of times to unlock it.
|
|
*
|
|
* This class is safe to use in static variables because it does not depend on
|
|
* any other C++ static constructors or destructors.
|
|
*/
|
|
class ReentrantSemaphore
|
|
{
|
|
public:
|
|
explicit ReentrantSemaphore()
|
|
{
|
|
m_semaphore = initializeMutexRecursive();
|
|
}
|
|
~ReentrantSemaphore()
|
|
{
|
|
deleteMutex(m_semaphore);
|
|
}
|
|
|
|
/**
|
|
* Lock the semaphore, blocking until it's available.
|
|
* @return 0 for success, -1 for error. If -1, the error will be in errno.
|
|
*/
|
|
int take()
|
|
{
|
|
return takeMutex(m_semaphore);
|
|
}
|
|
|
|
/**
|
|
* Unlock the semaphore.
|
|
* @return 0 for success, -1 for error. If -1, the error will be in errno.
|
|
*/
|
|
int give()
|
|
{
|
|
return giveMutex(m_semaphore);
|
|
}
|
|
|
|
private:
|
|
MUTEX_ID m_semaphore;
|
|
|
|
friend class Synchronized;DISALLOW_COPY_AND_ASSIGN(ReentrantSemaphore);
|
|
};
|
|
|
|
/**
|
|
* Provide easy support for critical regions.
|
|
*
|
|
* A critical region is an area of code that is always executed under mutual exclusion. Only
|
|
* one task can be executing this code at any time. The idea is that code that manipulates data
|
|
* that is shared between two or more tasks has to be prevented from executing at the same time
|
|
* otherwise a race condition is possible when both tasks try to update the data. Typically
|
|
* semaphores are used to ensure only single task access to the data.
|
|
*
|
|
* Synchronized objects are a simple wrapper around semaphores to help ensure
|
|
* that semaphores are always unlocked (semGive) after locking (semTake).
|
|
*
|
|
* You allocate a Synchronized as a local variable, *not* on the heap. That
|
|
* makes it a "stack object" whose destructor runs automatically when it goes
|
|
* out of scope. E.g.
|
|
*
|
|
* { Synchronized _sync(aReentrantSemaphore); ... critical region ... }
|
|
*/
|
|
class Synchronized
|
|
{
|
|
public:
|
|
explicit Synchronized(MUTEX_ID);
|
|
#ifndef __vxworks
|
|
explicit Synchronized(SEMAPHORE_ID);
|
|
#endif
|
|
explicit Synchronized(ReentrantSemaphore&);
|
|
virtual ~Synchronized();
|
|
private:
|
|
MUTEX_ID m_mutex;
|
|
SEMAPHORE_ID m_semaphore;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Synchronized);
|
|
};
|
|
|