BowlerKernel
RobotHelper.java
Go to the documentation of this file.
1 package com.neuronrobotics.bowlerstudio.scripting;
2 
3 import java.io.File;
4 import java.io.IOException;
5 import java.nio.file.Files;
6 import java.util.ArrayList;
7 import java.util.Arrays;
8 
9 import org.apache.commons.io.IOUtils;
10 
11 import com.neuronrobotics.bowlerstudio.creature.MobileBaseLoader;
12 import com.neuronrobotics.sdk.addons.kinematics.DHLink;
13 import com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics;
14 import com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration;
15 import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
16 
17 public class RobotHelper implements IScriptingLanguage {
18 
19  @Override
20  public Object inlineScriptRun(File code, ArrayList<Object> args) {
21  byte[] bytes;
22  try {
23  bytes = Files.readAllBytes(code.toPath());
24  String s = new String(bytes, "UTF-8");
25  MobileBase mb;
26  try {
27  mb = new MobileBase(IOUtils.toInputStream(s, "UTF-8"));
29  return MobileBaseLoader.get(mb).getBase();
30  } catch (IOException e) {
31  // TODO Auto-generated catch block
32  e.printStackTrace();
33  return null;
34  }
35  } catch (IOException e1) {
36  // TODO Auto-generated catch block
37  e1.printStackTrace();
38  }
39  // System.out.println("Clojure returned of type="+ret.getClass()+" value="+ret);
40  return null;
41  }
42 
43  @Override
44  public Object inlineScriptRun(String code, ArrayList<Object> args) {
45 
46  MobileBase mb = null;
47  try {
48  mb = new MobileBase(IOUtils.toInputStream(code, "UTF-8"));
49  } catch (IOException e) {
50  // TODO Auto-generated catch block
51  e.printStackTrace();
52  return null;
53  }
54 
55  return mb;
56  }
57 
58  @Override
59  public String getShellType() {
60  return "MobilBaseXML";
61  }
62 
63  @Override
64  public boolean getIsTextFile() {
65  // TODO Auto-generated method stub
66  return true;
67  }
68 
74  public String getDefaultContents() {
75 
76  return new MobileBase().getXml();
77  }
78 
84  @SuppressWarnings("restriction")
85  public String getDefaultContents(String gitURL, String slug) {
86  MobileBase back = new MobileBase();
87  back.setScriptingName(slug);
88  back.setGitSelfSource(Arrays.asList(gitURL, slug + ".xml").toArray(new String[0]));
89  String[] cad = ScriptingEngine.copyGitFile(
90  "https://github.com/CommonWealthRobotics/BowlerStudioExampleRobots.git", gitURL, "exampleCad.groovy",slug+"Cad.groovy",true);
91  String[] kin = ScriptingEngine.copyGitFile(
92  "https://github.com/CommonWealthRobotics/BowlerStudioExampleRobots.git", gitURL,
93  "exampleKinematics.groovy",slug+"Kinematics.groovy",true);
94  String[] walk = ScriptingEngine.copyGitFile(
95  "https://github.com/CommonWealthRobotics/BowlerStudioExampleRobots.git", gitURL,
96  "exampleWalking.groovy",slug+"Walk.groovy",true);
97  back.setGitCadEngine(cad);
98  back.setGitDhEngine(kin);
99  back.setGitWalkingEngine(walk);
101  limb.setScriptingName(slug+"-Limb-1");
102  limb.setGitCadEngine(cad);
103  limb.setGitDhEngine(kin);
104  LinkConfiguration newLink = new LinkConfiguration();
105  newLink.setName("link1");
106  newLink.setDeviceScriptingName(newLink.getName());
107  newLink.setDeviceScriptingName("exampleDevice");
108  DHLink nextLink = new DHLink(0, 0, 100, 0);
109  nextLink.setListener(new javafx.scene.transform.Affine());
110  limb.addNewLink(newLink, nextLink);
111  back.getAppendages().add(limb);
112 
113  return back.getXml();
114  }
115 
116  @Override
117  public ArrayList<String> getFileExtenetion() {
118  // TODO Auto-generated method stub
119  return new ArrayList<>(Arrays.asList("xml"));
120  }
121 
122 }
Object inlineScriptRun(File code, ArrayList< Object > args)
Object inlineScriptRun(String code, ArrayList< Object > args)
static String[] copyGitFile(String sourceGit, String targetGit, String filename)
void addNewLink(LinkConfiguration newLink, DHLink dhLink)
void setGitWalkingEngine(String[] walkingEngine)
ArrayList< DHParameterKinematics > getAppendages()