Go to Post FIRST is the only sort of competition that I've seen where somebody can win and the opponents can be genuinely happy for them. - RiceRobotica [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
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 13-01-2013, 01:43
William Kunkel William Kunkel is offline
Programming Lead
AKA: Kunkel
FRC #0422 (Mech Tech Dragons)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Richmond, VA
Posts: 94
William Kunkel is an unknown quantity at this point
Unit Tests & Test-Driven Development

Does anyone know of a sane way to write unit tests for robot code? I'd prefer to have a test-driven development cycle for our code, but I can't think of a good way to implement it for this kind of programming. There's a test harness project on FirstForge here, but it seems to be a dead project. Any ideas?
Reply With Quote
  #2   Spotlight this post!  
Unread 13-01-2013, 02:22
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,050
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: Unit Tests & Test-Driven Development

Revive the project
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #3   Spotlight this post!  
Unread 13-01-2013, 11:03
Spaghetti's Avatar
Spaghetti Spaghetti is offline
Registered User
FRC #0488 (XBot)
Team Role: Mentor
 
Join Date: Apr 2012
Rookie Year: 2011
Location: Seattle
Posts: 13
Spaghetti is an unknown quantity at this point
Re: Unit Tests & Test-Driven Development

Curious if short of emulating the robot like the test-harness project was trying for, does anyone have a nice flow for unit testing bits of logic sans crio that have no robot dependencies?
Reply With Quote
  #4   Spotlight this post!  
Unread 13-01-2013, 11:12
William Kunkel William Kunkel is offline
Programming Lead
AKA: Kunkel
FRC #0422 (Mech Tech Dragons)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Richmond, VA
Posts: 94
William Kunkel is an unknown quantity at this point
Re: Unit Tests & Test-Driven Development

I'd love to revive the project, but I don't think it's appropriate to do during build season.
Reply With Quote
  #5   Spotlight this post!  
Unread 14-01-2013, 13:08
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,050
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: Unit Tests & Test-Driven Development

What we created for RobotPy users (python interpreter for cRio) is a library called fake-wpilib, which has bare implementations of most of the WPILib objects. You setup some hooks, import the robot code, and call StartCompetition(), and your unit tests have access to see/control everything.

We have implemented separately a tk-based program that allows our students to run their python robot code in a simulator of sorts, and they can drive the robot around and use sensors and such.

If I was re-implementing the test harness again for C++, this is probably how I would go about it. It seems like someone could create a script that could parse the C++ code and automatically create functional shells from that. Tools like SWIG and SIP sorta do that sort of thing, you would just need a mechanism to map function inputs to public variables.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #6   Spotlight this post!  
Unread 14-01-2013, 13:43
Chris Hibner's Avatar Unsung FIRST Hero
Chris Hibner Chris Hibner is offline
Eschewing Obfuscation Since 1990
AKA: Lars Kamen's Roadie
FRC #0051 (Wings of Fire)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1997
Location: Canton, MI
Posts: 1,488
Chris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond repute
Re: Unit Tests & Test-Driven Development

The simplest way is to design your software units for test. What I mean is this: do NOT make any calls to the WPI library from within your unit. Make all calls to WPI library in a wrapper function.

For example:

Code:
void periodic_10ms_task(void)
{
    armAngle = WPI_readEncoder(ARM_ENCODER);
    armLimit = WPI_readDIO(ARM_LIMIT_SWITCH);

    armOutput = controlArm(armAngle, armLimit);

    WPI_setPWM(armOutput);
}
Before anyone complains: I don't really know what the WPI library function name are - the above names are made up (we use LabVIEW).

Now you can test you controlArm() function as a unit on a PC using MS VisualC++ Express.
__________________
-
An ounce of perception is worth a pound of obscure.
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 12:48.

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