#In search of guidance for project

1 messages · Page 1 of 1 (latest)

frosty crypt
#

Goal of this project is to use various csv files (accelerometer, change of orientation, and gyroscope) to plot points and display some sort of a map. these files are obtained from a smartphone. my current code is as follows:

buoyant ventureBOT
#

This post has been reserved for your question.

Hey @frosty crypt! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

frosty crypt
#
        Graphics g = jPanel1.getGraphics();
        Graphics2D g2d = (Graphics2D) g;
        String path1 = "C:\\Users\\dmanp\\OneDrive\\Desktop\\Accelerometer.csv";
        String path2 = "C:\\Users\\dmanp\\OneDrive\\Desktop\\Orientation.csv";
        String path3 = "C:\\Users\\dmanp\\OneDrive\\Desktop\\Gyroscope.csv";
        String line0 = "";
        String line1 = "";
        String line2 = "";
        
        try {
            double finalVelocity = 0;
            double initialVelocity = 0;
            double oldDist = 0;
            double newDist = 0;
            double x = 1;
            double y = 1;
            BufferedReader[] b1 = new BufferedReader[3];
            b1[0] = new BufferedReader(new FileReader(path1));
            b1[1] = new BufferedReader(new FileReader(path2));
            b1[2] = new BufferedReader(new FileReader(path3));
             while(((line0 = b1[0].readLine()) != null) & ((line1 = b1[1].readLine()) != null) & ((line2 = b1[2].readLine()) != null)){
                
              //  g.drawLine(x,y,x,y)
              //  g2d.drawLine(x,y,x,y);
                //g2d.draw(new Line2D.Double(x,y,x,y));
                 g2d.draw(new Line2D.Double(x, y, x, y));
                String[] accelerometer = line0.split(",");
                String[] orientation = line1.split(",");
                String[] gyroscope = line2.split(",");
                double timeElapsedAccelerometer = Double.parseDouble(accelerometer[1]);
                double timeElapsedOrientation = Double.parseDouble(orientation[1]);
                double timeElapsedGyroscope = Double.parseDouble(gyroscope[1]);
                
                if(timeElapsedAccelerometer == timeElapsedOrientation & timeElapsedAccelerometer == timeElapsedGyroscope) {
#
                    double acceleration = Double.parseDouble(accelerometer[3]);
                    
                    initialVelocity = newDist - (((1/2)*(acceleration)*(Math.pow(timeElapsed, 2))) * (1 / timeElapsed));
                    newDist = (initialVelocity) * timeElapsed + (acceleration / 2) * (Math.pow(timeElapsed, 2));
                    double angle = Math.toRadians(90 - Double.parseDouble(orientation[4]));
                    double changeX = Math.cos(angle) * newDist;
                    double changeY = Math.sin(angle) * newDist;
                    x += changeX;
                    y += changeY;
                    
                    g2d.drawLine((int) (x * 1000), (int) (y * 1000), (int) (x * 1000), (int) (y * 1000)); 
                    
                
                }

            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
        }catch (IOException ex) {
            Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
       
        
    }
#

this is inside of a jFrame with a jPanel, also note that i need common time values with their relative(same line) values (like acceleration from accelerometer) to use in the calculations for the new x and y values

fiery marlin
frosty crypt
#

no the files are from a recording from a smartphone

fiery marlin
#

the method name is not very descriptive. When should that method be called ?

frosty crypt
#

the method findValue?

fiery marlin
#

the method jPanel1MouseClicked

frosty crypt
#

ill be honest i do not know, i got that part from a tutorial on how to draw lines using java, this is all inside a Jframe ( the way i learned how to draw lines/plot points)

fiery marlin
#

but when should that method be triggered. What is the user trying to do when this method is executed. Is he just clicking anywhere on screen or is he trying to focus a specific data point ?

frosty crypt
fiery marlin
#

but the pop window will display the points

frosty crypt
#

it doesnt until the user clicks

fiery marlin
#

In any case I would do the calculation at an earlier stage when the user opens the popup. Then just store the calculated points in an ArrayList and draw them when the user clicks on the screen.
The drawing should happen in the method paintComponent

frosty crypt
#

So i should just use a normal java application? not a jFrame?

fiery marlin
#

you should use a JFrame and a JPanel but follow the lesson I linked below and do the loading at an earlier point or asynchronously.

#

you are currently doing all your calculations on the EDT (Event Dispatch Thread) when this thread gets blocked the gui freezes

#

and the points won't show up since they are only get drawn once. In the next paint cycle they are not drawn again.

frosty crypt
#

ah ok

#

then for the file-line matching, do you have any tips for that?

fiery marlin
#

I would use a try-with-resources but you need the three buffered readers so the general structure looks ok.

frosty crypt
buoyant ventureBOT
# frosty crypt thanks i appreciate the help will note

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.