I recently order two DROD-Nx proximity sensors from mindsensors.com and wanted to see how they performed on my Synchro drive robot platform. I thought that the best way to test them would be to write a sample program to draw an “obstacle map” on the NXT screen that represented what the sensors detected. Next step is to write code for the robot to back itself out of corners and avoid obstacles.

// Bitmask defining which segments around the vehicle perimeter an
// obstacle was detected in. Obstacles can be located all around
// the robot so we need to know every obstacle in one reading
// to plan a route away from them
typedef enum {
kNoObstacles = 0,
kFrontLeft = 1,
kFront = 2,
kFrontRight = 4,
kRearLeft = 8,
kRear = 16,
kRearRight = 32
} tObstacleLocation;

// Global variables
int line = 1;
tObstacleLocation obstacleLocation;

// This array contains the start and endpoints of each line
// segment we draw around the robot graphic on the screen
// Each segment is represented as four coordiantes
// 0: start x
// 1: start y
// 2: end x
// 3: end y
//
// The contents are computed once based on the dimensions specified
// in ax, ay, h, t during initialisation
int obstacleMap[6][4];

// compute the distance between the front DROD reading and each
// return value. The one with the smallest error is the location
// of the obstacle
front = SensorValue[frontDROD];
rear = SensorValue[rearDROD];

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum