If someone could point me in the right direction here -or- maybe a link to some code examples.
I would like to draw a line from a fixed point, a given length and at a given angle. I have found some examples that show a line that will follow your mouse and will rotate around a fixed point, but not one including length.
Here is what I am looking at doing:
I want to draw a map (just a line showing a path) on my screen as walter travels around. Each time walter changes direction, a little data packet is sent describing his last move. I.e.
fwd (16) counts (send that to processing and a line is drawn from starting point and is (16) units long)
rotated (4) counts or 1/4 turn (send to processing and the angle of the next line is determined)
fwd (27) counts (a line, 27 units long is drawn at the angle determined above)
Each new line segment will start from the end of the last one drawn.
Here’s just another example (in C): #include <stdio.h> #include <math.h>
#define PI 3.14159265
static float heading = 0; /* Initial heading in degrees / static float x = 0; / Initial x coordinate / static float y = 0; / Initial y coordinate /
/ Travel d units to current heading / void travel(float d) { float rad = heading * PI / 180; printf(“Travelling %.3f units\n”, d); x = x + cos(rad) * d; y = y + sin(rad) * d; }
I played around with that snippet and got bored real fast. And puzzled. All it has in common with your “problem” are the pretty lines. I cannot even figure out which feature is being demonstrated here.
The only statements in this code that I want you to learn now are “pushMatrix” and “popMatrix”. You DO know about the selecting a word and right-clicking on it, right? “find in reference” Baby!
BTW, the matrix lines in this code can be disabled without changing anything 8-(
Processing is getting the data --the print string responds with
r:259t:18t:0
but I get nothing after that. Now I know you tested this based on your picture so the problem must be with the way I am sending the data. Also, what is the second “t” for?
Those are just examples! Send them individually! They each need a CR. Got it.
Man, this is exactly what I wanted! Perfect. I mean, you wrote my code! Hat’s off, sir.
I just need to change the start position and figure out the converion math for what I am sending vs. how big the window is. --I guess I just need to do the “scale math”. Perfect.
As we all know, picaxe does not like negitive numbers. I would say that I will have to find a mid-point between a given min and max and have processing translate that mid-point to 0 and thus go positive and negitive from there. To be honest, it was very late last night when I was playing with your code so I didn’t have a lot of time to figure out numbers. I have a lot of chores to do today, but if I get them done and get to play with my computer, I have some test plans in the works:
I was figuring on two pots with a debug to sertxd or LCD for turns and distance. A push button would send the data after it is dialed in by the pot. This way I can see exactly what I am sending and what I am getting. I’ll probably write all that down on a piece of paper using a pencil. From there, I just need to find my notes on my encoder count math and do the conversion. Should be pretty simple. Not to mention, one of my chores today is to get this house cleaned up --which is needed for walter to go “free range”… There are a couple “sonar holes” that need a piece of cardboard in front of them and a big sonar-soaking couch which appears as infinity and is thus a walter-magnet. I should have some solid working results soon.
The picaxe does not NEED to understand negatives, as long as it is transmitting the “-” character when appropriate. But then of course, who needs it: 30 degrees CCW = 330 degrees CW anyways.
The real fun starts with using a circle made of degrees 0-255, so that it will always fit inside a byte. You might want to make up a silly, distinctive name for that unit. Wikipedia probably already has it on file. Without the funny.
Another advantage of the single byte approach to headings/bearings: the roll-over at the bottom and top of the range: 255 + 1 = 256 = 0 2 - 3 = -1 = 255
You know rik, I have been playing with the code and to be honest, I just don’t want to bother converting to a 256 circle. It is simply worth using a word to get the 359 that I need. In reality, most of the time I would not need anything past 270. I tried sending a - along with my travel distance (r:0) and sure enough, it back-tracked along it’s own line. Perfect.
You know, I thought I was done with hardware on Walter and here I am adding 2 more encoders and one more picaxe. Not to mention I just added a RFID reader and the new voice box.
I am adding this mapping system to my control panel and quickly found a problem… You have background() turned off and the lines don’t get cleared. With background on, the image is refreshed each frame and you only see each line segment as it is sent from the robot. The bottom line is that the map (what we have drawn so far (all the line segments)) need to be redrawn after the background command, each time through. My only thought is to keep adding the r: and t: commands to a string as they come in and on each loop, read them back (one-by-one),split each pair up, run them all through a quick “redraw all this” sub-loop and redraw it that way. I have to have the background command in my draw loop for my controls to work. My other thought was to put the map in a second window, but I have not found any information on that. You got any thoughts?
I don’t even know if there is a max size of a string and/or how long it is going to take to redraw everything each time.
Maybe you could use off-screen buffer to draw all the lines and then draw the buffer to screen when it’s ready. Here’s a link I found about that: http://wiki.processing.org/w/Draw_to_off-screen_buffer. That way the redraw speed shouldn’t be a problem. If you are worried about string lengths you could use ArrayList to store string or maybe convert string to PVector before storing.
Just a note: I’ve not done anything with processing myself (Maybe I should. It seems to be popular around here) so all above is more or less a guess how your problem could be solved.