Initial commit of the WPILib simulation support in an alpha quality state.

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
This commit is contained in:
Alex Henning
2014-06-12 11:02:26 -07:00
committed by thomasclark
parent d5a509c7e7
commit cb56c9a144
425 changed files with 38450 additions and 335 deletions

View File

@@ -0,0 +1,22 @@
#include "Autonomous.h"
#include "PrepareToPickup.h"
#include "Pickup.h"
#include "Place.h"
#include "SetDistanceToBox.h"
#include "DriveStraight.h"
#include "SetWristSetpoint.h"
#include "CloseClaw.h"
#include <iostream>
Autonomous::Autonomous() : CommandGroup("Autonomous") {
AddSequential(new PrepareToPickup());
AddSequential(new Pickup());
AddSequential(new SetDistanceToBox(0.10));
// AddSequential(new DriveStraight(4)); // Use Encoders if ultrasonic is broken
AddSequential(new Place());
AddSequential(new SetDistanceToBox(0.60));
// addSequential(new DriveStraight(-2)); // Use Encoders if ultrasonic is broken
AddParallel(new SetWristSetpoint(-45));
AddSequential(new CloseClaw());
}

View File

@@ -0,0 +1,15 @@
#ifndef Autonomous_H
#define Autonomous_H
#include "Commands/CommandGroup.h"
/**
* The main autonomous command to pickup and deliver the
* soda to the box.
*/
class Autonomous: public CommandGroup {
public:
Autonomous();
};
#endif

View File

@@ -0,0 +1,34 @@
#include "CloseClaw.h"
#include "Robot.h"
CloseClaw::CloseClaw() : Command("CloseClaw") {
Requires(Robot::claw);
}
// Called just before this Command runs the first time
void CloseClaw::Initialize() {
Robot::claw->Close();
}
// Called repeatedly when this Command is scheduled to run
void CloseClaw::Execute() {}
// Make this return true when this Command no longer needs to run execute()
bool CloseClaw::IsFinished() {
return Robot::claw->IsGripping() ;
}
// Called once after isFinished returns true
void CloseClaw::End() {
// NOTE: Doesn't stop in simulation due to lower friction causing the can to fall out
// + there is no need to worry about stalling the motor or crushing the can.
#ifdef REAL
Robot::claw->Stop();
#endif
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
void CloseClaw::Interrupted() {
End();
}

View File

@@ -0,0 +1,20 @@
#ifndef CloseClaw_H
#define CloseClaw_H
#include "Commands/Command.h"
/**
* Opens the claw for one second. Real robots should use sensors, stalling
* motors is BAD!
*/
class CloseClaw: public Command {
public:
CloseClaw();
void Initialize();
void Execute();
bool IsFinished();
void End();
void Interrupted();
};
#endif

View File

@@ -0,0 +1,50 @@
#include "DriveStraight.h"
#include "Robot.h"
DriveStraight::DriveStraight(double distance) {
Requires(Robot::drivetrain);
pid = new PIDController(4, 0, 0, new DriveStraightPIDSource(),
new DriveStraightPIDOutput());
pid->SetAbsoluteTolerance(0.01);
pid->SetSetpoint(distance);
}
// Called just before this Command runs the first time
void DriveStraight::Initialize() {
// Get everything in a safe starting state.
Robot::drivetrain->Reset();
pid->Reset();
pid->Enable();
}
// Called repeatedly when this Command is scheduled to run
void DriveStraight::Execute() {}
// Make this return true when this Command no longer needs to run execute()
bool DriveStraight::IsFinished() {
return pid->OnTarget();
}
// Called once after isFinished returns true
void DriveStraight::End() {
// Stop PID and the wheels
pid->Disable();
Robot::drivetrain->Drive(0, 0);
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
void DriveStraight::Interrupted() {
End();
}
DriveStraightPIDSource::~DriveStraightPIDSource() {}
double DriveStraightPIDSource::PIDGet() {
return Robot::drivetrain->GetDistance();
}
DriveStraightPIDOutput::~DriveStraightPIDOutput() {}
void DriveStraightPIDOutput::PIDWrite(float d) {
Robot::drivetrain->Drive(d, d);
}

View File

@@ -0,0 +1,37 @@
#ifndef DriveStraight_H
#define DriveStraight_H
#include "WPILib.h"
#include "Commands/Command.h"
/**
* Drive the given distance straight (negative values go backwards).
* Uses a local PID controller to run a simple PID loop that is only
* enabled while this command is running. The input is the averaged
* values of the left and right encoders.
*/
class DriveStraight: public Command {
public:
DriveStraight(double distance);
void Initialize();
void Execute();
bool IsFinished();
void End();
void Interrupted();
private:
PIDController* pid;
};
class DriveStraightPIDSource: public PIDSource {
public:
virtual ~DriveStraightPIDSource();
double PIDGet();
};
class DriveStraightPIDOutput: public PIDOutput {
public:
virtual ~DriveStraightPIDOutput();
void PIDWrite(float d);
};
#endif

View File

@@ -0,0 +1,31 @@
#include "OpenClaw.h"
#include "Robot.h"
OpenClaw::OpenClaw() : Command("OpenClaw") {
Requires(Robot::claw);
SetTimeout(1);
}
// Called just before this Command runs the first time
void OpenClaw::Initialize() {
Robot::claw->Open();
}
// Called repeatedly when this Command is scheduled to run
void OpenClaw::Execute() {}
// Make this return true when this Command no longer needs to run execute()
bool OpenClaw::IsFinished() {
return IsTimedOut();
}
// Called once after isFinished returns true
void OpenClaw::End() {
Robot::claw->Stop();
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
void OpenClaw::Interrupted() {
End();
}

View File

@@ -0,0 +1,20 @@
#ifndef OpenClaw_H
#define OpenClaw_H
#include "Commands/Command.h"
/**
* Opens the claw for one second. Real robots should use sensors, stalling
* motors is BAD!
*/
class OpenClaw: public Command {
public:
OpenClaw();
void Initialize();
void Execute();
bool IsFinished();
void End();
void Interrupted();
};
#endif

View File

@@ -0,0 +1,12 @@
#include "Pickup.h"
#include "CloseClaw.h"
#include "SetWristSetpoint.h"
#include "SetElevatorSetpoint.h"
#include <iostream>
Pickup::Pickup() : CommandGroup("Pickup") {
AddSequential(new CloseClaw());
AddParallel(new SetWristSetpoint(-45));
AddSequential(new SetElevatorSetpoint(0.25));
}

View File

@@ -0,0 +1,15 @@
#ifndef Pickup_H
#define Pickup_H
#include "Commands/CommandGroup.h"
/**
* Pickup a soda can (if one is between the open claws) and
* get it in a safe state to drive around.
*/
class Pickup: public CommandGroup {
public:
Pickup();
};
#endif

View File

@@ -0,0 +1,12 @@
#include "Place.h"
#include "OpenClaw.h"
#include "SetWristSetpoint.h"
#include "SetElevatorSetpoint.h"
#include <iostream>
Place::Place() : CommandGroup("Place") {
AddSequential(new SetElevatorSetpoint(0.25));
AddSequential(new SetWristSetpoint(0));
AddSequential(new OpenClaw());
}

View File

@@ -0,0 +1,14 @@
#ifndef Place_H
#define Place_H
#include "Commands/CommandGroup.h"
/**
* Place a held soda can onto the platform.
*/
class Place: public CommandGroup {
public:
Place();
};
#endif

View File

@@ -0,0 +1,12 @@
#include "PrepareToPickup.h"
#include "OpenClaw.h"
#include "SetWristSetpoint.h"
#include "SetElevatorSetpoint.h"
#include <iostream>
PrepareToPickup::PrepareToPickup() : CommandGroup("PrepareToPickup") {
AddParallel(new OpenClaw());
AddParallel(new SetWristSetpoint(0));
AddSequential(new SetElevatorSetpoint(0));
}

View File

@@ -0,0 +1,14 @@
#ifndef PrepareToPickup_H
#define PrepareToPickup_H
#include "Commands/CommandGroup.h"
/**
* Make sure the robot is in a state to pickup soda cans.
*/
class PrepareToPickup: public CommandGroup {
public:
PrepareToPickup();
};
#endif

View File

@@ -0,0 +1,50 @@
#include "SetDistanceToBox.h"
#include "Robot.h"
SetDistanceToBox::SetDistanceToBox(double distance) {
Requires(Robot::drivetrain);
pid = new PIDController(-2, 0, 0, new SetDistanceToBoxPIDSource(),
new SetDistanceToBoxPIDOutput());
pid->SetAbsoluteTolerance(0.01);
pid->SetSetpoint(distance);
}
// Called just before this Command runs the first time
void SetDistanceToBox::Initialize() {
// Get everything in a safe starting state.
Robot::drivetrain->Reset();
pid->Reset();
pid->Enable();
}
// Called repeatedly when this Command is scheduled to run
void SetDistanceToBox::Execute() {}
// Make this return true when this Command no longer needs to run execute()
bool SetDistanceToBox::IsFinished() {
return pid->OnTarget();
}
// Called once after isFinished returns true
void SetDistanceToBox::End() {
// Stop PID and the wheels
pid->Disable();
Robot::drivetrain->Drive(0, 0);
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
void SetDistanceToBox::Interrupted() {
End();
}
SetDistanceToBoxPIDSource::~SetDistanceToBoxPIDSource() {}
double SetDistanceToBoxPIDSource::PIDGet() {
return Robot::drivetrain->GetDistanceToObstacle();
}
SetDistanceToBoxPIDOutput::~SetDistanceToBoxPIDOutput() {}
void SetDistanceToBoxPIDOutput::PIDWrite(float d) {
Robot::drivetrain->Drive(d, d);
}

View File

@@ -0,0 +1,37 @@
#ifndef SetDistanceToBox_H
#define SetDistanceToBox_H
#include "WPILib.h"
#include "Commands/Command.h"
/**
* Drive until the robot is the given distance away from the box. Uses a local
* PID controller to run a simple PID loop that is only enabled while this
* command is running. The input is the averaged values of the left and right
* encoders.
*/
class SetDistanceToBox: public Command {
public:
SetDistanceToBox(double distance);
void Initialize();
void Execute();
bool IsFinished();
void End();
void Interrupted();
private:
PIDController* pid;
};
class SetDistanceToBoxPIDSource: public PIDSource {
public:
virtual ~SetDistanceToBoxPIDSource();
double PIDGet();
};
class SetDistanceToBoxPIDOutput: public PIDOutput {
public:
virtual ~SetDistanceToBoxPIDOutput();
void PIDWrite(float d);
};
#endif

View File

@@ -0,0 +1,29 @@
#include "SetElevatorSetpoint.h"
#include "Robot.h"
#include <math.h>
SetElevatorSetpoint::SetElevatorSetpoint(double setpoint) : Command("SetElevatorSetpoint") {
this->setpoint = setpoint;
Requires(Robot::elevator);
}
// Called just before this Command runs the first time
void SetElevatorSetpoint::Initialize() {
Robot::elevator->SetSetpoint(setpoint);
Robot::elevator->Enable();
}
// Called repeatedly when this Command is scheduled to run
void SetElevatorSetpoint::Execute() {}
// Make this return true when this Command no longer needs to run execute()
bool SetElevatorSetpoint::IsFinished() {
return Robot::elevator->OnTarget();
}
// Called once after isFinished returns true
void SetElevatorSetpoint::End() {}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
void SetElevatorSetpoint::Interrupted() {}

View File

@@ -0,0 +1,23 @@
#ifndef SetElevatorSetpoint_H
#define SetElevatorSetpoint_H
#include "Commands/Command.h"
/**
* Move the elevator to a given location. This command finishes when it is within
* the tolerance, but leaves the PID loop running to maintain the position. Other
* commands using the elevator should make sure they disable PID!
*/
class SetElevatorSetpoint: public Command {
private:
double setpoint;
public:
SetElevatorSetpoint(double setpoint);
void Initialize();
void Execute();
bool IsFinished();
void End();
void Interrupted();
};
#endif

View File

@@ -0,0 +1,28 @@
#include "SetWristSetpoint.h"
#include "Robot.h"
SetWristSetpoint::SetWristSetpoint(double setpoint) : Command("SetWristSetpoint") {
this->setpoint = setpoint;
Requires(Robot::wrist);
}
// Called just before this Command runs the first time
void SetWristSetpoint::Initialize() {
Robot::wrist->SetSetpoint(setpoint);
Robot::wrist->Enable();
}
// Called repeatedly when this Command is scheduled to run
void SetWristSetpoint::Execute() {}
// Make this return true when this Command no longer needs to run execute()
bool SetWristSetpoint::IsFinished() {
return Robot::wrist->OnTarget();
}
// Called once after isFinished returns true
void SetWristSetpoint::End() {}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
void SetWristSetpoint::Interrupted() {}

View File

@@ -0,0 +1,23 @@
#ifndef SetWristSetpoint_H
#define SetWristSetpoint_H
#include "Commands/Command.h"
/**
* Move the wrist to a given angle. This command finishes when it is within
* the tolerance, but leaves the PID loop running to maintain the position.
* Other commands using the wrist should make sure they disable PID!
*/
class SetWristSetpoint: public Command {
private:
double setpoint;
public:
SetWristSetpoint(double setpoint);
void Initialize();
void Execute();
bool IsFinished();
void End();
void Interrupted();
};
#endif

View File

@@ -0,0 +1,30 @@
#include "TankDriveWithJoystick.h"
#include "Robot.h"
TankDriveWithJoystick::TankDriveWithJoystick() : Command("TankDriveWithJoystick") {
Requires(Robot::drivetrain);
}
// Called just before this Command runs the first time
void TankDriveWithJoystick::Initialize() {}
// Called repeatedly when this Command is scheduled to run
void TankDriveWithJoystick::Execute() {
Robot::drivetrain->Drive(Robot::oi->GetJoystick());
}
// Make this return true when this Command no longer needs to run execute()
bool TankDriveWithJoystick::IsFinished() {
return false;
}
// Called once after isFinished returns true
void TankDriveWithJoystick::End() {
Robot::drivetrain->Drive(0, 0);
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
void TankDriveWithJoystick::Interrupted() {
End();
}

View File

@@ -0,0 +1,19 @@
#ifndef TankDriveWithJoystick_H
#define TankDriveWithJoystick_H
#include "Commands/Command.h"
/**
* Have the robot drive tank style using the PS3 Joystick until interrupted.
*/
class TankDriveWithJoystick: public Command {
public:
TankDriveWithJoystick();
void Initialize();
void Execute();
bool IsFinished();
void End();
void Interrupted();
};
#endif