Posts Tagged ‘robotc’

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

Leaky Integrator Class

December 22, 2010 2 comments

I have been working to update my framework lately and I ran across and interesting LeakyIntegratorconcept that can be used by robots to track recurring events and store them in a short-term memory that eventually fades.  This is useful, for instance, when a robot gets stuck in a corner, bumping left and them bumping right and repeating.  This behavior is called canyoning and seems to happen often.  The robot is essentially stuck in the corner, thrashing back and forth until something changes.

Using a Leaky Integrator allow the successive bumps to be summed in the short-term memory while at the same time leaking some bumps out of the bottom at a slower rate.  As the robot thrashes more the integrator is filled up.  This value could be used to adjust the spin angle for the robot so that the more times the robot bumps, the more it turns to get out of the corner.  As the robot escapes, the memory of the corner fades to prevent drastic actions on bumps later in its journey when it may not be stuck in a corner.

An analogy for the leaky integrator is a bucket with a drain in the side that can be opened to let some water out.  Water poured into the top fills the bucket if more water comes in than is let out the bottom.  If the water stops pouring in, eventually the level will decrease to the level of the side drain.  If too much water is poured in, the bucket will eventually have the maximum amount in it and the rest is lost over the top edges.

The RobotC code contains the class.  A sample program is commented out at the bottom.  It demonstrates instantiating the class and filling a bucket (as it tries to leak out) until the bucket is full.  Once full, the input is stopped, and the bucket drains.  Very simple, but might be useful to someone out there in Mindstorms land.

Download: LeakyIntegrator.c

Categories: RobotC Code Tags: ,

More fun with Math – Boolean Functions

August 6, 2010 1 comment

This is a quick post about some more math functions I found that might be useful.

I found a reference on the net that defined some boolean functions.  I added these to may math utility libary (just in case) and tested them.


OR, AND & NOT are already implemented in RobotC, but I included them because the math and logic to get the correct answer is kind of cool. 

Let me know what you think.

(I added a couple more boolean functions to the list tonight…