noob trouble - constructor undefined
in
Programming Questions
•
3 years ago
Hi, I have been messing with processing for 3 days now. Very new to programming...
I am trying to work with Roborealm robotic vision software.
Here's how I hoped it works...
Processing accesses a text file that includes a string array of data in multiples of 12 numbers - each set of 12 providing data for each object identified by Roborealm - the length of this string is variable depending on how many objects the vision software identifies
At setup (), 20 'Circle' objects are created to place data in.
A Timer class creates a loop every 6400 ms.
In draw(), at the end of the timer loop, data from the file is added to the Circles objects, to then be used to create imagery and sound
Problem -
I keep getting The constructor 'Timer' is unidentified, with reference to the line in setup () , timer = new Timer(6400)
What am I doing wrong?
As far as I can tell the Timer class seems to be constructed properly?
Please help!
Here is the code
Circles [] circles;
Timer timer;
String numbers= join(loadStrings("test2.txt")," ");//loads in file and joins strings into one
int[] nums = int(split(numbers, " "));//converts string to integer array
void setup() {
size (640,480);
timer = new Timer(6400);//starts a timing loop
timer.start();
for (int i = 0; i < 20; i++) {
//initialise 20 circle objects
circles [i] = new Circles(0,0,0,0,0,0,0);
}
}
void draw() {
background();
if (timer.isfinished());//end of the timer loop
{
for (int i = 0; i < (nums[].length/12); i++){ //put data into active objects
circles[i].Xpos = nums[i*12];
circles[i].Ypos = nums[i*12+1];
circles[i].Rad = nums[i*12+2];
circles[i].Standev = nums[i*12+3];
circles[i].ColR = nums[i*12+4];
circles[i].ColG = nums[i*12+5];
circles[i].ColB = nums[i*12+6];
}
for (int i = nums[].length/12; i < 20; i++){//put zero data into inactive objects (see Circles class / deactivate
circles[i].deactivate;
}
timer.start(); //restart the timer
}
}
//define Circles class
class Circles {
int xpos;
int ypos;
int radius;
int standev; //standard deviation of circle colour;
int colourr; //mean red colour of circle
int colourg; // '' green
int colourb; // '' blue
Timer timer;
//Circles Constructor
Circles(int Xpos, int Ypos, int Rad, int Standev, int ColR, int ColG, int ColB)
{
xpos = Xpos;
ypos = Ypos;
radius = Rad;
standev = Standev;
colourr = ColR;
colourg = ColG;
colourb = ColB;
}
//void display() {
//to display imagery...
//}
//void sound() {
//to make sound...
void deactivate() {
xpos = 0;
ypos = 0;
radius = 0;
standev = 0;
colourr = 0;
colourg = 0;
colourb = 0;}
}
}
class Timer {
int savedTime; // When Timer started
int totalTime; // How long Timer should last
int passedTime;
Timer(int tempTotalTime) {
totalTime = tempTotalTime;
}
// Starting the timer
void start() {
// When the timer starts it stores the current time in milliseconds.
savedTime = millis();
}
// The function isFinished() returns true if 6,400 ms have passed.
boolean isFinished() {
// Check how much time has passed
int passedTime = millis()- savedTime;
if (passedTime > totalTime) {
return true;
} else {
return false;
}
}
int nowtime (){
return passedTime;}
}
I am trying to work with Roborealm robotic vision software.
Here's how I hoped it works...
Processing accesses a text file that includes a string array of data in multiples of 12 numbers - each set of 12 providing data for each object identified by Roborealm - the length of this string is variable depending on how many objects the vision software identifies
At setup (), 20 'Circle' objects are created to place data in.
A Timer class creates a loop every 6400 ms.
In draw(), at the end of the timer loop, data from the file is added to the Circles objects, to then be used to create imagery and sound
Problem -
I keep getting The constructor 'Timer' is unidentified, with reference to the line in setup () , timer = new Timer(6400)
What am I doing wrong?
As far as I can tell the Timer class seems to be constructed properly?
Please help!
Here is the code
Circles [] circles;
Timer timer;
String numbers= join(loadStrings("test2.txt")," ");//loads in file and joins strings into one
int[] nums = int(split(numbers, " "));//converts string to integer array
void setup() {
size (640,480);
timer = new Timer(6400);//starts a timing loop
timer.start();
for (int i = 0; i < 20; i++) {
//initialise 20 circle objects
circles [i] = new Circles(0,0,0,0,0,0,0);
}
}
void draw() {
background();
if (timer.isfinished());//end of the timer loop
{
for (int i = 0; i < (nums[].length/12); i++){ //put data into active objects
circles[i].Xpos = nums[i*12];
circles[i].Ypos = nums[i*12+1];
circles[i].Rad = nums[i*12+2];
circles[i].Standev = nums[i*12+3];
circles[i].ColR = nums[i*12+4];
circles[i].ColG = nums[i*12+5];
circles[i].ColB = nums[i*12+6];
}
for (int i = nums[].length/12; i < 20; i++){//put zero data into inactive objects (see Circles class / deactivate
circles[i].deactivate;
}
timer.start(); //restart the timer
}
}
//define Circles class
class Circles {
int xpos;
int ypos;
int radius;
int standev; //standard deviation of circle colour;
int colourr; //mean red colour of circle
int colourg; // '' green
int colourb; // '' blue
Timer timer;
//Circles Constructor
Circles(int Xpos, int Ypos, int Rad, int Standev, int ColR, int ColG, int ColB)
{
xpos = Xpos;
ypos = Ypos;
radius = Rad;
standev = Standev;
colourr = ColR;
colourg = ColG;
colourb = ColB;
}
//void display() {
//to display imagery...
//}
//void sound() {
//to make sound...
void deactivate() {
xpos = 0;
ypos = 0;
radius = 0;
standev = 0;
colourr = 0;
colourg = 0;
colourb = 0;}
}
}
class Timer {
int savedTime; // When Timer started
int totalTime; // How long Timer should last
int passedTime;
Timer(int tempTotalTime) {
totalTime = tempTotalTime;
}
// Starting the timer
void start() {
// When the timer starts it stores the current time in milliseconds.
savedTime = millis();
}
// The function isFinished() returns true if 6,400 ms have passed.
boolean isFinished() {
// Check how much time has passed
int passedTime = millis()- savedTime;
if (passedTime > totalTime) {
return true;
} else {
return false;
}
}
int nowtime (){
return passedTime;}
}
1