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,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.wpi.first.wpilibj.simulation</groupId>
<artifactId>SimDS</artifactId>
<version>0.1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>edu.wpi.first.wpilibj.simulation.ds.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration />
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>docline-java8-disable</id>
<build>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

91
simulation/SimDS/pom.xml Normal file
View File

@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.wpi.first.wpilibj.simulation</groupId>
<artifactId>SimDS</artifactId>
<packaging>jar</packaging>
<version>0.1.0-SNAPSHOT</version>
<profiles>
<profile>
<id>docline-java8-disable</id>
<activation>
<jdk>[1.8,</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>net.java.jinput</groupId>
<artifactId>jinput</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.gazebosim</groupId>
<artifactId>JavaGazebo</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<!-- TODO: Add unit tests -->
<!-- <dependency> -->
<!-- <groupId>junit</groupId> -->
<!-- <artifactId>junit</artifactId> -->
<!-- <version>4.11</version> -->
<!-- </dependency> -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>edu.wpi.first.wpilibj.simulation.ds.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<!-- put your configurations here -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,152 @@
package edu.wpi.first.wpilibj.simulation.ds;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.DropMode;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import org.gazebosim.transport.Node;
import org.gazebosim.transport.Publisher;
import edu.wpi.first.wpilibj.simulation.ds.FakeJoystick;
import edu.wpi.first.wpilibj.simulation.ds.ISimJoystick;
import edu.wpi.first.wpilibj.simulation.ds.JoystickProvider;
import gazebo.msgs.GzDriverStation.DriverStation;
public class DS {
private JoystickProvider joystickProvider;
private JoystickList joysticks;
private JFrame mainframe;
private JPanel modePanel;
private ActionListener modeListener;
private ButtonGroup modes;
private JButton enable, refresh;
public enum State {
Disabled, Teleop, Autonomous, Test;
}
private boolean enabled = false;
private State state = State.Teleop;
private DriverStation.State protoState = DriverStation.State.TELEOP;
private Publisher<DriverStation> pub;
public DS(JoystickProvider joystickProvider) {
this.joystickProvider = joystickProvider;
mainframe = new JFrame();
mainframe.setTitle("FRC Simulation DriverStation");
mainframe.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
makeModeButtons(constraints);
mainframe.pack();
constraints.gridy = 1;
makeEnableButton(constraints);
constraints.gridx = 1;
constraints.gridy = 0;
makeJoystickUI(constraints);
mainframe.pack();
constraints.gridy = 1;
makeRefreshButton(constraints);
mainframe.pack();
mainframe.setVisible(true);
}
private void makeModeButtons(GridBagConstraints constraints) {
modePanel = new JPanel();
modePanel.setLayout(new BoxLayout(modePanel, BoxLayout.PAGE_AXIS));
modeListener = new ModeAction(this);
JRadioButton teleop = new JRadioButton("Teleop");
teleop.setActionCommand(State.Teleop.toString());
teleop.addActionListener(modeListener);
JRadioButton auto = new JRadioButton("Autonomous");
auto.setActionCommand(State.Autonomous.toString());
auto.addActionListener(modeListener);
JRadioButton test = new JRadioButton("Test");
test.setActionCommand(State.Test.toString());
test.addActionListener(modeListener);
teleop.setSelected(true);
modes = new ButtonGroup();
modes.add(teleop);
modes.add(auto);
modes.add(test);
modePanel.add(teleop);
modePanel.add(auto);
modePanel.add(test);
mainframe.add(modePanel, constraints);
}
private void makeEnableButton(GridBagConstraints constraints) {
enable = new JButton("Enable");
enable.addActionListener(new EnableAction(this));
enable.setPreferredSize(new Dimension(modePanel.getSize().width, 50));
mainframe.add(enable, constraints);
}
private void makeJoystickUI(GridBagConstraints constraints) {
joysticks = new JoystickList(joystickProvider);
mainframe.add(joysticks, constraints);
scanForJoysticks();
}
public void scanForJoysticks() {
joysticks.removeAll();
List<ISimJoystick> sticks = joystickProvider.scanForJoysticks();
while (sticks.size() < 4) {
sticks.add(new FakeJoystick());
}
joysticks.setListData(sticks);
}
private void makeRefreshButton(GridBagConstraints constraints) {
refresh = new JButton("Refresh Joysticks");
refresh.addActionListener(new RefreshAction(this));
refresh.setPreferredSize(new Dimension(joysticks.getSize().width, 50));
mainframe.add(refresh, constraints);
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
enable.setText(enabled ? "Disable" : "Enable");
}
public State getState() {
return enabled ? state : State.Disabled;
}
public void setState(State state) {
setEnabled(false);
this.state = state;
switch (state) {
case Autonomous: protoState = DriverStation.State.AUTO; break;
case Teleop: protoState = DriverStation.State.TELEOP; break;
case Test: protoState = DriverStation.State.TEST; break;
default: break;
}
}
public void toggleEnable() {
setEnabled(!enabled);
}
public void advertise(Node node) {
pub = node.advertise("ds/state", DriverStation.getDefaultInstance());
}
public void publish() {
pub.publish(DriverStation.newBuilder().setEnabled(enabled).setState(protoState).build());
}
}

View File

@@ -0,0 +1,18 @@
package edu.wpi.first.wpilibj.simulation.ds;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class EnableAction implements ActionListener {
private DS ds;
public EnableAction(DS ds) {
this.ds = ds;
}
@Override
public void actionPerformed(ActionEvent e) {
ds.toggleEnable();
}
}

View File

@@ -0,0 +1,19 @@
package edu.wpi.first.wpilibj.simulation.ds;
import org.gazebosim.transport.Node;
public class FakeJoystick implements ISimJoystick {
public String getName() {
return "Empty Joystick";
}
public String toString() {
return getName();
}
@Override public void advertise(Node node, int i) {}
@Override public void publish() {}
}

View File

@@ -0,0 +1,9 @@
package edu.wpi.first.wpilibj.simulation.ds;
import org.gazebosim.transport.Node;
public interface ISimJoystick {
String getName();
void advertise(Node node, int i);
void publish();
}

View File

@@ -0,0 +1,118 @@
package edu.wpi.first.wpilibj.simulation.ds;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragSourceDragEvent;
import java.awt.dnd.DragSourceDropEvent;
import java.awt.dnd.DragSourceEvent;
import java.awt.dnd.DragSourceListener;
import java.util.List;
import javax.swing.DropMode;
import javax.swing.JList;
import javax.swing.TransferHandler;
import edu.wpi.first.wpilibj.simulation.ds.ISimJoystick;
import edu.wpi.first.wpilibj.simulation.ds.JoystickProvider;
@SuppressWarnings("serial")
public class JoystickList extends JList<ISimJoystick> {
private JoystickProvider joystickProvider;
List<ISimJoystick> joysticks;
public JoystickList(JoystickProvider joystickProvider) {
super();
this.joystickProvider = joystickProvider;
setDragEnabled(true);
setDropMode(DropMode.INSERT);
setTransferHandler(new DropHandler(this));
new DragListener(this);
}
public void moveElement(int index, int dropTargetIndex) {
ISimJoystick move = joysticks.get(index);
joysticks.add(dropTargetIndex, move);
joysticks.remove(index < dropTargetIndex ? index : index + 1);
setListData(joysticks);
}
public void setListData(List<ISimJoystick> sticks) {
joysticks = sticks;
setListData(sticks.toArray(new ISimJoystick[0]));
joystickProvider.setJoysticks(sticks);
}
class DragListener implements DragSourceListener, DragGestureListener {
JoystickList list;
DragSource ds = new DragSource();
public DragListener(JoystickList list) {
this.list = list;
ds.createDefaultDragGestureRecognizer(
list, DnDConstants.ACTION_MOVE, this);
}
public void dragGestureRecognized(DragGestureEvent dge) {
StringSelection transferable = new StringSelection(
Integer.toString(list.getSelectedIndex()));
ds.startDrag(dge, DragSource.DefaultCopyDrop, transferable, this);
}
public void dragEnter(DragSourceDragEvent dsde) {}
public void dragExit(DragSourceEvent dse) {}
public void dragOver(DragSourceDragEvent dsde) {}
public void dragDropEnd(DragSourceDropEvent dsde) {}
public void dropActionChanged(DragSourceDragEvent dsde) {}
}
class DropHandler extends TransferHandler {
JoystickList list;
public DropHandler(JoystickList list) {
this.list = list;
}
public boolean canImport(TransferHandler.TransferSupport support) {
if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return false;
}
JList.DropLocation dl = (JList.DropLocation) support
.getDropLocation();
if (dl.getIndex() == -1) {
return false;
} else {
return true;
}
}
public boolean importData(TransferHandler.TransferSupport support) {
if (!canImport(support)) {
return false;
}
Transferable transferable = support.getTransferable();
String indexString;
try {
indexString = (String) transferable.getTransferData(DataFlavor.stringFlavor);
} catch (Exception e) {
return false;
}
int index = Integer.parseInt(indexString);
JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
int dropTargetIndex = dl.getIndex();
list.moveElement(index, dropTargetIndex);
return true;
}
}
}

View File

@@ -0,0 +1,44 @@
package edu.wpi.first.wpilibj.simulation.ds;
import java.util.ArrayList;
import java.util.List;
import edu.wpi.first.wpilibj.simulation.ds.ISimJoystick;
import edu.wpi.first.wpilibj.simulation.ds.SimJoystick;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;
public class JoystickProvider {
List<ISimJoystick> joysticks;
public JoystickProvider() {
scanForJoysticks();
}
public List<ISimJoystick> scanForJoysticks() {
List<ISimJoystick> foundControllers = new ArrayList<>();
Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
for(int i = 0; i < controllers.length; i++){
Controller controller = controllers[i];
if (controller.getType() == Controller.Type.STICK
|| controller.getType() == Controller.Type.GAMEPAD
|| controller.getType() == Controller.Type.WHEEL
|| controller.getType() == Controller.Type.FINGERSTICK) {
foundControllers.add(new SimJoystick(controller));
}
}
joysticks = foundControllers;
return foundControllers;
}
public List<ISimJoystick> getJoysticks() {
return joysticks;
}
public void setJoysticks(List<ISimJoystick> joysticks) {
this.joysticks = joysticks;
}
}

View File

@@ -0,0 +1,29 @@
package edu.wpi.first.wpilibj.simulation.ds;
import org.gazebosim.transport.Node;
public class Main {
public static void main(String args[]) {
Node node = new Node("frc");
JoystickProvider provider = new JoystickProvider();
@SuppressWarnings("unused")
DS ds = new DS(provider);
ds.advertise(node);
while (true) {
ds.publish();
for (int i = 0; i < provider.getJoysticks().size(); i++) {
ISimJoystick joystick = provider.getJoysticks().get(i);
joystick.advertise(node, i+1);
joystick.publish();
}
try {
Thread.sleep(19);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

View File

@@ -0,0 +1,18 @@
package edu.wpi.first.wpilibj.simulation.ds;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ModeAction implements ActionListener {
private DS ds;
public ModeAction(DS ds) {
this.ds = ds;
}
@Override
public void actionPerformed(ActionEvent e) {
ds.setState(DS.State.valueOf(e.getActionCommand()));
}
}

View File

@@ -0,0 +1,18 @@
package edu.wpi.first.wpilibj.simulation.ds;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class RefreshAction implements ActionListener {
private DS ds;
public RefreshAction(DS ds) {
this.ds = ds;
}
@Override
public void actionPerformed(ActionEvent arg0) {
ds.scanForJoysticks();
}
}

View File

@@ -0,0 +1,69 @@
package edu.wpi.first.wpilibj.simulation.ds;
import gazebo.msgs.GzJoystick.Joystick;
import java.util.ArrayList;
import java.util.List;
import org.gazebosim.transport.Node;
import org.gazebosim.transport.Publisher;
import net.java.games.input.Component;
import net.java.games.input.Controller;
public class SimJoystick implements ISimJoystick {
private Controller controller;
private List<Component> axes, buttons;
private Publisher<Joystick> pub = null;
private int prevI = -1; private Node prevNode = null;
public SimJoystick(Controller controller) {
this.controller = controller;
axes = new ArrayList<>();
buttons = new ArrayList<>();
for(Component c : controller.getComponents()) {
if (c.getIdentifier() instanceof Component.Identifier.Axis) {
axes.add(c);
} else if (c.getIdentifier() instanceof Component.Identifier.Button) {
buttons.add(c);
}
}
}
@Override
public String getName() {
return controller.getName();
}
@Override
public String toString() {
return getName();
}
@Override
public void advertise(Node node, int i) {
if (pub == null) {
// I'm good
} else if (prevI != i || prevNode != node) {
// TODO: pub.close();
} else {
return; // No change
}
pub = node.advertise("ds/joysticks/"+i, Joystick.getDefaultInstance());
prevNode = node;
prevI = i;
}
@Override
public void publish() {
controller.poll();
Joystick.Builder builder = Joystick.newBuilder();
for (Component a : axes) {
builder.addAxes(a.getPollData());
}
for (Component b : buttons) {
builder.addButtons(b.getPollData() > 0.5);
}
pub.publish(builder.build());
}
}