Thanks … That’s all my code
class Robot {
float diameter;
float distance;
int index = 1; //index for number of outputs
int condition; //if (Nl == Nr or Nl = -Nr) = 0;
float [] velocityLeft = {1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0, -0.1, -0.2, -0.3, -0.4, -0.5, -0.6, -0.7, -0.8, -0.9, -1.0};
float [] velocityRight = {1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0, -0.1, -0.2, -0.3, -0.4, -0.5, -0.6, -0.7, -0.8, -0.9, -1.0};
Table results = new Table();
results.addColumn("Diameter");
results.addColumn("Left Speed");
results.addColumn("Right Speed");
float Nl; //Right wheel velocity
float Nr; //Left wheel velocity
float theta = radians(0); //Angle with -x-axis
float firstLocationX;
float firstLocationY;
float radius = 3; //DDMR wheel radius
float L = 6; //Distance between two wheels
float vx;
float vy;
PVector velocity = new PVector(vx, vy); //linear velocity
PVector location; //DDMR current location
float omega; //Angular velocity
float initialX;
float initialY;
Robot (){
initialX = 300;
initialY = 300;
location = new PVector (initialX, initialY); // Initialize the location.
}
void display(){
for (int iterationLeft = 0; iterationLeft < velocityLeft.length; iterationLeft ++)
{
for (int iterationRight = 0; iterationRight < velocityRight.length; iterationRight ++)
{
TableRow newRow = results.addRow();
condition = 1;
diameter = 0;
distance = 0;
Nl = velocityLeft[iterationLeft];
Nr = velocityRight[iterationRight];
omega = radians((radius/(2*L))*(Nl-Nr));
firstLocationX = location.x;
firstLocationY = location.y;
if (Nl == Nr)
{
newRow.setFloat("Diameter", 99999);
newRow.setFloat("Left Speed", Nl);
newRow.setFloat("Right Speed", Nr);
condition = 0;
index ++;
} else if (Nl + Nr == 0)
{
newRow.setFloat("Diameter", 0);
newRow.setFloat("Left Speed", Nl);
newRow.setFloat("Right Speed", Nr);
condition = 0;
index ++;
}
while (condition == 1)
{
//new location
location.add(velocity);
//Calculate velocity
velocity.x = (radius/2)*cos(theta)*(Nr + Nl);
velocity.y = (radius/2)*sin(theta)*(Nr + Nl);
//new angle
theta = theta + omega;
distance = dist(firstLocationX, firstLocationY, location.x, location.y);
print("Diameter = " + diameter + " -- " + "Distance = " + distance + "\n");
if (diameter < distance)
{
diameter = distance;
}//end of (if) statement
if (diameter > distance)
{
newRow.setFloat("Diameter", diameter);
newRow.setFloat("Left Speed", Nl);
newRow.setFloat("Right Speed", Nr);
saveTable(results, "data/new.csv");
//print(index + " : Diameter= " + diameter + " - Left Speed = " + Nl + " - Right Speed = " + Nr + "\n");
condition = 0;
index++;
velocity.x = 0;
velocity.y = 0;
}//end of (if) Statement
}//end of (While) Loop
}//end (for) iterationRight loop
}//end (for) iterationLeft loop
}//end void Display()
}//end class Robot