Skip to content

Commit

Permalink
Added MrModule and fixed ImageManagementModule
Browse files Browse the repository at this point in the history
  • Loading branch information
flseaui committed Jul 26, 2018
1 parent 973ecdc commit eb8e01c
Show file tree
Hide file tree
Showing 9 changed files with 547 additions and 296 deletions.
678 changes: 418 additions & 260 deletions .idea/workspace.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/main/java/com/apw/ImageManagement/ImageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
import java.lang.invoke.LambdaMetafactory;
import java.util.Arrays;

@Deprecated
public class ImageManager {

int nrows, ncols;
private ImagePicker picker;
ImagePicker picker;
private byte mono[];
private byte simple[];
private int rgb[];

public ImageManager(FlyCamera trakcam) {
picker = new ImagePicker(trakcam, 30);
nrows = picker.getNrows();
ncols = picker.getNcols();
mono = new byte[nrows * ncols];
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/apw/apw3/DriverCons.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public abstract class DriverCons { // TrakSim constant parameters
D_StartInCalibrate = false, // T: use this to calibrate servo limits
D_Log_Draw = false, D_Log_Log = false, D_Fax_Log = false,
D_Mini_Log = false, D_NoisyMap = true,
D_DrawOnSides = true, D_DrawPredicted = true, D_DrawCurrent = true; //Drive lines.
D_DrawOnSides = true, D_DrawPredicted = true, D_DrawCurrent = true; //MrModule lines.

public static final int

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/apw/carcontrol/CarControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ public interface CarControl {
* @param angle The angle to set the car's angle to or increment it by.
*/
void steer(boolean absolute, int angle);

}
58 changes: 26 additions & 32 deletions src/main/java/com/apw/carcontrol/ImageManagementModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,18 @@
public class ImageManagementModule implements Module {

private int viewType = 1;
private int width, height;
private int ncols, nrows;
private int[] imagePixels;
private ImagePicker picker;
private byte mono[];
private byte simple[];
private int rgb[];


public ImageManagementModule(FlyCamera trakcam) {
picker = new ImagePicker(trakcam, 30);
nrows = picker.getNrows();
ncols = picker.getNcols();
public ImageManagementModule(int nrows, int ncols) {
this.nrows = nrows;
this.ncols = ncols;
mono = new byte[nrows * ncols];
simple = new byte[nrows * ncols];
rgb = new int[nrows * ncols];

}

public int getNrows() {
Expand All @@ -51,22 +46,21 @@ public void setNcols(int ncols) {
this.ncols = ncols;
}


/*Serves monochrome raster of camera feed
* Formatted in 1D array of bytes*/
public byte[] getMonochromeRaster() {
ImageManipulator.convertToMonochromeRaster(picker.getPixels(), mono, nrows, ncols);
public byte[] getMonochromeRaster(byte[] pixels) {
ImageManipulator.convertToMonochromeRaster(pixels, mono, nrows, ncols);
return mono;

}
public byte[] getMonochrome2Raster(){
ImageManipulator.convertToMonochrome2Raster(picker.getPixels(), mono, nrows, ncols);
public byte[] getMonochrome2Raster(byte[] pixels){
ImageManipulator.convertToMonochrome2Raster(pixels, mono, nrows, ncols);
return mono;
}

public byte[] getBlackWhiteRaster() {
public byte[] getBlackWhiteRaster(byte[] pixels) {

ImageManipulator.convertToBlackWhiteRaster(picker.getPixels(), mono, nrows, ncols);
ImageManipulator.convertToBlackWhiteRaster(pixels, mono, nrows, ncols);
return mono;

}
Expand All @@ -79,46 +73,46 @@ public byte[] getBlackWhiteRaster() {
* 4 = GREY
* 5 = BLACK
*/
public byte[] getSimpleColorRaster() {
public byte[] getSimpleColorRaster(byte[] pixels) {

ImageManipulator.convertToSimpleColorRaster(picker.getPixels(), simple, nrows, ncols);
ImageManipulator.convertToSimpleColorRaster(pixels, simple, nrows, ncols);
return simple;


}

public int[] getRGBRaster() {
public int[] getRGBRaster(byte[] pixels) {

ImageManipulator.convertToRGBRaster(picker.getPixels(), rgb, nrows, ncols);
ImageManipulator.convertToRGBRaster(pixels, rgb, nrows, ncols);
return rgb;

}

public int[] getSimpleRGBRaster() {
public int[] getSimpleRGBRaster(byte[] pixels) {

ImageManipulator.convertToSimpleColorRaster(picker.getPixels(), simple, nrows, ncols);
ImageManipulator.convertToSimpleColorRaster(pixels, simple, nrows, ncols);
ImageManipulator.convertSimpleToRGB(simple, rgb, simple.length);
return rgb;

}

public int[] getBWRGBRaster() {
public int[] getBWRGBRaster(byte[] pixels) {

ImageManipulator.convertToBlackWhiteRaster(picker.getPixels(), mono, nrows, ncols);
ImageManipulator.convertToBlackWhiteRaster(pixels, mono, nrows, ncols);
ImageManipulator.convertBWToRGB(mono, rgb, mono.length);
return rgb;

}

public int[] getMonoRGBRaster() {
public int[] getMonoRGBRaster(byte[] pixels) {

ImageManipulator.convertToMonochromeRaster(picker.getPixels(), mono, nrows, ncols);
ImageManipulator.convertToMonochromeRaster(pixels, mono, nrows, ncols);
ImageManipulator.convertMonotoRGB(mono, rgb, mono.length);
return rgb;

}
public int[] getMonoRGB2Raster() {
ImageManipulator.convertToMonochromeRaster(picker.getPixels(), mono, nrows, ncols);
public int[] getMonoRGB2Raster(byte[] pixels) {
ImageManipulator.convertToMonochromeRaster(pixels, mono, nrows, ncols);
ImageManipulator.convertMonotoRGB(mono, rgb, mono.length);
return rgb;
}
Expand All @@ -133,19 +127,19 @@ public void update(CarControl control) {
imagePixels = null;
switch(viewType) {
case 1:
imagePixels = getRGBRaster();
imagePixels = getRGBRaster(control.getRecentCameraImage());
break;
case 2:
imagePixels = getMonoRGBRaster();
imagePixels = getMonoRGBRaster(control.getRecentCameraImage());
break;
case 3:
imagePixels = getSimpleRGBRaster();
imagePixels = getSimpleRGBRaster(control.getRecentCameraImage());
break;
case 4:
imagePixels = getBWRGBRaster();
imagePixels = getBWRGBRaster(control.getRecentCameraImage());
break;
case 5:
imagePixels = getMonoRGB2Raster();
imagePixels = getMonoRGB2Raster(control.getRecentCameraImage());
break;
default:
throw new IllegalStateException("No image management viewType: " + viewType);
Expand Down
68 changes: 68 additions & 0 deletions src/main/java/com/apw/carcontrol/MrModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.apw.carcontrol;

import javax.swing.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class MrModule extends JFrame implements Runnable {

private ScheduledExecutorService executorService;
private ArrayList<Module> modules;
private TrakSimControl trakSimControl;
private BufferedImage displayImage;

private final int width = 1920;
private final int height = 1080;

private MrModule() {
init();
setupWindow();
createModules();
}

private void init() {
executorService = Executors.newSingleThreadScheduledExecutor();
displayImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

trakSimControl = new TrakSimControl();
modules = new ArrayList<>();
}

private void setupWindow() {
executorService.scheduleAtFixedRate(this, 0, 1000 / 60, TimeUnit.MILLISECONDS);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(width, height);
setVisible(true);
}

private void createModules() {
modules.add(new ImageManagementModule(width, height));
modules.add(new SpeedControlModule());
modules.add(new SteeringModule());
}

private void update() {
trakSimControl.readCameraImage();
for (Module module : modules)
module.update(trakSimControl);
}

private void paint() {
for (Module module : modules)
module.paint(trakSimControl, displayImage);
}

@Override
public void run() {
update();
paint();
}

public static void main(String[] args) {
new MrModule();
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/apw/carcontrol/SpeedControlModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.apw.carcontrol;

import java.awt.image.BufferedImage;

public class SpeedControlModule implements Module {
@Override
public void update(CarControl control) {

}

@Override
public void paint(CarControl control, BufferedImage image) {

}
}
15 changes: 15 additions & 0 deletions src/main/java/com/apw/carcontrol/SteeringModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.apw.carcontrol;

import java.awt.image.BufferedImage;

public class SteeringModule implements Module {
@Override
public void update(CarControl control) {

}

@Override
public void paint(CarControl control, BufferedImage image) {

}
}
2 changes: 1 addition & 1 deletion src/main/java/com/apw/carcontrol/TrakSimControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import javax.swing.JFrame;

public class TrakSimControl extends JFrame implements CarControl {
public class TrakSimControl implements CarControl {
private SimCamera cam;
private Arduino driveSys;

Expand Down

0 comments on commit eb8e01c

Please sign in to comment.