我需要计算余弦 theta 的值,并且我还需要最终找到机器人当前位置和它移动的新位置之间的角度值。θ 值。
import java.io.IOException;
import java.lang.reflect.Method;
import mrds_project.Path;
import mrds_project.Pose;
import mrds_project.controller.Controller;
import java.lang.Math;
public class NaiveStrategy implements PathStrategy {
private final Controller controller;
private NaiveStrategy() {
}
public NaiveStrategy(Controller controller) {
this.controller = controller;
}
@Override
public void move(Path path) {
for (Pose target : path) {
Pose currentPose = controller.getPose();
double[] targetPoint = target.getPosition().getVector();
double targetVectorX;
double targetVectorY;
double currentVector;
targetVectorX = targetPoint[0] - currentPose.getPosition().getVector()[0];
targetVectorY = targetPoint[1] - currentPose.getPosition().getVector()[1];
}
}
public double dotPro1(double[] vectorA, double[] vectorB){
double[] vecPro;
vecPro = new double[2];
vecPro[0] = vectorA[0]*vectorB[0];
vecPro[1] = vectorA[1]*vectorB[1];
return vecPro[0] + vecPro[1];
}
public double dotPro2(double[] length){
double[] lenPro;
lenPro = new double[1];
lenPro[0] = length[0];
return lenPro[0];
}
public static double cosine(double a) throws IOException, ClassNotFoundException{
double x = Math.cos(Math.toRadians(a));
Class c = Class.forName("NaiveStrategy");
Class methodTypes[] = new Class[3];
methodTypes[0] = Double.TYPE;
methodTypes[1] = Double.TYPE;
methodTypes[2] = Double.TYPE;
Method[] m = c.getMethods();
NaiveStrategy ns = new NaiveStrategy();
Object arg[] = new Object[3];
arg[0] = new Double(50);
arg[1] = new Double(50);
arg[2] = new Double(50);
Object o = m.ns(ns, arg);
return 0;
}
}
我需要知道这个问题的答案,我在构造函数中遇到错误,我知道为什么是因为“变量控制器可能没有初始化”。在 return 语句之前的最后一行出现错误,我不知道,它说“找不到符号”
Controller.java
package mrds_project.controller;
import mrds_project.Pose;
public interface Controller {
void setVelocity(int linear, int angular);
public Pose getPose();
}
Pose.java
package mrds_project;
import java.util.Map;
public class Pose {
private final Quaternion orientation;
private final Quaternion position;
public Pose(Map<String, Object> mrdsmap)
{
Map<String, Object> orientationMap = (Map<String, Object>) mrdsmap.get("Orientation");
double w = (Double) orientationMap.get("W");
double x = (Double)orientationMap.get("X");
double y = (Double)orientationMap.get("Y");
double z = (Double)orientationMap.get("Z");
orientation = new Quaternion(w, x, y, z);
Map<String, Object> positionMap = (Map<String, Object>) mrdsmap.get("Position");
double x1 = (Double)positionMap.get("X");
double y1 = (Double)positionMap.get("Y");
double z1 = (Double)positionMap.get("Z");
position = new Quaternion(x1, y1, z1);
}
public Quaternion getOrientation() {
return orientation;
}
public Quaternion getPosition() {
return position;
}
}