3 Replies - 341 Views - Last Post: 26 April 2019 - 02:57 AM Rate Topic: -----

#1 aditya_mangalampalli   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 25-April 19

Keep receiving "Error: Cannot find symbol" even if Array is pr

Posted 25 April 2019 - 04:24 PM

Hi all,
So I am trying to make a script for my robotics project where I take in a series of points, inject multiple more closely spaced points in between them, and make the points into a curve. So far, I was able to do all of the following except the end. The 2D array that had all the closely spaced points needs to be plugged into the function to return smoother points. I have the 2D array and I know it is there because I can print out the array to the console and it shows. It says the name of the 2D array is not present even though it is in another function with a return type returning the 2D array.

import java.util.ArrayList;
import java.util.Arrays;  
class Main {
  static ArrayList<double[]> coords = new ArrayList<double[]>();
 
  public static void main(String[] args) {
      // injectPoints(5, 6, 7, 5);
      pathLeft();
  } 
    private static void  pathLeft(){
      startPath();
      wayPoint(6, 4);
      wayPoint(7, 4);
      wayPoint(8, 9);
      wayPoint(10, 12);
      endPath();
    }
    
    private static void setRadius(double lookahead){
      return;}
    //Pass in coords multiple times using the same function in order to set points
    //Use points to inject the points through before smoothing
    
    private static void wayPoint(double x1, double y1){
      coords.add(new double[]{x1, y1});
      for(int i = 0; i<coords.size(); i++){
        // System.out.println(Arrays.toString(coords.get(i)));
        }
    }
  
    private static ArrayList<double[]> injectPoints(double x1, double y1, double x2, double y2) {
      double spacing = 0.25;
      double vectorAx = x2-x1;
      double vectorAy = y2-y1;  
      double vectorMag = distance_formula(x1, y1 , x2, y2);
      int num_of_point = (int) Math.ceil(vectorMag / spacing);
      double vectNormX = (vectorAx/vectorMag) * spacing;
      double vectNormY = (vectorAy/vectorMag) * spacing;
    
      ArrayList<double[]> new_points = new ArrayList<double[]>();
          for(int i = 0; i<num_of_point; i++){
             new_points.add(new double[]{x1+vectNormX*i, y1+vectNormY*i});
        }
 
      return new_points;
        }

  private static double[][] injectPointsIntoPath(){
    ArrayList<double[]> temp = new ArrayList<double[]>();
    for(int i = 0; i<coords.size()-1; i++){
      double[] start = coords.get(i); //start point of segment
      double[] end = coords.get(i+1); //end point of segment
      ArrayList<double[]> pointsForSegment = injectPoints(start[0],start[1],end[0],end[1]);
      temp.addAll(pointsForSegment);
  }  
    temp.add(coords.get(coords.size()-1)); //add last point
    coords = temp; 
    double[][] multiPointPath = new double[coords.size()][2];

    //Loop through the arraylist and transfer the data to the array
    for(int x = 0; x<coords.size(); x++){
      multiPointPath[x][0] = coords.get(x)[0]; //x coord
      multiPointPath[x][1] = coords.get(x)[1]; //y coord
  }
    System.out.println(Arrays.deepToString(multiPointPath));
    return multiPointPath;
}

  
  private double[][] smoother(double[][] path, double weight_data, double weight_smooth, double tolerance)
	{

		//copy array
		double[][] newPath = path.clone();

		double change = tolerance;
		while(change >= tolerance)
		{
			change = 0.0;
			for(int i=1; i<path.length-1; i++)
				for(int j=0; j<path[i].length; j++)
				{
					double aux = newPath[i][j];
					newPath[i][j] += weight_data * (path[i][j] - newPath[i][j]) + weight_smooth * (newPath[i-1][j] + newPath[i+1][j] - (2.0 * newPath[i][j]));
					change += Math.abs(aux - newPath[i][j]);	
				}					
		}

		return newPath;

	}
  
  private static void startPath(){
    //other init stuff
  }

  private static void endPath(){
    injectPointsIntoPath();
    //smoother(multiPointPath, 0.25, 0.75, 0.001); //a is 1-b
    
    for(int i = 0; i<coords.size(); i++){
    //System.out.println(Arrays.toString(coords.get(i)));
  }
  }

  private static void odometry(){
    double x = 0;
    double y = 0;
    double robot_angle = -180;
    int oldTickR = 00; //getCurrentPos
    int newTickR = 1120; //getCurrentPos
    int oldTickL = 00; //getCurrentPos
    int newTickL = 1120; //getCurrentPos
    double robot_radius = 9;
    robot_angle += (newTickL - newTickR) / (robot_radius * Math.PI); 
    System.out.println("The new heading is " + robot_angle);
    double distance = ((newTickL - oldTickL) + (newTickR - oldTickR)) / 2;
    System.out.println("The new distance is " + distance);
    if ((robot_angle == 90) || (robot_angle == -90)){
      x = 0;
    }

    else{
      x += distance * Math.cos(Math.toRadians(robot_angle));
    }
   
    if ((robot_angle == 180) || (robot_angle == -180)){
      y = 0;
    }

    else{
      y += distance * Math.sin(Math.toRadians(robot_angle));
    }

    System.out.println("The new x coordinate is " + x);
    System.out.println("The new y coordinate is " + y);
    
  }

  private static double distance_formula(double x1, double y1, double x2, double y2){
    double distance = Math.sqrt(Math.pow((x2-x1),2) + Math.pow((y2-y1), 2));
    return distance;
  }

  
  }
  
  




As you can see the 2D array is defined but other function to use them is not seeing it for some reason. Any help would be greatly appreciated. Thanks in advance!
Thanks,
Aditya

Is This A Good Question/Topic? 0
  • +

Replies To: Keep receiving "Error: Cannot find symbol" even if Array is pr

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5404
  • View blog
  • Posts: 14,310
  • Joined: 18-April 07

Re: Keep receiving "Error: Cannot find symbol" even if Array is pr

Posted 25 April 2019 - 04:40 PM

What line is it saying is the problem? What Array is it talking about being undefined?
Was This Post Helpful? 1
  • +
  • -

#3 aditya_mangalampalli   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 25-April 19

Re: Keep receiving "Error: Cannot find symbol" even if Array is pr

Posted 25 April 2019 - 04:48 PM

So the line which was giving the error was commented out in the above code. On line 99, it says

Main.java:99: error: cannot find symbol
    smoother(multiPointPath, 0.25, 0.75, 0.001); //a is 1-b
             ^
  symbol:   variable multiPointPath
  location: class Main
1 error
compiler exit status 1


It says that multiPointPath is undefined even if it is defined and returned in the function from lines 48 to 66.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,050
  • Joined: 12-December 12

Re: Keep receiving "Error: Cannot find symbol" even if Array is pr

Posted 26 April 2019 - 02:57 AM

It is difficult to decipher your code with the lack of consistent indenting, but you call injectPointsIntoPath(); on the line prior to the error but you do not store the value returned by this method. So multiPointPath does not exist for the following line.

(A return value also needn't have the same name unless you assign it to a variable of the same name.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1