Skip to content

Commit

Permalink
resolved or less controversial updates (#1364)
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick authored Nov 15, 2023
1 parent 8d33fc5 commit 10eb2f5
Show file tree
Hide file tree
Showing 29 changed files with 1,355 additions and 76 deletions.
59 changes: 58 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
<!-- Duplicate entry for com.squareup.okhttp3-okhttp-3.9.0 skipping -->
<!-- AzureTranslator end -->

<!-- BoofCV begin -->
<!-- BoofCv begin -->
<dependency>
<groupId>org.boofcv</groupId>
<artifactId>boofcv-all</artifactId>
Expand Down Expand Up @@ -198,6 +198,12 @@
</dependency>
<!-- CsvConnector end -->

<dependency>
<groupId>org.nanohttpd</groupId> <!-- <groupId>com.nanohttpd</groupId> for 2.1.0 and earlier -->
<artifactId>nanohttpd</artifactId>
<version>2.2.0</version>
</dependency>

<!-- Deeplearning4j begin -->
<dependency>
<groupId>org.bytedeco</groupId>
Expand Down Expand Up @@ -1602,6 +1608,34 @@
</dependency>
<!-- Twitter end -->

<!-- Vertx begin -->
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>4.3.3</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
<version>4.3.3</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Duplicate entry for io.netty-netty-all-4.1.82.Final skipping -->
<!-- Vertx end -->

<!-- VoiceRss begin -->
<!-- Duplicate entry for org.myrobotlab.audio-voice-effects-1.0 skipping -->
<dependency>
Expand Down Expand Up @@ -1645,6 +1679,18 @@
<!-- Duplicate entry for javax.websocket-javax.websocket-api-1.1 skipping -->
<!-- WebSocketConnector end -->

<dependency>
<groupId>au.edu.federation.caliko</groupId>
<artifactId>caliko</artifactId>
<version>1.3.8</version>
</dependency>

<dependency>
<groupId>au.edu.federation.caliko.visualisation</groupId>
<artifactId>caliko-visualisation</artifactId>
<version>1.3.8</version>
</dependency>

<!-- Webcam begin -->
<dependency>
<groupId>com.github.sarxos</groupId>
Expand Down Expand Up @@ -1733,13 +1779,24 @@
</dependency>
<!-- Xmpp end -->

<dependency>
<groupId>dev.onvoid.webrtc</groupId>
<artifactId>webrtc-java</artifactId>
<version>0.7.0</version>
</dependency>


<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.12.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>au.edu.federation.caliko.demo</groupId>
<artifactId>caliko-demo</artifactId>
<version>1.3.8</version>
</dependency>
</dependencies>

<build>
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/myrobotlab/framework/interfaces/JsonSender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.myrobotlab.framework.interfaces;

public interface JsonSender {

/**
* Send interface which takes a json encoded Message.
* For schema look at org.myrobotlab.framework.Message
* @param jsonEncodedMessage
*/
public void send(String jsonEncodedMessage);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.myrobotlab.framework.Message;
import org.myrobotlab.framework.TimeoutException;

public interface MessageSender extends NameProvider {
public interface MessageSender extends NameProvider, SimpleMessageSender {

/**
* Send invoking messages to remote location to invoke {name} instance's
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.myrobotlab.framework.interfaces;

import org.myrobotlab.framework.Message;

public interface SimpleMessageSender {

public void send(Message msg);

}
46 changes: 37 additions & 9 deletions src/main/java/org/myrobotlab/service/FiniteStateMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.myrobotlab.logging.LoggingFactory;
import org.myrobotlab.service.config.FiniteStateMachineConfig;
import org.myrobotlab.service.config.FiniteStateMachineConfig.Transition;
import org.myrobotlab.service.config.ServiceConfig;
import org.slf4j.Logger;

import com.github.pnavais.machine.StateMachine;
Expand Down Expand Up @@ -46,8 +45,14 @@ public class FiniteStateMachine extends Service<FiniteStateMachineConfig> {

protected String lastEvent = null;

@Deprecated /* is this deprecated with ServiceConfig.listeners ? */
protected Set<String> messageListeners = new HashSet<>();

/**
* state history of fsm
*/
protected List<String> history = new ArrayList<>();

// TODO - .from("A").to("B").on(Messages.ANY)
// TODO - .from("A").to("B").on(Messages.EMPTY)

Expand All @@ -58,6 +63,21 @@ public class Tuple {
public Transition transition;
public StateTransition stateTransition;
}

public class StateChange {
public String last;
public String current;
public String event;
public StateChange(String last, String current, String event) {
this.last = last;
this.current = current;
this.event = event;
}

public String toString() {
return String.format("%s --%s--> %s", last, event, current);
}
}

private static Transition toFsmTransition(StateTransition state) {
Transition transition = new Transition();
Expand Down Expand Up @@ -92,6 +112,13 @@ public String getNext(String key) {

public void init() {
stateMachine.init();
State state = stateMachine.getCurrent();
if (history.size() > 100) {
history.remove(0);
}
if (state != null) {
history.add(state.getName());
}
}

private String makeKey(String state0, String msgType, String state1) {
Expand Down Expand Up @@ -167,7 +194,8 @@ public void fire(String event) {
log.info("fired event ({}) -> ({}) moves to ({})", event, last == null ? null : last.getName(), current == null ? null : current.getName());

if (last != null && !last.equals(current)) {
invoke("publishNewState", current.getName());
invoke("publishStateChange", new StateChange(last.getName(), current.getName(), event));
history.add(current.getName());
}
} catch (Exception e) {
log.error("fire threw", e);
Expand Down Expand Up @@ -209,21 +237,21 @@ public List<Transition> getTransitions() {
}

/**
* publishes state if changed here
* Publishes state change (current, last and event)
*
* @param state
* @param stateChange
* @return
*/
public String publishNewState(String state) {
log.error("publishNewState {}", state);
public StateChange publishStateChange(StateChange stateChange) {
log.info("publishStateChange {}", stateChange);
for (String listener : messageListeners) {
ServiceInterface service = Runtime.getService(listener);
if (service != null) {
org.myrobotlab.framework.Message msg = org.myrobotlab.framework.Message.createMessage(getName(), listener, CodecUtils.getCallbackTopicName(state), null);
org.myrobotlab.framework.Message msg = org.myrobotlab.framework.Message.createMessage(getName(), listener, CodecUtils.getCallbackTopicName(stateChange.current), null);
service.in(msg);
}
}
return state;
return stateChange;
}

@Override
Expand Down Expand Up @@ -391,7 +419,7 @@ public void setCurrent(String state) {
stateMachine.setCurrent(state);
current = stateMachine.getCurrent();
if (last != null && !last.equals(current)) {
invoke("publishNewState", current.getName());
invoke("publishStateChange", new StateChange(last.getName(), current.getName(), null));
}
} catch (Exception e) {
log.error("setCurrent threw", e);
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/myrobotlab/service/JMonkeyEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.FloatBuffer;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -52,7 +50,6 @@
import org.myrobotlab.net.Connection;
import org.myrobotlab.sensor.EncoderData;
import org.myrobotlab.sensor.EncoderListener;
import org.myrobotlab.service.abstracts.AbstractComputerVision;
import org.myrobotlab.service.config.JMonkeyEngineConfig;
import org.myrobotlab.service.config.ServiceConfig;
import org.myrobotlab.service.interfaces.Gateway;
Expand Down Expand Up @@ -405,10 +402,12 @@ public void attach(Attachable attachable) throws Exception {
// this is to support future (non-Java) classes that cannot be instantiated
// and
// are subclassed in a proxy class with getType() overloaded for to identify
/**<pre> DO NOT NEED THIS UNTIL JMONKEY DISPLAYS VIDEO DATA - SLAM MAPPING
if (service.getTypeKey().equals("org.myrobotlab.service.OpenCV")) {
AbstractComputerVision cv = (AbstractComputerVision) service;
subscribe(service.getName(), "publishCvData");
}
}</pre>
*/

if (service.getTypeKey().equals("org.myrobotlab.service.Servo")) {
// non-batched - "instantaneous" move data subscription
Expand Down Expand Up @@ -1469,7 +1468,7 @@ public void onAnalog(String name, float keyPressed, float tpf) {

// PAN -- works(ish)
if (mouseMiddle && shiftLeft) {
log.info("PAN !!!!");
log.debug("panning");
switch (name) {
case "mouse-axis-x":
case "mouse-axis-x-negative":
Expand Down
40 changes: 38 additions & 2 deletions src/main/java/org/myrobotlab/service/OakD.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.myrobotlab.service;

import org.myrobotlab.framework.Service;
import org.myrobotlab.framework.Status;
import org.myrobotlab.logging.Level;
import org.myrobotlab.logging.LoggerFactory;
import org.myrobotlab.logging.LoggingFactory;
import org.myrobotlab.service.config.ServiceConfig;
import org.myrobotlab.process.GitHub;
import org.myrobotlab.service.config.OakDConfig;
import org.slf4j.Logger;
/**
*
Expand All @@ -14,16 +16,50 @@
* @author GroG
*
*/
public class OakD extends Service<ServiceConfig> {
public class OakD extends Service<OakDConfig> {

private static final long serialVersionUID = 1L;

public final static Logger log = LoggerFactory.getLogger(OakD.class);

private transient Py4j py4j = null;
private transient Git git = null;

public OakD(String n, String id) {
super(n, id);
}

public void startService() {
super.startService();

py4j = (Py4j)startPeer("py4j");
git = (Git)startPeer("git");

if (config.py4jInstall) {
installDepthAi();
}

}

/**
* starting install of depthapi
*/
public void publishInstallStart() {
}

public Status publishInstallFinish() {
return Status.error("depth ai install was not successful");
}

/**
* For depthai we need to clone its repo and install requirements
*
*/
public void installDepthAi() {

//git.clone("./", config.depthaiCloneUrl)
py4j.exec("");
}

public static void main(String[] args) {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/myrobotlab/service/ProgramAB.java
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ public String addBotPath(String path) {

broadcastState();
} else {
error("invalid bot path - a bot must be a directory with a subdirectory named \"aiml\"");
error("invalid bot path %s - a bot must be a directory with a subdirectory named \"aiml\"", path);
return null;
}
return path;
Expand Down
Loading

0 comments on commit 10eb2f5

Please sign in to comment.