Mapper

Hi, I have not been programming microcontrollers long, and my last project, of which i am now waiting for parts to arrive, so have a delay, I had a lot of help with the methods, from nexisnet here. This project therefore i want to see how far i can get on my own, obviously i will still need help my my knowledge is now much greater than it was before…

anyway, i want to build something that logs where i walk, simple really every time i put my foot down it adds a distance to a variable (button in bottom of shoe).

I want to modify it though. I am going to have a switch so that if i twist my foot left it knows it, and right aswell.

I am having trouble though in how to account for that in the programming. Could i do that with a two dimenstional array:

array[][1]
where the program continues to add to the same data point in the array until the left or right direction point is pressed, then moves to the next one. But how would i be able to record whether i moved left or right. with this method i would just know i DID move left or right but not which one…

This is where I’m at:

DDRC &= ~(1 << PC5);
   PORTC|=(1<<PC5);
   //change direction button 
DDRC &= ~(1 << PC6);
   PORTC|=(1<<PC6);
float travel[][1] = 0;
int i=0;
if (!(PINC&(1<<PC5)));
{
		//while direction button is not pressed
	while(PINC&(1<<PC6))
		{
		i=i;

		}
		else//if direction button is pressed
			{
			i = i+1;
			}
	travel[i][1] = travel[0][1] + 1;//1 being 1 metre - rough estimate of a step.

}

Hello.

If you want to conserve space, you will simply store a list of all of the coordinates you have visited. For example, make a struct for an x-y point:

struct point
{
char x;
char y;
};

Note that you should use the smallest data type you can handle for storing x and y. chars are a single byte each that can range from -128 to 127. If you need to store bigger numbers, try using an int, which is a two-byte integer value.

Then make an array of these structs:

struct point path[100];

Note that microcontrollers typically do not have a lot of RAM, so you might be very limited in the amount of data you can store. If you use chars to encode x and y, the above array will take up 200 bytes. If you use ints, it will take up 400 bytes.

Internally you will probably want to store your current position (this would be the most recent addition to your path array) and your current orientation. This coupled with your knowledge about your next step should let you calculate your next position, which you would add to the array.

- Ben

Thanks Ben, I have never heard of struct points,does C understand:

in my case what are you thinking x and y are, how are you thinking the method should work, dont worry about space, i am going to write it to a text file on an sd card. i am hoping to end up with a file saying something like:

50 steps
left
10 steps
left
5 steps
right
etc etc
where does your x and y fit in? I am thinking to have a button to record steps, and a potentiometer to measure the angle turn - calibrated obviously

“point” was the name I gave the struct so I could refer to it later when creating the aray. C recognizes structs. If you don’t have to worry about space then you can be as inefficient at storing the information as you want. In my suggestion the x and y are your two-dimensional cartesian coordinates along the path you walk. For example, you can call your starting point (0, 0) (x = 0, y = 0) and decide that north is in the positive y direction and east is in the positive x direction. If you take one step west, you are now at point (-1, 0). If from there you take one step north, you are now at point (-1, 1). At this point your array would look like:

{ (0, 0), (-1, 0), (-1, 1) }

Each array entry tells you your position relative to your starting location after n steps, where n is the index of the array entry. Your method would work fine, too.

- Ben

how were you planning on inputing your information?

I wasn’t… All I was doing was giving you a way to store your data. You need to figure out what sensors to use and how. It sounds like a fairly difficult problem since I don’t see an obvious way for you to tell which way you’re stepping. I’ve heard of people doing this sort of thing with GPS (which would probably be the easiest solution for you, but also the most expensive). You could also consider using an compass sensor to determine what your orientation is and some other sensor (a pedometer or a button in your shoe) to detect steps. It then becomes a matter of trigonometry to determine your coordinates since you’re moving a distance D at an angle A:

dx = D * cos(A)
dy = D * sin(A)

- Ben