/** * Generates a prismatic joint with random physical parameters and attaches it to the given * {@code predecessor}. * * @param random the random generator to use. * @param name the joint name. * @param predecessor the rigid-body to which the joint is added as a child. * @return the random joint. */ public static PrismaticJoint nextPrismaticJoint(Random random, String name, RigidBodyBasics predecessor) { Vector3D jointAxis = EuclidCoreRandomTools.nextVector3DWithFixedLength(random, 1.0); return nextPrismaticJoint(random, name, jointAxis, predecessor); }
/** * Generates a 1-DoF joint with random physical parameters and attaches it to the given * {@code predecessor}. * * @param random the random generator to use. * @param name the joint name. * @param jointAxis used to define the joint axis. * @param predecessor the rigid-body to which the joint is added as a child. * @return the random joint. */ public static OneDoFJoint nextOneDoFJoint(Random random, String name, Vector3DReadOnly jointAxis, RigidBodyBasics predecessor) { if (random.nextBoolean()) return nextPrismaticJoint(random, name, jointAxis, predecessor); else return nextRevoluteJoint(random, name, jointAxis, predecessor); }
/** * Generates a 1-DoF joint with random physical parameters and attaches it to the given * {@code predecessor}. * * @param random the random generator to use. * @param name the joint name. * @param predecessor the rigid-body to which the joint is added as a child. * @return the random joint. */ public static OneDoFJoint nextOneDoFJoint(Random random, String name, RigidBodyBasics predecessor) { if (random.nextBoolean()) return nextPrismaticJoint(random, name, predecessor); else return nextRevoluteJoint(random, name, predecessor); }
/** * Generates a random kinematic chain composed of rigid-bodies and prismatic joints. * <p> * The joints and rigid-bodies have random physical parameters. * </p> * <p> * The generated multi-body system is a kinematic chain, i.e. every rigid-body has only one child * joint. * </p> * * @param random the random generator to use. * @param prefix provides a common prefix used for all the joint and rigid-body names. * @param rootBody the root to which the kinematic chain is to be attached. * @param jointAxes array containing in order the axis for each joint. The length of the array also * defines the number of joints for the generated kinematic chain. * @return the list of all the joints composing the kinematic chain. */ public static List<PrismaticJoint> nextPrismaticJointChain(Random random, String prefix, RigidBodyBasics rootBody, Vector3DReadOnly[] jointAxes) { RigidBodyBasics predecessor = rootBody; List<PrismaticJoint> prismaticJoints = new ArrayList<>(); for (int i = 0; i < jointAxes.length; i++) { PrismaticJoint joint = nextPrismaticJoint(random, prefix + "Joint" + i, jointAxes[i], predecessor); prismaticJoints.add(joint); predecessor = nextRigidBody(random, prefix + "Body" + i, joint); } return prismaticJoints; }
/** * Generates a random kinematic tree composed of rigid-bodies and prismatic joints. * <p> * The joints and rigid-bodies have random physical parameters. * </p> * <p> * The generated multi-body system is a kinematic tree, i.e. every rigid-body can have one or more * child joint(s). * </p> * * @param random the random generator to use. * @param prefix provides a common prefix used for all the joint and rigid-body names. * @param rootBody the root to which the kinematic tree is to be attached. * @param numberOfJoints how many joints the kinematic tree should be composed of. * @return the list of all the joints composing the kinematic tree. */ public static List<PrismaticJoint> nextPrismaticJointTree(Random random, String prefix, RigidBodyBasics rootBody, int numberOfJoints) { List<PrismaticJoint> prismaticJoints = new ArrayList<>(); RigidBodyBasics predecessor = rootBody; for (int i = 0; i < numberOfJoints; i++) { PrismaticJoint joint = nextPrismaticJoint(random, prefix + "Joint" + i, predecessor); nextRigidBody(random, prefix + "Body" + i, joint); prismaticJoints.add(joint); predecessor = prismaticJoints.get(random.nextInt(prismaticJoints.size())).getSuccessor(); } return SubtreeStreams.from(PrismaticJoint.class, rootBody.getChildrenJoints()).collect(Collectors.toList()); }
/** * Generates a joint with random type and physical parameters and attaches it to the given * {@code predecessor}. * * @param random the random generator to use. * @param name the joint name. * @param predecessor the rigid-body to which the joint is added as a child. * @return the random joint. */ public static JointBasics nextJoint(Random random, String name, RigidBodyBasics predecessor) { switch (random.nextInt(6)) { case 0: return nextSixDoFJoint(random, name, predecessor); case 1: return nextPlanarJoint(random, name, predecessor); case 2: return nextSphericalJoint(random, name, predecessor); case 3: return nextPrismaticJoint(random, name, predecessor); case 4: return nextRevoluteJoint(random, name, predecessor); default: return nextFixedJoint(random, name, predecessor); } }