Skip to content

Commit 560b98e

Browse files
committed
Merge pull request #6 from NeuronRobotics/development
Release for Make Faire NYC
2 parents 93da888 + 835ee78 commit 560b98e

File tree

87 files changed

+4867
-1980
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+4867
-1980
lines changed

javasdk/NRSDK/addons/com/neuronrobotics/addons/driving/AbstractRobotDrive.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public void stopRobot(){
5555
DriveStraight(0,0);
5656
}
5757

58+
public RobotLocationData getRobotLocation(){
59+
return new RobotLocationData(getCurrentX(), getCurrentY(), getCurrentOrentation());
60+
}
61+
5862
public void setCurrentX(double currentX) {
5963
//System.out.println("Current X is: "+currentX);
6064
this.currentX = currentX;

javasdk/NRSDK/addons/com/neuronrobotics/addons/driving/AckermanBot.java

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.neuronrobotics.addons.driving;
22

33
import com.neuronrobotics.sdk.addons.kinematics.ServoRotoryLink;
4+
import com.neuronrobotics.sdk.common.Log;
5+
import com.neuronrobotics.sdk.dyio.peripherals.DigitalOutputChannel;
46
import com.neuronrobotics.sdk.pid.PIDChannel;
57
import com.neuronrobotics.sdk.pid.PIDCommandException;
68
import com.neuronrobotics.sdk.pid.PIDEvent;
@@ -15,7 +17,17 @@ public class AckermanBot extends AbstractRobotDrive {
1517
protected double steeringAngle=0;
1618
ServoRotoryLink steering;
1719
PIDChannel drive;
20+
PIDChannel lSteer;
21+
PIDChannel rSteer;
22+
PIDChannel bSteer;
23+
24+
boolean complexSteering=false;
25+
1826
private IAckermanBotKinematics ak = new AckermanDefaultKinematics();
27+
private DigitalOutputChannel driveEnable;
28+
private DigitalOutputChannel driveDirection;
29+
private double scale = 360.0/4096.0;
30+
private int currentEncoderReading;
1931

2032
protected AckermanBot(){
2133

@@ -26,14 +38,38 @@ public AckermanBot(ServoRotoryLink s,PIDChannel d) {
2638
steering=s;
2739
}
2840

41+
public AckermanBot( PIDChannel drive,
42+
PIDChannel lSteer,
43+
PIDChannel rSteer,
44+
PIDChannel bSteer,
45+
DigitalOutputChannel driveEnable,
46+
DigitalOutputChannel driveDirection) {
47+
this.driveEnable = driveEnable;
48+
this.driveDirection = driveDirection;
49+
setPIDChanel(drive);
50+
51+
this.lSteer=lSteer;
52+
this.rSteer=rSteer;
53+
this.bSteer=bSteer;
54+
complexSteering=true;
55+
SetDriveVelocity(0);
56+
}
57+
2958
protected void setPIDChanel(PIDChannel d){
3059
drive=d;
3160
drive.addPIDEventListener(this);
3261
}
3362

3463
public void setSteeringHardwareAngle(double s) {
35-
steering.setTargetAngle(s);
36-
steering.flush(0);
64+
if(complexSteering==false){
65+
steering.setTargetAngle(s);
66+
steering.flush(0);
67+
68+
}else{
69+
this.lSteer.SetPIDSetPoint((int) (s/scale), 0);
70+
this.rSteer.SetPIDSetPoint((int) (s/scale), 0);
71+
this.bSteer.SetPIDSetPoint(0, 0);
72+
}
3773
}
3874

3975
public void setSteeringAngle(double s) {
@@ -58,16 +94,23 @@ public double getSteeringAngle() {
5894
return steeringAngle;
5995
}
6096
protected void SetDriveDistance(int ticks, double seconds){
61-
System.out.println("Seting PID set point of="+ticks);
62-
drive.SetPIDSetPoint(ticks, seconds);
97+
Log.debug("Seting PID set point of= "+ticks+" currently at "+currentEncoderReading);
98+
//drive.SetPIDSetPoint(ticks, seconds);
99+
driveDirection.setHigh(ticks< currentEncoderReading);
100+
driveEnable.setHigh(false);
101+
ThreadUtil.wait((int) (seconds*1000));
102+
driveEnable.setHigh(true);
103+
Log.debug("Arrived at= "+currentEncoderReading);
63104
}
64105
protected void SetDriveVelocity(int ticksPerSecond){
65-
System.out.println("Seting PID Velocity set point of="+ticksPerSecond);
66-
try {
67-
drive.SetPDVelocity(ticksPerSecond, 0);
68-
} catch (PIDCommandException e) {
69-
e.printStackTrace();
106+
Log.debug("Seting PID Velocity set point of="+ticksPerSecond);
107+
if(ticksPerSecond>0){
108+
driveDirection.setHigh(ticksPerSecond> 0);
109+
driveEnable.setHigh(false);
110+
}else{
111+
driveEnable.setHigh(true);
70112
}
113+
71114
}
72115
protected void ResetDrivePosition(){
73116
//Log.enableDebugPrint(true);
@@ -101,6 +144,7 @@ public double getMaxTicksPerSecond() {
101144

102145
@Override
103146
public void onPIDEvent(PIDEvent e) {
147+
currentEncoderReading = e.getValue();
104148
setRobotLocationUpdate(ak.onPIDEvent(e,getSteeringAngle()));
105149
}
106150

javasdk/NRSDK/addons/com/neuronrobotics/addons/driving/AckermanConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
public class AckermanConfiguration {
44

5-
private double ticksPerRevolution = 128;//ticks
6-
private double wheelDiameter = 2.54;//cm
5+
private double ticksPerRevolution = 4096;//ticks
6+
private double wheelDiameter = 8.0*2.54;//cm
77
private double cmPerRevolution = 2*Math.PI*wheelDiameter;
88
private double ticksToCm = ticksPerRevolution/cmPerRevolution;
99

1010
private double maxTicksPerSeconds = 200;
11-
private double wheelbase = 14.2;//cm
11+
private double wheelbase = 16.5*2.54;//cm
1212
private double servoToSteerAngle=1;
1313

1414
public void setMaxTicksPerSeconds(double maxTicksPerSeconds) {

javasdk/NRSDK/addons/com/neuronrobotics/addons/driving/NrMap.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ public class NrMap extends JPanel{
1818
*/
1919
private static final long serialVersionUID = -1487461776000494761L;
2020

21-
private double pixelToCm=10;
21+
private double pixelToCm=100;
2222
JLabel lab=new JLabel();
2323
private BufferedImage display;
2424

2525
private ArrayList<userDefinedObsticles> obs = new ArrayList<userDefinedObsticles>();
2626

27-
protected static final double width = 600;
28-
protected static final double height = 480;
27+
protected static final double width = 1024;
28+
protected static final double height = 1024;
2929

3030
/**
3131
* Instantiate a robot map using a default blank map.
@@ -65,7 +65,7 @@ protected void setDisplay(BufferedImage d){
6565

6666
public BufferedImage getMap() {
6767
if(display==null){
68-
return new BufferedImage(600, 480,BufferedImage.TYPE_INT_RGB);
68+
return new BufferedImage((int)width,(int) height,BufferedImage.TYPE_INT_RGB);
6969
}
7070
BufferedImage d = new BufferedImage(display.getWidth(), display.getHeight(),BufferedImage.TYPE_INT_RGB);
7171
Graphics2D g =d.createGraphics();
@@ -79,11 +79,11 @@ public BufferedImage getMap() {
7979
public void removeAllUserDefinedObsticles(){
8080
obs.clear();
8181
}
82-
public void addUserDefinedObsticle(int x, int y, int size){
82+
public void addUserDefinedObsticle(int x, int y, int size,ObsticleType type){
8383
if(display==null){
84-
display = new BufferedImage(600, 480,BufferedImage.TYPE_INT_RGB);
84+
display = new BufferedImage((int)width,(int) height,BufferedImage.TYPE_INT_RGB);
8585
}
86-
obs.add(new userDefinedObsticles(x,y,size));
86+
obs.add(new userDefinedObsticles(x,y,size,type));
8787

8888
}
8989

@@ -99,14 +99,16 @@ public double getCmToPixel(double cm){
9999
}
100100

101101
private class userDefinedObsticles{
102-
public userDefinedObsticles(int x2, int y2, int size2) {
102+
ObsticleType type;
103+
public userDefinedObsticles(int x2, int y2, int size2,ObsticleType type) {
104+
this.type = type;
103105
setX(x2);
104106
setY(y2);
105107
setSize(size2);
106108
}
107109

108110
public void drawUserObsticles(Graphics2D g) {
109-
g.setColor(Color.pink);
111+
g.setColor(type.getValue());
110112
g.fillRect(getX()-(getSize()/2),getY()-(getSize()/2), getSize(),getSize());
111113
}
112114

@@ -138,5 +140,21 @@ public int getSize() {
138140
private int y;
139141
private int size;
140142
}
143+
public void setUserDefinedData(ArrayList<DataPoint> data,ObsticleType type) {
144+
//removeAllUserDefinedObsticles();
145+
for(DataPoint d:data){
146+
double pix = getCmToPixel(d.getRange()/100);
147+
double centerX=(width/2);
148+
double centerY=(height/2);
149+
if(!(pix>centerX || pix>centerY )){
150+
double deltX = pix*Math.cos(Math.toRadians(d.getAngle()));
151+
double deltY = pix*Math.sin(Math.toRadians(d.getAngle()));
152+
addUserDefinedObsticle((int)(centerX+deltX), (int)(centerY+deltY), 2,type);
153+
}else{
154+
//System.out.println("Range too long: "+pix+" cm="+d.getRange()/100);
155+
}
156+
}
157+
updateMap();
158+
}
141159

142160
}

javasdk/NRSDK/addons/com/neuronrobotics/addons/driving/Rbe3002Robot.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,15 @@ public Rbe3002Robot() {
2424
DyIOChannelMode.COUNT_IN_INT,//Input mode
2525
10,//Output Channel
2626
DyIOChannelMode.SERVO_OUT);//Output mode
27-
PIDConfiguration lpid =new PIDConfiguration ( 1,//PID group
28-
true,//enabled
29-
false,//inverted
30-
true,//Async
31-
KP,// Kp
32-
KI,// Ki
33-
KD,//Kd
34-
0,//latch
35-
false,//use latch
36-
false);//stop on latch
27+
PIDConfiguration lpid =new PIDConfiguration ();//stop on latch
3728

3829

3930
DyPIDConfiguration rdypid = new DyPIDConfiguration( 2,//PID group 2
4031
19,//Input channel number
4132
DyIOChannelMode.COUNT_IN_INT,//Input mode
4233
11,//Output Channel
4334
DyIOChannelMode.SERVO_OUT);//Output mode
44-
PIDConfiguration rpid =new PIDConfiguration ( 2,//PID group
45-
true,//enabled
46-
true,//inverted
47-
true,//Async
48-
KP,// Kp
49-
KI,// Ki
50-
KD,//Kd
51-
0,//latch
52-
false,//use latch
53-
false);//stop on latch
35+
PIDConfiguration rpid =new PIDConfiguration ();
5436
dyio.ConfigureDynamicPIDChannels(ldypid);
5537
dyio.ConfigurePIDController(lpid);
5638
dyio.ConfigureDynamicPIDChannels(rdypid);

javasdk/NRSDK/addons/com/neuronrobotics/addons/driving/RobotLocationData.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
package com.neuronrobotics.addons.driving;
2+
3+
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;
4+
25
/**
36
* This class represents the Delta position of the robot in the robots co-ordinate system.
47
* Only the delta y, delta x and delta orentation relative to the robots current position
@@ -9,11 +12,21 @@
912

1013
public class RobotLocationData {
1114
private double x,y,o;
15+
private TransformNR arm = new TransformNR();
1216
public RobotLocationData(double deltaX, double deltaY, double deltaOrentation){
1317
setX(deltaX);
1418
setY(deltaY);
1519
setO(deltaOrentation);
1620
}
21+
22+
public void setArmLocation(TransformNR arm){
23+
this.arm = arm;
24+
25+
}
26+
public TransformNR getArmTransform(){
27+
return arm;
28+
}
29+
1730
public String toString() {
1831
String s="delta: x="+x+" y="+y+" orentation="+o;
1932
return s;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.neuronrobotics.addons.driving;
2+
3+
import java.awt.Color;
4+
import java.awt.color.CMMException;
5+
import java.util.ArrayList;
6+
7+
import javax.swing.JFrame;
8+
9+
import com.neuronrobotics.addons.driving.virtual.ObsticleType;
10+
import com.neuronrobotics.sdk.ui.ConnectionImageIconFactory;
11+
12+
public class SimpleDisplay extends NrMap {
13+
14+
/**
15+
*
16+
*/
17+
private static final long serialVersionUID = -7042174918507023465L;
18+
private JFrame frame = new JFrame();
19+
public SimpleDisplay(){
20+
getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
21+
setBackground(Color.black);
22+
getFrame().add(this);
23+
getFrame().setSize((int)width+200,(int)height+200);
24+
getFrame().setLocationRelativeTo(null);
25+
getFrame().setVisible(true);
26+
getFrame().setIconImage( ConnectionImageIconFactory.getIcon("images/hat.png").getImage());
27+
28+
}
29+
public JFrame getFrame() {
30+
return frame;
31+
}
32+
public void setFrame(JFrame frame) {
33+
this.frame = frame;
34+
}
35+
public void setData(ArrayList<DataPoint> data) {
36+
//removeAllUserDefinedObsticles();
37+
for(DataPoint d:data){
38+
double pix = getCmToPixel(d.getRange()/100);
39+
double centerX=(width/2);
40+
double centerY=(height/2);
41+
if(!(pix>centerX || pix>centerY )){
42+
double deltX = pix*Math.cos(Math.toRadians(d.getAngle()));
43+
double deltY = pix*Math.sin(Math.toRadians(d.getAngle()));
44+
addUserDefinedObsticle((int)(centerX+deltX), (int)(centerY+deltY), 2,ObsticleType.USERDEFINED);
45+
}else{
46+
//System.out.println("Range too long: "+pix+" cm="+d.getRange()/100);
47+
}
48+
}
49+
updateMap();
50+
}
51+
}

javasdk/NRSDK/addons/com/neuronrobotics/addons/driving/virtual/ObsticleType.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ public enum ObsticleType {
1111

1212
WALL(Color.blue),
1313

14-
FIRE(Color.orange),
14+
FIRE(Color.magenta),
1515

16-
USERDEFINED(Color.pink),
16+
PINKBALL(Color.pink),
17+
HOCKYPUCK(Color.red),
18+
HOOKSAMPLE(Color.white),
19+
ORANGEROD(Color.orange),
20+
BASESTATION(Color.yellow),
1721

18-
NONE(Color.white);
22+
USERDEFINED(Color.green),
23+
24+
NONE(Color.lightGray);
1925

2026
/** The Constant lookup. */
2127
private static final Map<Color,ObsticleType > lookup = new HashMap<Color,ObsticleType >();

javasdk/NRSDK/addons/com/neuronrobotics/sdk/addons/kinematics/gui/DHViewer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class DHViewer extends SimpleTransformViewer{
3636
private static final long serialVersionUID = -7066991305201979906L;
3737

3838
public DHViewer (DHChain tk,double[] jointSpaceVector){
39+
3940
ArrayList<TransformNR> chain = tk.getChain(jointSpaceVector);
4041
int i=0;
4142
for(TransformNR t:chain){

javasdk/NRSDK/addons/com/neuronrobotics/sdk/addons/kinematics/gui/MatrixDisplayNR.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ public MatrixDisplayNR(String name){
3535
// int vColIndex = 0;
3636
// TableColumn col = getTable().getColumnModel().getColumn(vColIndex);
3737
// int width = 40;
38-
// col.setPreferredWidth(width);
39-
getTable().getColumnModel().getColumn(0).setPreferredWidth(56);
40-
getTable().getColumnModel().getColumn(1).setPreferredWidth(56);
41-
getTable().getColumnModel().getColumn(2).setPreferredWidth(56);
42-
getTable().getColumnModel().getColumn(3).setPreferredWidth(56);
38+
// col.setPreferredWidth(width);
39+
int colWidth = 66;
40+
getTable().getColumnModel().getColumn(0).setPreferredWidth(colWidth);
41+
getTable().getColumnModel().getColumn(1).setPreferredWidth(colWidth);
42+
getTable().getColumnModel().getColumn(2).setPreferredWidth(colWidth);
43+
getTable().getColumnModel().getColumn(3).setPreferredWidth(colWidth);
4344

4445
add(getTable(),"wrap");
4546
setEditable(false);

0 commit comments

Comments
 (0)