The problem:
I am not really sure. I almost have it all put together, but I get weird artifacts when drawing visualizations. Little things are not behaving as they should (i.e. I believe a line should be horizontal, the numeric output is horizontal, but processing draws it with a slight incline). The problem is that it part of a bigger project and I am having trouble locating the problem. I would like to be able to make sure that my math is solid. If anyone could help me think through this, it would help me a lot.
I will not post the whole code, as I think it might be overkill, but start with the parts which are most critical.
(I am happy to post the rest, if it helps, but at the moment what is most important to me is to know that the following functions are doing what I think they are.)
Step1 - Calculate B
StartingPoint = A
BONE_LENGTH = Distance AB
Endpoint = B
PVector CalculateEndPoint()
{
float endpointY = sin(rotation.y)*BONE_LENGTH;
//cos(pitch) = adjecant / hypothenuse
//projection is the line AB projected onto the 'ground plane'
float projectionXZ = cos(rotation.y)*BONE_LENGTH;
//sin(yaw) = opposite / hypotenuse
float endpointZ = cos(rotation.x)*projectionXZ;
// float eX = sqrt((projectionXZ*projectionXZ)-(eZ*eZ));
I know its sort of wierd talking of roll in this situation. In order to better conceptualize what I want to achieve here, imagine there is a camera hanging on the wall. It is filming an analogue watch which is hanging, somewhat offset, on the oppoite wall. I want to know the angle between the minute pointer and the center of the image.
The center of the image would be my point D. The angle which the minute pointer is at would be my Roll angle.
(and I only know where this imaginary clock is, because I know its at the end of line BC)
Could somebody please glance at my code and tell me if I am making any obvious mistakes? Somehow it is introducing a significant amount of lag, which I cannot account for.
I am using two Arduinos. Arduino1 reads 8 capacitive sensors and sends them to my computer via serial connection. The other Arduino2 is running Firmata and controlls 8 motors.
If I am running the serial consule of Arduino, the readings from Arduino1 appear snappy and fast. In my own software however, it lags behind by ~500ms
Here is the code:
//handles the touch issues.
// incoming touch is a serial connection, outgoing touch runs via firmata
//array for storing incoming values, arranged according to evernote pins??
int[] incomingValues = new int[8];
//threshholds for deciding whether there is contact or not
int[] thresholds = new int[8];
//array for storing motor connections
int[] motorPins = new int[8];
import processing.serial.*; //import the Serial library
import cc.arduino.*;
Arduino arduino;
char end = '\n'; // /nl is the end of the message
String incomingString; // the string which is read
Serial port; // The serial port
String[] a; //string for temporarily storing the incoming values
void setup() {
println(Arduino.list()); //list all arduinos connected
arduino = new Arduino(this, Arduino.list()[3], 57600);
port = new Serial(this, Serial.list()[2], 9600);
incomingString = port.readStringUntil(end);
port.clear(); // function from serial library that throws out the first reading, in case we started reading in the middle of a string from Arduino
incomingString = null; // initially, the string will be null (empty)
//set all pins as output and set then low
for (int i = 0; i <= 13; i++) {
arduino.pinMode(i, Arduino.OUTPUT);
arduino.digitalWrite(i, Arduino.LOW);
}
//assign which motor is connected to wich pin (i.e. motor 0 is connected to pin 11)
motorPins[0] = 11;
motorPins[1] = 10;
motorPins[2] = 9;
motorPins[3] = 8;
motorPins[4] = 7;
motorPins[5] = 6;
motorPins[6] = 5;
motorPins[7] = 3;
//assign the thresholds for each sensor (i.e. if sensor 2 has a reading higher then 3 its a contact)
thresholds[0] = 1;
thresholds[1] = 2;
thresholds[2] = 3;
thresholds[3] = 2;
thresholds[4] = 2;
thresholds[5] = 2;
thresholds[6] = 2;
thresholds[7] = 2;
}
void draw() {
while (port.available () > 0) { //as long as there is data coming from serial port, read it and store it
incomingString = port.readStringUntil(end);
}
if (incomingString != null) { //if the string is not empty
a = split(incomingString, ", ");
//this is done in order to remap the incoming values so they are in the apropreate order
incomingValues[0] =int(a[6]);
incomingValues[1] =int(a[7]);
incomingValues[2] =int(a[0]);
incomingValues[3] =int(a[1]);
incomingValues[4] =int(a[2]);
incomingValues[5] =int(a[4]);
incomingValues[6] =int(a[3]);
incomingValues[7] =int(a[5]);
//print the values for debugging
for (int i = 0; i<8; i++) {
print(incomingValues[i]);
print(", ");
}
println();
}
//set the motors high or low, depending on if there is a touch or not
for (int i = 0; i<8; i++) {
if (incomingValues[i] - thresholds[i] > 0) {
arduino.digitalWrite(motorPins[i], Arduino.HIGH);
}
else {
arduino.digitalWrite(motorPins[i], Arduino.LOW);
}
}
}
Any suggestions on how to improve the code would be welcome. I would prefer not to change the code running on the Arduinos (there is a lot more going on, everything Arduino related is working fine, I am not 100% sure which version of the code is running on them :-/ ...)
Partly as a programming exercise, and partly becouse I believe it would be useful both for myself and others, I have decided to write a signal processing library.
Right now the idea is that you create a SignalPath for each each sensor value you receive.
If there is an incoming value, you assign it to the Path. The signal is then run through all filters specified.
At the end of the loop you close the signal path. No further filtering will occur until there is another incoming value.
A complete signal path, might look something like this:
(assuming all incoming data is stored in data[] and there is some array of SignalPathes, called accFilter
for (int i = 0; i < data.length; i++) {
accFilter[i].assign(data[i]);
}
for (int i = 0; i < accFilter.length; i++) {
accFilter[i].offset(250); //i do this, so that the range is in the positive spectrum
//accFilter[i].highpass(0.08); //i could do this, if I am only interested in motion, rather than position
accFilter[i].lowpass(0.8); //i do this to smoothen the data readings.
}
// do something here, like some fancy visualization
for (int i = 0; i < accFilter.length; i++) {
accFilter[i].closePath();
}
Ideally there should be a second type of filter which can sort of "fill in the blanks" if the incoming data comes at longer time-intervals.
So far all the filters are functions of the SignalProcessing class. However, I guess in order to use a given filter multiple times, these would actually need a class of their own. I will give that a try, but I am a bit fuzzy on how to do that at this moment.
The complete code I have now is here:
///////////////////////////////////
//Signal Processing Class /////////
///////////////////////////////////
class SignalPath
{
float inputSignal = 1; //primary input, signal to be processed
float referenceSignal = 1; //secondary input, used as baseline for detecting events etc. (optional)
I am using a custom library for some hardware prototypes and am running into an issue which I cant resolve.
One of the functions provided by the library is
getDULData(); which returns
Object[] as data-type. What I am expecting is an array of integers. However using int() gives me an error, as the int() function does not except the Object datatype.
The library comes with an example, which sadly confuses me even more, and throws an error.
it initiates the veriable "res" like this:
Integer[] res=null;
and within draw then assigns the Object[] to it
res=dul.getDULData();
When I run the code it says cannot convert Object[] to Integer[]
I would like some pointers on how to approach a problem. I intend to write an android app using processing. Its for a demo, it just needs to look nice once - I am not destributing it or anything.
Here is the part that I am not sure how to approach as of yet:
I want to place multiple icons on the display.
The number of icons is not fixed and can change depending on other parameters.
The icons need to be placed randomly (or appear to be placed randomly) and should be evenly spaced.
Now comes the tricky part:
At some point, a rectangle will enter the display, reducing the size of the area which is available for the icons.
The icons should move and dynamically rearrange in order to make up for the reduced space.
*
If anyone has some suggestions on how they would approach this, I would be very thankful. I did not find any library that does what I want, though some of the wordcloud applications come close. I sort of hope that there is some library or tutorial floating around which might help me. I didnt find anything though :-/
FATAL EXCEPTION: Thread-11 java.lang.NoSuchMethodError: processing.core.PApplet.loadImage at com.modestmaps.InteractiveMap$TileLoader.run(InteractiveMap.java:457) at java.lang.Thread.run(Thread.java:1020)
What I *think* I understand:
InteractiveMap$TileLoader is calling on a method loadImage.
loadImage should be a method within PApplet.java, however for some reason it does not exist.
Becouse of this, the program crashes.
Now, what more information can I find in this message? What do all the numbers mean? Are they referring to lines of coad?
(I know I technically am cross posting here, however with this post I am just hoping for some generall help with interpreting the error message, rather than a solution to my problem, so I hope you will tolerate this.)
When I run my code (simplified to the bare essentials) I get following error message:
FATAL EXCEPTION: Thread-13
java.lang.NoSuchMethodError: processing.core.PApplet.loadImage
at com.modestmaps.InteractiveMap$TileLoader.run(InteractiveMap.java:457)
at java.lang.Thread.run(Thread.java:1020)
This is my code, it is the code from the website, however I removed all interactions and the gui.
// // This is a test of the interactive Modest Maps library for Processing // the modestmaps.jar in the code folder of this sketch might not be // entirely up to date - you have been warned! //
// this is the only bit that's needed to show a map: InteractiveMap map;
void setup() {
// create a new map, optionally specify a provider map = new InteractiveMap(this, new Microsoft.AerialProvider()); // others would be "new Microsoft.HybridProvider()" or "new Microsoft.RoadProvider()" // the Google ones get blocked after a few hundred tiles // the Yahoo ones look terrible because they're not 256px squares :)
}
void draw() { background(0);
// draw the map: map.draw(); // (that's it! really... everything else is interactions now)
}
Does anyone have any suggestions on how to go about solving my problem?
Any help would be appreceated
Thanks
p.
EDIT:
My guess is that depending on whether its regular processing or android processing, that it refers to a different PApplet.java file. However, I have no clue whether that makes sense, or how to do anything about it, if that is the problem.
EDIT: I thought OSC didnt work on my android - realized it was a simple typo in my code which made things go whack. oscP5 seems to work perfectly with android :-)