Go to Post We can either sit around and complain about what could have been, or we can focus on the upside of what we have and move on. - Vikesrock [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 12-02-2015, 11:31
Toa Circuit's Avatar
Toa Circuit Toa Circuit is offline
Thaddeus Maximus
AKA: Thad Hughes
FRC #4213 (MetalCow Robotics)
Team Role: Leadership
 
Join Date: Nov 2012
Rookie Year: 2012
Location: Shirley, IL
Posts: 131
Toa Circuit is an unknown quantity at this point
Logging error to driver station

We are using the RS-232 port on the roboRIO, so we can't use console out. I'm pretty sure I saw somewhere there's a way to put errors in the error log in the driver station (such as the ones seen at http://wpilib.screenstepslive.com/s/...rors-warnings).

We will be using this just for logging exceptions that are encountered via a try-catch; not like a constant stream of output data.

I'm struggling to find the class/method to do it. Does anyone know what it is?
__________________

2012 Head of Programming and Electrical
2013-14 Overall Team Captain and Programming Head
2012-14 Mentor of FLL Team Power Surge
2014 Dean's List Finalist
2014 CIR Xerox Creativity Award
Webpage
Reply With Quote
  #2   Spotlight this post!  
Unread 12-02-2015, 11:39
MrRoboSteve MrRoboSteve is offline
Mentor
AKA: Steve Peterson
FRC #3081 (Kennedy RoboEagles)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2011
Location: Bloomington, MN
Posts: 578
MrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond repute
Re: Logging error to driver station

DriverStation.reportError() is your friend.
__________________
2016-17 events: 10000 Lakes Regional, Northern Lights Regional, FTC Burnsville Qualifying Tournament

2011 - present · FRC 3081 Kennedy RoboEagles mentor
2013 - present · event volunteer at 10000 Lakes Regional, Northern Lights Regional, North Star Regional, Lake Superior Regional, Minnesota State Tournament, PNW District 4 Glacier Peak, MN FTC, CMP
http://twitter.com/MrRoboSteve · www.linkedin.com/in/speterson
Reply With Quote
  #3   Spotlight this post!  
Unread 15-02-2015, 22:05
shindigo shindigo is offline
Registered User
AKA: Mike Parker
FRC #0102
Team Role: Mentor
 
Join Date: Feb 2012
Rookie Year: 2009
Location: Somerville, NJ
Posts: 33
shindigo is an unknown quantity at this point
Re: Logging error to driver station

Unfortunately, we've found that reporterror does not give the stack trace to the error but to the line that reports the error Putting ex.printStackTrace() in our exception handlers is necessary.
Reply With Quote
  #4   Spotlight this post!  
Unread 17-02-2015, 11:48
MatthewC529 MatthewC529 is offline
Lcom/mattc/halp;
AKA: Matthew
FRC #1554 (Oceanside Sailors)
Team Role: Mentor
 
Join Date: Feb 2014
Rookie Year: 2013
Location: New York
Posts: 39
MatthewC529 is on a distinguished road
Re: Logging error to driver station

Quote:
Originally Posted by Toa Circuit View Post
We are using the RS-232 port on the roboRIO, so we can't use console out. I'm pretty sure I saw somewhere there's a way to put errors in the error log in the driver station (such as the ones seen at http://wpilib.screenstepslive.com/s/...rors-warnings).

We will be using this just for logging exceptions that are encountered via a try-catch; not like a constant stream of output data.

I'm struggling to find the class/method to do it. Does anyone know what it is?
We wanted the same thing, so after some digging around I have this code:
Code:
      public static final void writeToDS(String message) {
		final HALControlWord controlWord = FRCNetworkCommunicationsLibrary.HALGetControlWord();
		if (controlWord.getDSAttached()) {
			FRCNetworkCommunicationsLibrary.HALSetErrorData(message);
		}
	}

    public static final void exceptionToDS(Throwable t) {
		final StackTraceElement[] stackTrace = t.getStackTrace();
		final StringBuilder message = new StringBuilder();
		final String separator = "===\n";
		final Throwable cause = t.getCause();

		message.append("Exception of type ").append(t.getClass().getName()).append('\n');
		message.append("Message: ").append(t.getMessage()).append('\n');
		message.append(separator);
		message.append("   ").append(stackTrace[0]).append('\n');

		for (int i = 1; i < stackTrace.length; i++) {
			message.append(" \t").append(stackTrace[i]).append('\n');
		}

		if (cause != null) {
			final StackTraceElement[] causeTrace = cause.getStackTrace();
			message.append(" \t\t").append("Caused by ").append(cause.getClass().getName()).append('\n');
			message.append(" \t\t").append("Because: ").append(cause.getMessage()).append('\n');
			message.append(" \t\t   ").append(causeTrace[0]).append('\n');
			message.append(" \t\t \t").append(causeTrace[2]).append('\n');
			message.append(" \t\t \t").append(causeTrace[3]);
		}

		writeToDS(message.toString());
	}
This will send messages directly to the DriverStation LCD.
This can either write to the DS or log a Stack Trace to the DS. If there is a cause it goes one-level deep and logs the cause as well.

It does make use of StringBuilder but this is entirely feasible just appending Strings.
StringBuilder was used just to maintain memory and speed.
__________________
Team 1554 -- Oceanside Sailors
  • 2013-2014 - Lead/Sole Programmer
  • 2014-2015 - Lead Programmer, President
  • 2015-? - Team 1554 Mentor
Independent Public Projects

Developer at Legend Zero LLC.
Java/C++ Programmer

Last edited by MatthewC529 : 17-02-2015 at 11:52.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:50.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi