Skip to content

Commit

Permalink
1.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed May 26, 2020
1 parent a84f152 commit 52b4aee
Show file tree
Hide file tree
Showing 17 changed files with 271 additions and 121 deletions.
2 changes: 1 addition & 1 deletion arduino/sixi-pid2/clock.cpp
Expand Up @@ -34,7 +34,7 @@ void clockSetup() {

CLOCK_ADJUST(interval);

if(true) {
if(false) {
Serial.print(F("Hz=")); Serial.println(CLOCK_MAX_ISR_FREQUENCY);
Serial.print(F("interval=")); Serial.println(interval);
Serial.print(F("multiplier=")); Serial.println(isr_step_multiplier);
Expand Down
16 changes: 6 additions & 10 deletions arduino/sixi-pid2/eeprom.cpp
Expand Up @@ -185,22 +185,18 @@ void Eeprom::savePID() {
int j=ADDR_PID;

for(ALL_MOTORS(i)) {
writeFloat(j,motors[i].kp);
j+=4;
writeFloat(j,motors[i].ki);
j+=4;
writeFloat(j,motors[i].kd);
j+=4;
writeFloat(j,motors[i].kp); j+=4;
writeFloat(j,motors[i].ki); j+=4;
writeFloat(j,motors[i].kd); j+=4;
}
}

void Eeprom::loadPID() {
int j=ADDR_PID;
for(ALL_MOTORS(i)) {

motors[i].kp = readFloat(j);
motors[i].ki = readFloat(j+4);
motors[i].kd = readFloat(j+8);
j+=12;
motors[i].kp = readFloat(j); j+=4;
motors[i].ki = readFloat(j); j+=4;
motors[i].kd = readFloat(j); j+=4;
}
}
5 changes: 5 additions & 0 deletions arduino/sixi-pid2/motors.cpp
Expand Up @@ -19,10 +19,15 @@ int stepsCount = 0;

void StepperMotor::report() {
Serial.println(letter);
Serial.print("\tpid="); Serial.print(kp);
Serial.print(", "); Serial.print(ki);
Serial.print(", "); Serial.println(kd);
/*
Serial.print("\tstepsTarget="); Serial.println(stepsTarget);
Serial.print("\tstepsNow="); Serial.println(stepsNow);
Serial.print("\terror="); Serial.println(error);
Serial.print("\tangleTarget="); Serial.println(angleTarget);
//*/
}


Expand Down
30 changes: 16 additions & 14 deletions arduino/sixi-pid2/parser.cpp
Expand Up @@ -142,6 +142,7 @@ void Parser::update() {

if(sofar==51 && c=='E') {
// message received
Serial.print("REC ");

// echo confirmation
if(MUST_ECHO) Serial.println(serialBuffer);
Expand Down Expand Up @@ -187,26 +188,27 @@ void Parser::update() {
//Serial.println( RELATIVE_MOVES ? "REL" : "ABS" );

CRITICAL_SECTION_START();
for (ALL_MOTORS(i)) {/*
Serial.println(motors[i].letter);
Serial.println(motors[i].velocity);
Serial.println(angles[i]);
Serial.println(motors[i].letter);
Serial.print("\tangleTarget0=");
Serial.println(motors[i].angleTarget);
Serial.print("\tstepsTarget0=");
Serial.println(motors[i].stepsTarget);
Serial.print("\tangleTarget1=");
for (ALL_MOTORS(i)) {
Serial.print(motors[i].letter);
Serial.print(motors[i].velocity);
Serial.print(' ');/*
Serial.println(angles[i]);
Serial.print("\tstepsTarget1=");
Serial.println(steps[i]);
Serial.print("\tstepsNow=");
Serial.println(motors[i].stepsNow);
Serial.print("\tangleTarget0="); Serial.println(motors[i].angleTarget);
Serial.print("\tstepsTarget0="); Serial.println(motors[i].stepsTarget);
Serial.print("\tangleTarget1="); Serial.println(angles[i]);
Serial.print("\tstepsTarget1="); Serial.println(steps[i]);
Serial.print("\tstepsNow="); Serial.println(motors[i].stepsNow);
//*/
motors[i].angleTarget = angles[i];
motors[i].stepsTarget = steps[i];
}
Serial.println();
CRITICAL_SECTION_END();
} else {
Serial.print("CHECK BAD ");
Serial.print(checksum,HEX);
Serial.print("/");
Serial.println(serialBuffer[49]);
}
ready();
} else if(sofar>51) {
Expand Down
2 changes: 1 addition & 1 deletion arduino/sixi-pid2/sensors.cpp
Expand Up @@ -84,7 +84,7 @@ void SensorManager::setup() {
}

positionErrorFlags = 0;
//SET_BIT_ON(positionErrorFlags,POSITION_ERROR_FLAG_CONTINUOUS);// | POSITION_ERROR_FLAG_ESTOP;
SET_BIT_ON(positionErrorFlags,POSITION_ERROR_FLAG_CONTINUOUS);// | POSITION_ERROR_FLAG_ESTOP;

// the first few reads will return junk so we force a couple empties here.
update();
Expand Down
13 changes: 10 additions & 3 deletions arduino/sixi-pid2/sixi-pid2.ino
Expand Up @@ -12,11 +12,11 @@ uint8_t debugFlags;

void reportAllMotors() {
for(ALL_MOTORS(i)) {
motors[i].report();
motors[i].report();/*
Serial.print("\tsensorHome=");
Serial.println(sensorManager.sensors[i].angleHome);
Serial.print("\tsensor=");
Serial.println(sensorManager.sensors[i].angle);
Serial.println(sensorManager.sensors[i].angle);//*/
}
Serial.println();
}
Expand All @@ -39,7 +39,14 @@ void setup() {
// make sure the starting target is the starting position (no move)
parser.D18();

//reportAllMotors();
motors[0].setPID(1,0,0);
motors[1].setPID(0,0,0);
motors[2].setPID(1,0,0);
motors[3].setPID(0,0,0);
motors[4].setPID(0,0,0);
motors[5].setPID(0,0,0);

reportAllMotors();
//clockISRProfile();

clockSetup();
Expand Down
@@ -1,7 +1,7 @@
package com.marginallyclever.communications;

/**
* Lists available connections of a type (serial, ethernet, smoke signals, etc) and opens a connection of that type
* Lists available connections in a medium (serial, TCP/IP, smoke signals, etc) and opens a connection of that type
*
* @author Dan
* @since v7.1.0.0
Expand Down
Expand Up @@ -20,7 +20,7 @@ public class SerialTransportLayerPanel extends TransportLayerPanel {
private JComboBox<String> connectionBaud;

private String lastConnectionPort="COM4";
private int lastConnectionBaud=115200;
private int lastConnectionBaud=57600;

public static final int [] COMMON_BAUD_RATES = {300,1200,2400,4800,9600,19200,38400,57600,74880,115200,230400,250000,500000,1000000,2000000};

Expand Down
Expand Up @@ -176,9 +176,7 @@ public void closeConnection() {
portOpened = false;
}

/**
* Begins when Thread.start() is called in the constructor
*/
// Begins when Thread.start() is called in the constructor
public void run() {
StringBuilder input = new StringBuilder();

Expand Down
@@ -1,4 +1,4 @@
package com.marginallyclever.robotOverlord.entity.basicDataTypes;
package com.marginallyclever.robotOverlord.entity.remoteEntity;

import java.util.LinkedList;

Expand All @@ -11,15 +11,15 @@
import com.marginallyclever.robotOverlord.swingInterface.view.ViewPanel;

/**
* Wraps all network connection stuff into a neat entity package.
* Wraps all network connection stuff into a neat entity package designed to send one \n terminated string at a time.
*
* See also https://en.wikipedia.org/wiki/Messaging_pattern
*
* @author Dan Royer
* @since 1.6.0
*
*/
public class RemoteEntity extends StringEntity implements NetworkConnectionListener {
public class OneLineAtATimeRemoteEntity extends StringEntity implements NetworkConnectionListener {

/*
// pull the last connected port from prefs
Expand Down Expand Up @@ -60,7 +60,7 @@ public class NumberedCommand {
int nextNumberToSend=0;


public RemoteEntity() {
public OneLineAtATimeRemoteEntity() {
super();
setName("Connected to");
resetCommands();
Expand Down Expand Up @@ -138,12 +138,12 @@ public void sendMessage(String command) {
if(command.isEmpty()) return;

// add the number for error checking
//command = "N"+lastNumberAdded+" "+command;
command = "N"+lastNumberAdded+" "+command;
// add "there is a checksum" (*) + the checksum + end-of-line character
//command += StringHelper.generateChecksum(command) + "\n";
command += StringHelper.generateChecksum(command) + "\n";

//commands.add(new NumberedCommand(lastNumberAdded,command));
//lastNumberAdded++;
commands.add(new NumberedCommand(lastNumberAdded,command));
lastNumberAdded++;

sendQueuedMessage(command);
}
Expand Down
@@ -0,0 +1,91 @@
package com.marginallyclever.robotOverlord.entity.remoteEntity;

import com.marginallyclever.communications.NetworkConnection;
import com.marginallyclever.communications.NetworkConnectionListener;
import com.marginallyclever.communications.NetworkConnectionManager;
import com.marginallyclever.robotOverlord.log.Log;
import com.marginallyclever.robotOverlord.swingInterface.view.ViewPanel;

/**
* Wraps all network connection stuff into a neat entity package.
*
* See also https://en.wikipedia.org/wiki/Messaging_pattern
*
* @author Dan Royer
* @since 1.6.0
*
*/
public class RawByteRemoteEntity extends OneLineAtATimeRemoteEntity implements NetworkConnectionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
public NetworkConnection connection;


public RawByteRemoteEntity() {
super();
setName("Connected to");
}

public void closeConnection() {
connection.closeConnection();
connection.removeListener(this);
connection=null;
}

public void openConnection() {
connection = NetworkConnectionManager.requestNewConnection(null);
if(connection!=null) {
connection.addListener(this);
}
}

@Override
public void update(double dt) {
if(connection!=null) {
connection.update();
}
}

@Override
public void lineError(NetworkConnection arg0, int lineNumber) {}

@Override
public void sendBufferEmpty(NetworkConnection arg0) {}

@Override
public void dataAvailable(NetworkConnection arg0, String data) {
setChanged();
notifyObservers(data);
}

public boolean isConnectionOpen() {
return (connection!=null) && (connection.isOpen());
}

/**
* called by someone else to start the process of sending a message
* @param command
*/
public void sendMessage(String command) {
if(!isConnectionOpen()) return;
if(command.isEmpty()) return;

sendQueuedMessage(command);
}

private void sendQueuedMessage(String command) {
if(command==null) return;
try {
connection.sendMessage(command);
} catch (Exception e) {
Log.error("RemoteEntity.sendQueuedMessage failed: "+e.getLocalizedMessage());
}
}

@Override
public void getView(ViewPanel view) {
super.getView(view);
}
}

0 comments on commit 52b4aee

Please sign in to comment.