Suggestion: Template specialisation for CRange<CRadians>

Discussions regarding ARGoS bugs. Report bugs here.
mallwright
Posts: 35
Joined: Tue Apr 17, 2012 11:15 am

Suggestion: Template specialisation for CRange<CRadians>

Postby mallwright » Thu Jun 14, 2012 3:07 pm

Hi All,

I've come across a problem in ARGoS that I am going to make a patch for, however I would like to get some feedback first.

The patch will create a specialised version of the CRange template for types CRadians and CDegrees. Consider the following scenario to understand my motivation for this.

I would like to specify a range that is plus-minus an offset angle from an variable angle as an input. Creating the object using ARGoS libraries would look like this:

Code: Select all

CRange<CRadians> MyRange( InputAngle - OFFSET_ANGLE_CONST, InputAngle + OFFSET_ANGLE_CONST)
Now If I choose to represent angles from 0-->2pi, I have a problem such that if; InputAngle < OFFSET_ANGLE_CONST the lower bound will wrap around. This causes one of two problems, firstly the lower bound is greater than the upperbound, or secondly if the bounds were switched around, we would be actually talking about the exterior range instead of the interior range that was the target interval.

I propose that I fix this problem using template specialisation. A well known use of template specialisation is the std::vector specialisation for the type bool. Using template specialisation I can build the intelligence into CRange for the types CRange<CRadians> and CRange<CDegrees> such that we fix this problem.

Cheers,

pincy
Site Admin
Posts: 632
Joined: Thu Mar 08, 2012 8:04 pm
Location: Boston, MA
Contact:

Re: Suggestion: Template specialisation for CRange<CRadians>

Postby pincy » Fri Jun 15, 2012 9:11 am

I see the problem you're talking about and I think template specialization is a sensible technique to implement a solution.
What kind of solution do you want to implement?
I made ARGoS.

mallwright
Posts: 35
Joined: Tue Apr 17, 2012 11:15 am

Re: Suggestion: Template specialisation for CRange<CRadians>

Postby mallwright » Fri Jun 15, 2012 9:29 am

The solution that I will implement will provide same functionality and will be transparent to the user of the API.

The difference would be that I would compensate for things such that if a range given was between 10 and 30 degrees, and user ran the method CRange::WithinMinBoundIncludedMaxBoundIncluded(385), this would return true. Furthermore you could specify the upper-bound of the range to be something like -90 degrees and the lower bound the be +30, and it the range would catch all angles that were over that 120 degree interval.

There are a couple of ways this could be implemented, I think the simplest might involve just offsetting everything by a complete revolution, and offsetting all the arguments into the correct domain as they are passed in. But I will post an implementation proposal here in a couple hours based on what I come up with...

Cheers,

pincy
Site Admin
Posts: 632
Joined: Thu Mar 08, 2012 8:04 pm
Location: Boston, MA
Contact:

Re: Suggestion: Template specialisation for CRange<CRadians>

Postby pincy » Fri Jun 15, 2012 9:40 am

Ok great, thanks a lot! :-)
Please, post a diff and not the complete file (unless you add new files).
I made ARGoS.


Return to “Bugs”