Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toast Simulation GUI #50

Open
vectorcrumb opened this issue Jan 7, 2017 · 6 comments
Open

Toast Simulation GUI #50

vectorcrumb opened this issue Jan 7, 2017 · 6 comments

Comments

@vectorcrumb
Copy link

Would it be possible to have an independent simulator to aid teams who are using the default tools given to them by FIRST? Maybe a sort of wrapper which takes calls to the WPIlib classes and redirects those function calls to the GUI

@JaciBrunning
Copy link
Member

The way Toast's Simulation GUI currently works is by redirecting WPILib JNI calls to the GUI. Toast has a wrapper system that doesn't require a Toast module and will work with a normal WPILib jar. This won't work for 2017 binaries just yet, but works fine for 2016 codebases. Drop your .jar file into toast/modules and run Toast to get it up and running.

@vectorcrumb
Copy link
Author

I created a module with Hotplate and the instructions from the wiki and ran the basic module. The project has a run/toast/modules directory, so I suppose it goes in there. However, I'm not sure how to get the simulator running without compiling and loading the code in the src folder. Also, how does the sim manage calls to joysticks? If the code requires joysticks but they aren't connected to the computer when running the .jar will Toast crash?

@JaciBrunning
Copy link
Member

  1. To use joysticks, you need to connect the driver station to the simulator. If no joysticks are connected, all axis will read 0 and all buttons will read false.

  2. You can run simulation as normal and Toast will pickup the jar

@vectorcrumb
Copy link
Author

Ok, so I added the module and used the TestModule-Sim run config in IntelliJ 2016.3 with code compiled with the 2016 FRC plugins in Eclipse Mars (the code was developed with Eclipse but I felt like running Toast in IntelliJ). I dropped the the .jar into the modules folder: run/toast/modules/FRCUserProgram.jar. Initially I had an error with an ADIS16448_IMU class that tried to initialize a SPI port, so I removed all calls to that class. However, I'm now getting errors with the Encoder class provided with the FRC plugins. I've included the output:

 ________    ______                 __   
((       )  /_  __/___  ____ ______/ /_  
||  o o  |   / / / __ \/ __ `/ ___/ __/  
||   3   |  / / / /_/ / /_/ (__  ) /_    
\\_______/ /_/  \____/\__,_/____/\__/    

[09/01/17-01:43:34] [Toast] [Bootstrap] [INFO] Toast Version: 2.4.14
[09/01/17-01:43:34] [Toast] [Bootstrap] [INFO] Toast Commit Hash: 2022e41
[09/01/17-01:43:35] [Toast] [Core-Initialization] [INFO] Toast Started with Run Arguments: [-sim, --search, -ide, IDEA]
[09/01/17-01:43:35] [Toast] [Pre-Initialization] [INFO] Slicing Loaf...
[09/01/17-01:43:35] [Toast] [Initialization] [INFO] Nuking Toast...
platform: /Windows/amd64/
[09/01/17-01:43:36] [Toast] [Pre-Start] [INFO] Buttering Bread...
[09/01/17-01:43:36] [Toast|Loader] [Pre-Start] [INFO] Module Loaded: TestModule@0.0.1
[09/01/17-01:43:36] [Toast|Loader] [Pre-Start] [INFO] Module Loaded: FRCUserProgram.jar!wrapper@0.0.0
[09/01/17-01:43:36] [Toast] [Start] [INFO] Fabricating Sandwich...
[09/01/17-01:43:36] [Toast] [Start] [INFO] Verdict: Hot, Hot, HOT!!
[09/01/17-01:43:36] [Toast] [Main] [INFO] Total Initiation Time: 1.302 seconds
[09/01/17-01:43:37] [Toast] [Thread-9] [ERROR] Could not instantiate Wrapped Module reflection on robotInit: java.lang.reflect.InvocationTargetException
[09/01/17-01:43:37] [Toast] [Thread-9] [ERROR] java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at jaci.openrio.toast.lib.module.ModuleWrapper.reflectMethod(ModuleWrapper.java:150)
	at jaci.openrio.toast.lib.module.ModuleWrapper.lambda$start$21(ModuleWrapper.java:92)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.UnsatisfiedLinkError: edu.wpi.first.wpilibj.hal.EncoderJNI.initializeEncoder(BIZBIZZLjava/nio/IntBuffer;)J
	at edu.wpi.first.wpilibj.hal.EncoderJNI.initializeEncoder(Native Method)
	at edu.wpi.first.wpilibj.Encoder.initEncoder(Encoder.java:87)
	at edu.wpi.first.wpilibj.Encoder.<init>(Encoder.java:171)
	at com.team2576.robot.io.SensorInput.<init>(SensorInput.java:82)
	at com.team2576.robot.io.SensorInput.getInstance(SensorInput.java:71)
	at com.team2576.lib.Kapellmeister.<init>(Kapellmeister.java:28)
	at com.team2576.lib.Kapellmeister.getInstance(Kapellmeister.java:34)
	at com.team2576.robot.ChiliRobot.robotInit(ChiliRobot.java:57)
	... 7 more

The error occurs in this call:

public static SensorInput getInstance() {
	if(instance == null) {
		instance = new SensorInput();
	}
	return instance;
}

which calls the following constructor:

private SensorInput() {
	this.inputValues = Collections.synchronizedMap(new LinkedHashMap<String, Double>());
	
	pdp = new PowerDistributionPanel();
//	adIMU = new ADIS16448_IMU();
	cuiLeft = new Encoder(ChiliConstants.iLeftEncoderA, ChiliConstants.iLeftEncoderB, false, EncodingType.k4X);
	cuiRight = new Encoder(ChiliConstants.iRightEncoderA, ChiliConstants.iRightEncoderB, false, EncodingType.k4X);
	intakeAngle = new Encoder(ChiliConstants.iIntakeEncoderA, ChiliConstants.iIntakeEncoderB, false, EncodingType.k4X);
	
	camLeft = new USBCamera(ChiliConstants.kCamLeft);
	camCenter = new AxisCamera(ChiliConstants.kCamCenter);
	//camRight = new USBCamera(ChiliConstants.kCamRight);
	
	camLeft.openCamera();
	//camRight.openCamera();
	camLeft.startCapture();
	//camRight.startCapture();	
	
	abort_vision = false;
		
	this.initEncoders();
}

The error occurs when initializing cuiLeft.

@JaciBrunning
Copy link
Member

Your code is using Encoders, however Toast doesn't currently support Encoder simulation. See #35

@vectorcrumb
Copy link
Author

My bad, I forgot to look through the other issues. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants