Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServoMixer Updates #816

Merged
merged 10 commits into from May 4, 2021
870 changes: 438 additions & 432 deletions pom.xml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/main/java/org/myrobotlab/jme3/Jme3App.java
Expand Up @@ -31,7 +31,8 @@ public Jme3App(JMonkeyEngine jme) {
// menu = new MainMenuState(jme),
new ScreenshotAppState("", System.currentTimeMillis()));
menu = new MainMenuState(jme);
stateManager.attach(menu);
// REMOVED THE MENU ! GroG 20210424
// stateManager.attach(menu);
this.jme = jme;
// setShowSettings(true);
}
Expand Down
15 changes: 4 additions & 11 deletions src/main/java/org/myrobotlab/kinematics/Pose.java
Expand Up @@ -15,14 +15,12 @@
/** represent a set of servo positions at a given point in time */
public class Pose {

public final String name;
public final Date createdDate;
public String name;
public HashMap<String, Double> positions = new HashMap<String, Double>();
public HashMap<String, Double> speeds = new HashMap<String, Double>();

public Pose(String name, List<ServoControl> servos) {
this.name = name;
this.createdDate = new Date();
List<String> servoNames = new ArrayList<String>();
for (ServoControl sc : servos) {
positions.put(sc.getName(), sc.getCurrentInputPos());
Expand All @@ -40,7 +38,7 @@ public HashMap<String, Double> getPositions() {
}

public void savePose(String filename) throws IOException {
String s = CodecUtils.toJson(this);
String s = CodecUtils.toPrettyJson(this);
FileOutputStream out = new FileOutputStream(new File(filename));
out.write(s.getBytes());
out.close();
Expand All @@ -56,7 +54,6 @@ public static Pose loadPose(String filename) throws IOException {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((createdDate == null) ? 0 : createdDate.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((positions == null) ? 0 : positions.hashCode());
return result;
Expand All @@ -71,11 +68,7 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass())
return false;
Pose other = (Pose) obj;
if (createdDate == null) {
if (other.createdDate != null)
return false;
} else if (!createdDate.equals(other.createdDate))
return false;

if (name == null) {
if (other.name != null)
return false;
Expand All @@ -91,7 +84,7 @@ public boolean equals(Object obj) {

@Override
public String toString() {
return "Pose [positions=" + positions + ", speeds=\" + speeds + \", name=" + name + ", createdDate=" + createdDate + "]";
return "Pose [positions=" + positions + ", speeds=\" + speeds + \", name=" + name + "]";
}

}
27 changes: 27 additions & 0 deletions src/main/java/org/myrobotlab/kinematics/PoseSequence.java
@@ -0,0 +1,27 @@
package org.myrobotlab.kinematics;

public class PoseSequence {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this class to something easier to understand like a pose step.. or just a step (as a base class).. .. "sequence" makes me think this is a list of steps. but it's not, it's just one of them.


public int id;

/**
* name of pose
*/
public String name;

/**
* number of ms to wait before starting this pose
*/
public Long waitTimeMs;

public PoseSequence() {
}

public String toString() {
if (waitTimeMs == null) {
return name;
} else {
return String.format("%s %d ms");
}
}
}
45 changes: 45 additions & 0 deletions src/main/java/org/myrobotlab/kinematics/Sequence.java
@@ -0,0 +1,45 @@
package org.myrobotlab.kinematics;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.myrobotlab.codec.CodecUtils;
import org.myrobotlab.io.FileIO;
import org.myrobotlab.logging.LoggerFactory;
import org.myrobotlab.service.InMoov2;
import org.slf4j.Logger;

/** represent a set of servo positions at a given point in time */
public class Sequence {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this sequence, really should be renamed to gesture, and it should be represented by a list of steps..
steps can be pose steps or speaking steps.. (perhaps others)


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

public String name;

/**
* sequence of poses and offset times
*/
public List<PoseSequence> poses = new ArrayList<>();

public boolean cycle = false;

public Sequence() {
}

public Sequence(String name) {
this.name = name;
}

@Override
public String toString() {
return "Sequence: " + name;
}

public static Sequence loadSequence(String filename) throws IOException {
String json = FileIO.toString(filename);
Sequence pose = (Sequence) CodecUtils.fromJson(json, Sequence.class);
return pose;
}

}
12 changes: 8 additions & 4 deletions src/main/java/org/myrobotlab/service/InMoov2.java
Expand Up @@ -1170,6 +1170,14 @@ public void startAll(String leftPort, String rightPort) throws Exception {

speakBlocking(get("STARTINGSEQUENCE"));
}

/**
* start servos - no controllers
* @throws Exception
*/
public void startServos() throws Exception {
startServos(null, null);
}

public ProgramAB startChatBot() {

Expand Down Expand Up @@ -1299,10 +1307,6 @@ public InMoov2Head startHead(String port) throws Exception {
// legacy inmoov head exposed pins
public InMoov2Head startHead(String port, String type, Integer headYPin, Integer headXPin, Integer eyeXPin, Integer eyeYPin, Integer jawPin, Integer rollNeckPin) {

// log.warn(InMoov.buildDNA(myKey, serviceClass))
// speakBlocking(get("STARTINGHEAD") + " " + port);
// ??? SHOULD THERE BE REFERENCES AT ALL ??? ... probably not

speakBlocking(get("STARTINGHEAD"));

head = (InMoov2Head) startPeer("head");
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/myrobotlab/service/JMonkeyEngine.java
Expand Up @@ -2093,7 +2093,9 @@ public void simpleInitApp() {
// rootNode.setLocalTranslation(0, -200, 0);
rootNode.setLocalTranslation(0, 0, 0);


menu = app.getMainMenu();// new MainMenuState(this);
// menu.setEnabled(false);
// menu.loadGui();

if (usePhysics) {
Expand Down Expand Up @@ -2175,9 +2177,12 @@ synchronized public SimpleApplication start(String appName, String appType) {
// settings.setUseJoysticks(false);
settings.setUseInput(true);
settings.setAudioRenderer(null);
settings.setResizable(true);
app.setSettings(settings);

app.setShowSettings(false); // resolution bps etc dialog
app.setPauseOnLostFocus(false);


// the all important "start" - anyone goofing around with the engine
// before this is done will
Expand Down Expand Up @@ -2299,7 +2304,7 @@ public static void main(String[] args) {
LoggingFactory.init("WARN");

Platform.setVirtual(true);
Runtime.main(new String[] { "--interactive", "--id", "admin" });
// Runtime.main(new String[] { "--interactive", "--id", "admin" });
JMonkeyEngine jme = (JMonkeyEngine) Runtime.start("simulator", "JMonkeyEngine");

jme.addBox("box", 1.0, 1.0, 1.0, "fc8803", true);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/myrobotlab/service/Servo.java
Expand Up @@ -191,7 +191,7 @@ protected boolean processMove(Double newPos, boolean blocking, Long timeoutMs) {
broadcast("publishServoMoveTo", this);
}
// invoke("publishServoMoveTo", this);
broadcastState();
// broadcastState();
if (isBlocking) {
// our thread did a blocking call - we will wait until encoder notifies us
// to continue or timeout (if supplied) has been reached
Expand Down