Home > CollectorBot, My Robots, RobotC Code > Bumpers and Light – Combining Sensors into One Port

Bumpers and Light – Combining Sensors into One Port

TFR_20090713_0694_thumb.jpgSome of you may have noticed that my Collector Robot has more than two light sensors hanging off the sides…  There is an archaic bumper (design from the original Mindstorms 1.0 kit) and a legacy light sensor buried in the bumper.  There is also a couple of white arched technic pieces under the bumper.

I thought I would go into more detail on this design because the implementation was interesting.  This robot is designed to find and move Lego NXT pucks around.  It does not specifically search for pucks, but happens upon them because it is able to cover all areas of the arena.

Download the driver here: BumpLightCombo.h

Technical Background

The bumpers give the robot protection from walls and objects and trigger several behaviors within the robot to perform tasks like escaping a collision and following a wall (just like Areabot).

Collectorbot (2 of 4)

There is a “puck catch” under the bumper that is designed to either direct pucks into the middle where a light sensor can detect the black color, or deflect pucks to far to the right or left away from the wheels.  If a puck is detected in the catch, various behaviors are triggered to increase the chance the robot will deliver them to home base.

Sensor Implementation

Sometimes there is an opportunity to combine sensors together into one port that requires no additional hardware.  It requires a little bit of ingenuity and programming creativity, but the results can give you more sensory power without using additional input ports.

For my Collector Robot, I wanted to implement a front bumper to detect collisions, and a light sensor to detect captured pucks. As knowledge and experience luck would have it, I was able to combine the bumper and down pointing light sensor into one port because the sensors are not needed at the same time.

Collectorbot (3 of 4) Collectorbot (1 of 4)

There are a few compromises that need to be understood to configure the sensors using only one NXT input port.

  • The left and right bumpers are connected together to provide ONE bumper on the front of the robot.
    • A compromise with this configuration is the loss of ability to detect left or right collisions.  I used to think this was bad, but I found out it is not that big of a deal.  In my case, bumping is used to escape from a collision or for following a wall.  In both cases, I control the turning directions anyway, so there is no reason to implement left and right bumpers.  Escape randomly turns away from the wall.  Wall following always follows walls on the right side, so a spin gets it into position easily.
  • The legacy light sensor is also connected to the same port as the bumpers and is used to detect pucks in the “puck catch” area.
    • What happens, is the light sensor value is read as long as there is not a collision.  If there is a collision, the value goes to 100.  No problem for collector robot because I am continually monitoring for the presence of a puck when not hitting a wall.
      • You must implement bumpers that are normally open (not pressed) in order to use the light sensor.  These are not the best for bumpers because it takes more force to press the buttons than to release them.  Collector Robot gets beat up a little, but it is good for its sole 🙂  I can live with that.
      • When the bumper is pressed, the light sensor is useless.  This can be an issue if you need the bumpers and the light sensor at the same time.  In my case, a collision was more critical than whether or not I could detect a puck in the collector.

I wrote a driver that allows me to abstract all of this logic into a few functions I can call to check the sensor(s) status.  It is not complicated, but lets me concentrate on the rest of the code without remembering the implementation.

Code Listing

#define FRONT_BUMPER S2  //DEFAULT INPUT PORT FOR BUMPER SWITCH SENSOR
#define LIGHT_DOWN S2  //DEFAULT INPUT PORT FOR BUMPER SWITCH SENSOR 

const int kLightSensorDark = 24; //LIGHT SENSOR BLACK THRESHOLD 

//INITIALIZE FRONT BUMPER TYPE AND MODE
void BumpLightCombo_Initialize() {
  SensorType[LIGHT_DOWN] = sensorReflection;
  SensorMode[LIGHT_DOWN] = modePercentage;
} 

// CHECK THE SENSOR FOR BUMPED.  MUST BE NORMALLY OPEN AND CLOSED ON TRIGGER!
bool bumper_isBumped() {
  return (bool) (SensorValue[FRONT_BUMPER] >= 99);
} 

// CHECK THE SENSOR FOR BUMPED OR NOT BASED ON VALUE AND CONFIGURATION
bool lightDown_isDark() {
  return (bool) (SensorValue[LIGHT_DOWN] <= kLightSensorDark);
} 

// CHECK THE SENSOR FOR BUMPED OR NOT BASED ON VALUE AND CONFIGURATION
bool lightDown_isLight() {
byte _value = SensorValue[LIGHT_DOWN];
  return (bool) (_value > kLightSensorDark + 5 && _value <99);
}

cccc

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: