Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

https://www.dropbox.com/s/ji2mutxflpi8578/Balance.zip?dl=0 Matlab processing of

ID: 3599709 • Letter: H

Question

https://www.dropbox.com/s/ji2mutxflpi8578/Balance.zip?dl=0

Matlab processing of the balance lab data: Part 1 Write a Matlab function to calculate the center of pressure (COP) in the x and y directions from the force plate measurements Step l: Write a Matlab Function The input to your function will be six vectors corresponding to the three forces and three moments measured by the force plate. - The output of your function will be COPx and coPy, the center of pressure in the x and y directions, respectively. Therefore, the first line of your function file will look something like this. function [COPX , COPy] = calcCOP(fx, fy, fz, mz) mx , my, The equations for calculating COPx and COPy are below. Zoffset-102 mm for the AMTI Force Plate. (myTeoffset.Fx)))*(-1) (Mxt(Zoffset )) COP(x) = Step 2: Test your Matlab function by reading in one of the balance data files. data-load ( 'BalanceBalancel.txt) Extract the relevant variables from the data file Fx = data ( : , 1) ; Fy- data ( : , 2 ) ; Fz -data ( : , 3); Mx = data ( : , 4); My = data ( : , 5) ; Mz = data ( : , 6 ) ; Calculate the COPx and COPy of this data using the function your wrote in Step 1. [copx copy]=calcCOP (Fx, Fy , Fz, Mx , My, Mz): COP(y) = A good way to visualize this data is to plot the center of pressure in the y direction versus the center of pressure in the x direction. In other words, plot the (x,y) coordinates of the COP in the x-y plane for each time point. This can be done with the scatter command. scatter (copx, copy) Part 2 Determine which classmate had the best balance. You will use the function file written in Part 1. You will write a script file to process all 32 balance datasets. The script file should perform the following steps.

Explanation / Answer

package assignment5_sharewithstudents;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Random;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.JFrame;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.border.EtchedBorder;

class GlobalVariables {
    public ArrayList<Fish> mFish;
    public FishTank mFishTank;

    private GlobalVariables() {
        mFish = new ArrayList<Fish>();
        mFishTank = new FishTank();
    }

    private static GlobalVariables instance;

    public static GlobalVariables getInstance() {
        if (instance == null){
            instance = new GlobalVariables();
        }
        return instance;
    }
}

class Fish implements Comparable<Fish>{
  
    int mX;
    int mY;
    int mId;
    Color mColor;
  
    public Fish(int id, int x, int y, Color color){
      
        mId = id;
        mX = x;
        mY = y;
        mColor = color;
    }
  
    public void paint(Graphics g){
      
        // Implement this function

    }
  
    public void move(){
       
        // Implement this function
      
    }

    @Override
    public int compareTo(Fish o) {
      
        // Implement this function

    }
}

class FishTick extends TimerTask{

    @Override
    public void run() {
   
        if (FishTank.mSimulateStatus){
          
            for (int x=0;x<GlobalVariables.getInstance().mFish.size();x++){
              
                Fish f = GlobalVariables.getInstance().mFish.get(x);
                f.move();
                GlobalVariables.getInstance().mFish.set(x, f);
            }
            
            GlobalVariables.getInstance().mFishTank.mDrawPanel.paint();
        }
    }
}

public class FishTank extends javax.swing.JFrame implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener{
  
    private final int mNumRows = 20;
    private final int mNumCols = 20;
    private final int mGridSz = 30;
  
    private int mSelectedFishIndex = -1;
    private boolean mDragged = false;
  
    private int mTopHeight;
         
    JToolBar mToolbar;
    JToggleButton mSimulationButton;
    DrawPanel mDrawPanel;
  
    private int mFishIndex = 0;
  
    static public boolean mSimulateStatus = false;
  
    public static void main(String[] args) {

        GlobalVariables global = GlobalVariables.getInstance();
      
        if (global == null){
            System.out.println("Cannot initialize, exiting ....");
            return;
        }
      
    }

    private JToggleButton addButton(String title){
      
        JToggleButton button = new JToggleButton(title);
        button.addItemListener(new ItemListener() {
           public void itemStateChanged(ItemEvent ev) {
               mSimulateStatus = !mSimulateStatus;
           }
        });
      
        this.mToolbar.add(button);
      
        return (button);
    }
  
    public FishTank()
    {
        JFrame guiFrame = new JFrame();

        guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        guiFrame.setTitle("MY FISH TANK");
      
        // Create a toolbar and give it an etched border.
        this.mToolbar = new JToolBar();
        this.mToolbar.setBorder(new EtchedBorder());
      
        mSimulationButton = addButton("Simulate");
        this.mToolbar.add(mSimulationButton);

        //This will center the JFrame in the middle of the screen
        guiFrame.setLocationRelativeTo(null);
  
        this.mDrawPanel = new DrawPanel(mNumRows, mNumCols, mGridSz);
      
        this.mDrawPanel.setBackground(Color.cyan);
        this.mDrawPanel.paint();
      
        guiFrame.add(mDrawPanel);
        guiFrame.add(this.mToolbar, BorderLayout.NORTH);
      
        // Add the Exit Action
        JButton button = new JButton("Quit");
        button.setToolTipText("Quit the program");
        button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
        });
        mToolbar.add(button);
    
        guiFrame.addMouseListener(this);
        guiFrame.addMouseMotionListener(this);
      
        //make sure the JFrame is visible
        guiFrame.setVisible(true);
      
        mTopHeight = guiFrame.getInsets().top + mToolbar.getHeight();
        guiFrame.setSize(mNumRows * mGridSz, mNumCols * mGridSz + mTopHeight);
      
        Timer timer = new Timer("tick", true);
        timer.scheduleAtFixedRate(new FishTick(), Calendar.getInstance().get(Calendar.MILLISECOND), 500);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
      
        // Implement this function
    }

    @Override
    public void mousePressed(MouseEvent e) {
    }

    @Override
    public void mouseReleased(MouseEvent e) {
      
        // Implement this function
    }

    @Override
    public void mouseEntered(MouseEvent e) {
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }

    @Override
    public void mouseDragged(MouseEvent e) {
      
        // Implement this function
    }

    @Override
    public void mouseMoved(MouseEvent e) {
    }
}

class DrawPanel extends JPanel{

    int mRows;
    int mCols;
    int mGridSz;
    int maxGridSz;
  
    ArrayList<Fish> mFish;
  
    public DrawPanel(int numberOfRows, int numberOfCols, int gridSz){
      
        mGridSz = gridSz;
        mRows = numberOfRows;
        mCols = numberOfCols;
        maxGridSz = mGridSz * mRows;
    }
  
    private void paintBackground(Graphics g){
      
        for (int i = 1; i < mRows; i++) {
            g.drawLine(i * mGridSz, 0, i * mGridSz, maxGridSz);
        }
      
        for (int mAnimateStatus = 1; mAnimateStatus < mCols; mAnimateStatus++) {
            g.drawLine(0, mAnimateStatus * mGridSz, maxGridSz, mAnimateStatus * mGridSz);
        }
    }
  
    @Override
    public void paintComponent(Graphics g){
      
        super.paintComponent(g);
      
        paintBackground(g);
      
        for (Fish f:GlobalVariables.getInstance().mFish){
            f.paint(g);
        }
      
    }

    public void paint(){
        repaint();
    }

}