Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
I have the following problem: my robot should look around, store what it saw with its sharp en than drive towards the most likeable thing it saw, being likebale means not too narrow, like the leg of a chair and not too big like a door or a wall. The looking around and storing what it saw i already managed, the sensor reading is stored in an array, 20 different headpositions are stored.But i dont know how to program:If you find more than 4 headpositions with distance readings that do not differ too much, ignore it.if you find less than 2 headpositions with distance readings that do not differ too much, ignore it.else drive to it, this part i also have...I think i'll need a sonar to detect the narrow object reliably, but that is a budgetary impossibility right now...Thanks already for any help!
Hi,I want it to go to the nearest thing it sees around it, that is smaller than 30cm.Later on i want to add a temperature sensor and tell it to ignore things that are not 37 degrees celsius, but one thing at a time!
#include <stdio.h>#include <stdlib.h>#define NUM_THINGS 20/* * Support macros for the Thing struct. */#define MIN(a, b) (a < b) ? a : b#define MAX(a, b) (a > b) ? a : b#define THING_MIN_TEMP(a, b) MIN(a.temp, b.temp)#define THING_MAX_TEMP(a, b) MAX(a.temp, b.temp)#define THING_MIN_HEIGHT(a, b) MIN(a.height, a.height)#define THING_MAX_HEIGHT(a, b) MAX(a.height, b.height)#define THING_MIN_DIST(a, b) MIN(a.distance, b.distance)#define THING_MAX_DIST(a, b) MAX(a.distance, b.distance)/*! * @brief Describes a `thing` that the bot sees. */typedef struct { /*! * Temperature of the object in celsius. (Going out on a limb and * hoping that char may be signed; it's implementation specific) */ char temp; /*! * Height of thing in undefined units. It's up to you to decide what your * unit of measure is. Because it's in a char, you only get 255 values. * (Well 256 if you count 0; assuming a char is 8 bits) */ unsigned char height; /*! * Distance to object in some undefined unit. Again, you decide what your * unit of measure is. */ unsigned short int distance;} Thing;/*! * Initialize the array of things. */voidinit_things(Thing things[]){ int x; for (x = 0; x < NUM_THINGS; x++) { things[x].temp = rand() % 128; things[x].height = rand() % 255; things[x].distance = rand() % 32767; }}/*! * Print out all things. */voidprint_things(Thing things[]){ int x; printf("All Things\nnumber, temp, height, distance\n"); for (x=0; x < NUM_THINGS; x++) { printf("%5d, %5d,%5d,%5d\n", x, things[x].temp, things[x].height, things[x].distance); } printf("\n");}/*! * Return the index of thing that has the maximum temperature. */size_tmax_temp(Thing things[]){ size_t x, max_idx = 0; char max_temp = things[0].temp; for (x = 1; x < NUM_THINGS; x++) { if (max_temp < things[x].temp) { max_temp = things[x].temp; max_idx = x; } } return max_idx;}/*! * Return the index of the closest thing. */size_tmin_distance(Thing things[]){ size_t x, min_idx = 0; unsigned short int min_distance = things[0].distance; for (x=1; x < NUM_THINGS; x++) { if (min_distance > things[x].distance) { min_distance = things[x].distance; min_idx = x; } } return min_idx;}int main() { /* * Declare 20 Things and fill them in. */ Thing things[NUM_THINGS]; init_things(things); print_things(things); printf("Thing %d has the maximum temperature.\n", max_temp(things)); printf("Thing %d is the closest.\n", min_distance(things)); return 0;}