Posts Tagged ‘code’

Classes for virtual Sensors–Bumpers

January 2, 2011 Leave a comment

As I rework the behavior-based robot framework, I am encountering other areas of code that could also use improvement.  In the case of some of my sensor wrappers, I am not even sure if I ever published them.  I sometimes create virtual sensors when a group of sensors is used for specialized purposes.  The robot programs are more readable and internal logic can be abstracted from the rest of the program making for an easier implementation.

Bumpers – An example of a virtual sensor

I have a tendency to use bumpers on the front of my robots for easy (bump and escape) navigation.  Over the years I have created a couple of code sets that treat the bumper as one sensor even if I use two or more physical sensors to create it.  This article shows why and how I created a class to hide the details of a “Front Bumper” implementation.

Read more…


Code Downloads Fixed!

December 30, 2010 Leave a comment

I moved the code files to another service that is much easier for me to control.  The main framework code and the featured robot code in the following page should give you a good start.

My Framework Code

Thank you for your patience.

Behavior-based Framework Code–Download

December 23, 2010 2 comments

I am in the process of updating the framework to 3.0, but in the mean-time, here is the latest production version.

RobotC Behavior-Based Framework for Autonomous Robots 2.2

Other links on the site have not been corrected yet.  Sorry for the inconvenience.

Some of the features for 3.0 include:

  • Robot behaviors collection in one place with a core set of methods to operation on them.
    • Adding behaviors is easier now.  Just update the Behaviors list and it will be automatically initialized in the collection.
  • The arbitrator is now a class which means you can deploy more than one.  This might be useful for a robot that moves and has an arm that needs arbitration.
    • Behaviors can be assigned to an arbitrator (or not) from the robot’s behavior pool.
    • The drive module was extracted from the original arbitrator so arbitrators can be used for anything. – The 2 drive parameters were made generic in the behavior class to support this as well.

— More to come.

Robot Angle Functions

December 23, 2010 Leave a comment

One more article before I retire for the Christmas holiday.  It is valuable at times to know the normalized degrees of rotation.  I found some cool functions that take any number of degrees and converts them to either 0-359 degrees, or –180 to 179 degrees depending on your needs.

This code uses the MOD operator in RobotC to return the number of degrees left over after dividing by 360.  These are pretty handy functions.

1 // Returns an angle in degrees between 0 and 359 2 int norm_360(int deg) { 4 return deg%360; 5 } 6 7 // Returns an angle in degrees between -180 and 179 8 int norm_180(int deg) { 9 return norm_360(deg + 180)-180; 10 } 11

* Thanks Xander for the reminder about the RobotC mod operator.

Categories: RobotC Code Tags: , , , ,

Weighted Average Class

December 22, 2010 Leave a comment

Continuing on my current fascination with math and code to implement it, I decided to write a class for weighted average monitoring.  Creating a running average of a stream of numbers can be complicated, and consume many variables (depending on how many samples make up the average).  It also means you have create some sort of queue so the values can shift such that the n most current samples are available for calculation.  That can be a lot of work.

Average = SUM(nSamples)/n 

I found a shortcut to all of that where an average value is maintained in the background, and a weighted percentage is applied to the newest input value and the previous average.  I am sure this method is not as accurate as averaging the last n values, but the goal is not so much precision, but reducing spikes and anomalies.  In other words, I don’t care what the actual average is; I care that the trend of values over time reduces the spikes and provides usable information to the robot with less error.

Weighted Average = New Sample * %wt + (1-%wt)*Previous Average

This class can help filter sensor data to a robot, making it react more slowly to large value changes.  Try it and let me know what you think…

You can download the code here: WeightedAverage.c

Fun with Math – Returning plus or minus a Value

April 11, 2010 Leave a comment

Have you ever wanted to add or subtract a number from another at random?  This might come in handy when programming a robot to add randomness to otherwise predictable movement or decision making.  I checked out the web to see what the math world had done to help out.

I found a cool formula:

n = n + 2f(random(1) – 0.5)

Read more…

Behavior-Based Robot Framework 3.0

April 11, 2010 1 comment

I released a new version of my behavior-based robot framework today.  It includes inhibit and enable functionality.  Let me know what you think.

Download it here: Behavior-Based Robot Framework 3.0

I included a sample robot that extends the basic CRUISE robot by adding a new behavior SPIN that periodically inhibits CRUISE and takes control. 

Read more…