Files
Alex Henning cb56c9a144 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
2014-06-13 09:31:32 -04:00

91 lines
3.1 KiB
C++

#include "DriveTrain.h"
#include "Commands/TankDriveWithJoystick.h"
DriveTrain::DriveTrain() : Subsystem("DriveTrain") {
front_left_motor = new Talon(1);
back_left_motor = new Talon(2);
front_right_motor = new Talon(3);
back_right_motor = new Talon(4);
drive = new RobotDrive(front_left_motor, back_left_motor,
front_right_motor, back_right_motor);
left_encoder = new Encoder(1, 2);
right_encoder = new Encoder(3, 4);
// Encoders may measure differently in the real world and in
// simulation. In this example the robot moves 0.042 barleycorns
// per tick in the real world, but the simulated encoders
// simulate 360 tick encoders. This if statement allows for the
// real robot to handle this difference in devices.
#ifdef REAL
left_encoder->SetDistancePerPulse(0.042);
right_encoder->SetDistancePerPulse(0.042);
#else
// Circumference in ft = 4in/12(in/ft)*PI
left_encoder->SetDistancePerPulse((double) (4.0/12.0*M_PI) / 360.0);
right_encoder->SetDistancePerPulse((double) (4.0/12.0*M_PI) / 360.0);
#endif
left_encoder->Start();
right_encoder->Start();
rangefinder = new AnalogChannel(6);
gyro = new Gyro(1);
// Let's show everything on the LiveWindow
// TODO: LiveWindow::GetInstance()->AddActuator("Drive Train", "Front_Left Motor", (Talon) front_left_motor);
// TODO: LiveWindow::GetInstance()->AddActuator("Drive Train", "Back Left Motor", (Talon) back_left_motor);
// TODO: LiveWindow::GetInstance()->AddActuator("Drive Train", "Front Right Motor", (Talon) front_right_motor);
// TODO: LiveWindow::GetInstance()->AddActuator("Drive Train", "Back Right Motor", (Talon) back_right_motor);
LiveWindow::GetInstance()->AddSensor("Drive Train", "Left Encoder", left_encoder);
LiveWindow::GetInstance()->AddSensor("Drive Train", "Right Encoder", right_encoder);
LiveWindow::GetInstance()->AddSensor("Drive Train", "Rangefinder", rangefinder);
LiveWindow::GetInstance()->AddSensor("Drive Train", "Gyro", gyro);
}
/**
* When no other command is running let the operator drive around
* using the PS3 joystick.
*/
void DriveTrain::InitDefaultCommand() {
SetDefaultCommand(new TankDriveWithJoystick());
}
/**
* The log method puts interesting information to the SmartDashboard.
*/
void DriveTrain::Log() {
SmartDashboard::PutNumber("Left Distance", left_encoder->GetDistance());
SmartDashboard::PutNumber("Right Distance", right_encoder->GetDistance());
SmartDashboard::PutNumber("Left Speed", left_encoder->GetRate());
SmartDashboard::PutNumber("Right Speed", right_encoder->GetRate());
SmartDashboard::PutNumber("Gyro", gyro->GetAngle());
}
void DriveTrain::Drive(double left, double right) {
drive->TankDrive(left, right);
}
void DriveTrain::Drive(Joystick* joy) {
Drive(-joy->GetY(), -joy->GetRawAxis(4));
}
double DriveTrain::GetHeading() {
return gyro->GetAngle();
}
void DriveTrain::Reset() {
gyro->Reset();
left_encoder->Reset();
right_encoder->Reset();
}
double DriveTrain::GetDistance() {
return (left_encoder->GetDistance() + right_encoder->GetDistance())/2;
}
double DriveTrain::GetDistanceToObstacle() {
// Really meters in simulation since it's a rangefinder...
return rangefinder->GetAverageVoltage();
}