Difference between revisions of "Trajectory from gyro/accellerometer/compas with 9DOF IMU (Michal Zemko, Peter Svitok)"
From RoboWiki
(→Zdrojový kód pre pohyb) |
(→Zdrojový kód pre pohyb) |
||
Line 29: | Line 29: | ||
== Zdrojový kód pre pohyb == | == Zdrojový kód pre pohyb == | ||
'''Pohyb do ľubovoľného smeru''' | '''Pohyb do ľubovoľného smeru''' | ||
− | + | ||
− | |||
− | |||
Line 39: | Line 37: | ||
white-space: -o-pre-wrap; | white-space: -o-pre-wrap; | ||
word-wrap: break-word;"> | word-wrap: break-word;"> | ||
− | + | ||
+ | public class project{ | ||
+ | static int[] data_old=new int[9]; | ||
+ | static int[] data_new=new int[9]; | ||
+ | ArrayList<Integer> array = new ArrayList<Integer>(); | ||
+ | int startx=400; | ||
+ | int starty=300; | ||
+ | static int counter=0; | ||
+ | |||
+ | public project() { | ||
+ | super(); | ||
+ | } | ||
+ | |||
+ | static JFrame frame = new JFrame("Points"); | ||
+ | |||
+ | public class pokus extends JPanel{ | ||
+ | public void paintComponent(Graphics g) { | ||
+ | //super.paintComponent(g); | ||
+ | |||
+ | Graphics2D g2d = (Graphics2D) g; | ||
+ | |||
+ | g2d.setColor(Color.black); | ||
+ | |||
+ | Dimension size = getSize(); | ||
+ | Insets insets = getInsets(); | ||
+ | |||
+ | int w = size.width - insets.left - insets.right; | ||
+ | int h = size.height - insets.top - insets.bottom; | ||
+ | |||
+ | Random r = new Random(); | ||
+ | |||
+ | // int x = Math.abs(r.nextInt()) % w; | ||
+ | // int y = Math.abs(r.nextInt()) % h; | ||
+ | int x = data_new[0]-data_old[0]; | ||
+ | int y = data_new[1]-data_old[1]; | ||
+ | startx+=x; | ||
+ | starty+=y; | ||
+ | x=startx; | ||
+ | y=starty; | ||
+ | int x2 = 0; | ||
+ | int y2 = 0; | ||
+ | |||
+ | if(((x>0)&&(x<800))&&((y>0)&&(y<600))){ | ||
+ | array.add(x); | ||
+ | array.add(y); | ||
+ | |||
+ | for(int i=0;i<array.size();i+=2){ | ||
+ | x=array.get(i).intValue(); | ||
+ | y=array.get(i+1).intValue(); | ||
+ | if(i>1){ | ||
+ | x2=array.get(i-2).intValue(); | ||
+ | y2=array.get(i-1).intValue(); | ||
+ | g2d.drawLine(x, y, x2, y2); | ||
+ | } | ||
+ | g2d.drawLine(x, y, x, y); | ||
+ | g2d.drawLine(x+1, y, x-1, y); | ||
+ | g2d.drawLine(x, y+1, x, y-1); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | |||
</pre> | </pre> | ||
== 3. etapa == | == 3. etapa == |
Revision as of 17:10, 28 June 2013
Zadanie
Trajectory from gyro/accellerometer/compas. Requirement: must use this part: 9DOF IMU
O súčiastke
V projekte sme mali využiť súčiastku 9DOF IMU a následne zo získaných dát vykresliť prejdenú trajektóriu robota.
Na doske 9DOF IMU sa nachádzajú nasledujúce komponenty:
Etapy
- 1. Oboznamánie sa s projektom
- 2. Naprogramovanie v Jave
- 3. Záverečné prípravy
1. etapa
V prvej etape sme dostali súčiastku a cez program Putty skúšali jej funkčnosť.
2. etapa
Zdrojový kód pre pohyb
Pohyb do ľubovoľného smeru
public class project{ static int[] data_old=new int[9]; static int[] data_new=new int[9]; ArrayList<Integer> array = new ArrayList<Integer>(); int startx=400; int starty=300; static int counter=0; public project() { super(); } static JFrame frame = new JFrame("Points"); public class pokus extends JPanel{ public void paintComponent(Graphics g) { //super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.black); Dimension size = getSize(); Insets insets = getInsets(); int w = size.width - insets.left - insets.right; int h = size.height - insets.top - insets.bottom; Random r = new Random(); // int x = Math.abs(r.nextInt()) % w; // int y = Math.abs(r.nextInt()) % h; int x = data_new[0]-data_old[0]; int y = data_new[1]-data_old[1]; startx+=x; starty+=y; x=startx; y=starty; int x2 = 0; int y2 = 0; if(((x>0)&&(x<800))&&((y>0)&&(y<600))){ array.add(x); array.add(y); for(int i=0;i<array.size();i+=2){ x=array.get(i).intValue(); y=array.get(i+1).intValue(); if(i>1){ x2=array.get(i-2).intValue(); y2=array.get(i-1).intValue(); g2d.drawLine(x, y, x2, y2); } g2d.drawLine(x, y, x, y); g2d.drawLine(x+1, y, x-1, y); g2d.drawLine(x, y+1, x, y-1); } } } }