我需要计算余弦θ和θ的值 此外,我需要最终找到机器人的当前位置和它移动的新位置之间的角度值。 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;
}
}
我需要知道答案,我在构造函数中遇到错误,我知道为什么它是因为“变量控制器可能没有初始化”。和ERROR在返回语句前的最后一行,我不知道,它说“找不到符号”
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;
}
}
答案 0 :(得分:3)
您不能拥有未分配的最终变量
private final Controller controller;
和默认构造函数 - 编译器将防止未分配的变量。删除final
关键字将允许您保留2个构造函数。
答案 1 :(得分:1)
更改
Object o = m.ns(ns, arg);
到
Object o = m.invoke(ns, arg);
但是你为什么还要使用反射呢?为什么不使用
public static double cosine(double a) {
double x = Math.cos(Math.toRadians(a));
NaiveStrategy ns = new NaiveStrategy();
ns.YourMethodHere(50, 50, 50);
return 0;
}