Introduction to Java Programming编程题5.26<回文素数>

本文介绍了一个使用Java实现的程序,该程序能够找出前100个既是素数又是回文数的整数。文章详细解释了如何判断一个数是否为素数以及如何检查一个数是否为其自身的反转。此外,还提供了完整的源代码供读者学习和参考。
/*
2   3   5   7   11  101 131 151 181 191
313 353 373 383 727 757 787 797 919 929
10301   10501   10601   11311   11411   12421   12721   12821   13331   13831
13931   14341   14741   15451   15551   16061   16361   16561   16661   17471
17971   18181   18481   19391   19891   19991   30103   30203   30403   30703
30803   31013   31513   32323   32423   33533   34543   34843   35053   35153
35353   35753   36263   36563   37273   37573   38083   38183   38783   39293
70207   70507   70607   71317   71917   72227   72727   73037   73237   73637
74047   74747   75557   76367   76667   77377   77477   77977   78487   78787
78887   79397   79697   79997   90709   91019   93139   93239   93739   94049
*/
public class CovertTime {
  public static void main(String[] args) {
    int count = 0;
    for (int i = 2; count < 100; i++) {
      if (isPrimer(i)) {
        if (isReverseNumber(i)) {
          count++;
          System.out.print(i + "\t");
          if (count % 10 == 0)
            System.out.println();
        }
      }
    }
  }

  public static boolean isPrimer(int n) {
    for (int i = 2; i <= n / 2; i++) {
      if (n % i == 0)
        return false;
    }
    return true;
  }

  public static boolean isReverseNumber(int n) {
    if (reverseNumber(n) == n)
      return true;
    else
      return false;
  }

  public static int reverseNumber(int n) {
    int i, temp = n, count = 0;
    long reverseNumber = 0;
    final int DECIMAL = 10;

    while ((temp /= DECIMAL) != 0)
      count++;

    do {
      reverseNumber += (n % DECIMAL) * Math.pow(DECIMAL, count);
      count--;
    } while ((n /= DECIMAL) != 0);

    return (int)reverseNumber;
  }
}
="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/collision/link7.stl"/></geometry></collision><inertial><origin rpy="0 0 0" xyz="0.0045225817 0.0086261921 -0.0161633251"/><mass value="0.6271432862"/><inertia ixx="0.00021092389150104718" ixy="-2.433299114461931e-05" ixz="4.564480393778983e-05" iyy="0.00017718568002411474" iyz="8.744070223226438e-05" izz="5.993190599659971e-05"/></inertial></link><joint name="fr3_joint7" type="revolute"><origin rpy="1.570796326794897 0 0" xyz="0.088 0 0"/><parent link="fr3_link6"/><child link="fr3_link7"/><axis xyz="0 0 1"/><limit effort="12.0" lower="-3.0159" upper="3.0159" velocity="5.26"/><safety_controller k_position="100.0" k_velocity="40.0" soft_lower_limit="-3.0159" soft_upper_limit="3.0159"/><dynamics D="1" K="7000" damping="0.003" friction="0.2" mu_coulomb="0" mu_viscous="16"/></joint><link name="fr3_link8"/><joint name="fr3_joint8" type="fixed"><origin rpy="0 0 0" xyz="0 0 0.107"/><parent link="fr3_link7"/><child link="fr3_link8"/></joint><joint name="fr3_hand_joint" type="fixed"><parent link="fr3_link8"/><child link="fr3_hand"/><origin rpy="0 0 -0.7853981633974483" xyz="0 0 0"/></joint><!-- sub-link defining detailed meshes for collision with environment --><link name="fr3_hand"><visual name="fr3_hand_visual"><geometry><mesh filename="package://franka_description/meshes/robot_ee/franka_hand_white/visual/hand.dae"/></geometry></visual><collision name="fr3_hand_collision"><geometry><mesh filename="package://franka_description/meshes/robot_ee/franka_hand_white/collision/hand.stl"/></geometry></collision><inertial><origin rpy="0 0 0" xyz="-0.0000376 0.0119128 0.0207260"/><mass value="0.6544"/><inertia ixx="0.00186" ixy="0.0" ixz="0.0" iyy="0.0003" iyz="-2e-05" izz="0.00174"/></inertial></link><!-- Define the hand_tcp frame --><link name="fr3_hand_tcp"/><joint name="fr3_hand_tcp_joint" type="fixed"><origin rpy="0 0 0" xyz="0 0 0.1034"/><parent link="fr3_hand"/><child link="fr3_hand_tcp"/></joint><link name="fr3_leftfinger"><visual name="fr3_leftfinger_visual"><geometry><mesh filename="package://franka_description/meshes/robot_ee/franka_hand_white/visual/finger.dae"/></geometry></visual><!-- screw mount --><collision><origin rpy="0 0 0" xyz="0 18.5e-3 11e-3"/><geometry><box size="22e-3 15e-3 20e-3"/></geometry></collision><!-- cartriage sledge --><collision><origin rpy="0 0 0" xyz="0 6.8e-3 2.2e-3"/><geometry><box size="22e-3 8.8e-3 3.8e-3"/></geometry></collision><!-- diagonal finger --><collision><origin rpy="0.5235987755982988 0 0" xyz="0 15.9e-3 28.35e-3"/><geometry><box size="17.5e-3 7e-3 23.5e-3"/></geometry></collision><!-- rubber tip with which to grasp --><collision><origin rpy="0 0 0" xyz="0 7.58e-3 45.25e-3"/><geometry><box size="17.5e-3 15.2e-3 18.5e-3"/></geometry></collision><inertial><origin rpy="0 0 0" xyz="0 0.0152850 0.0219675"/><mass value="0.0291"/><inertia ixx="8.49e-06" ixy="0.0" ixz="0.0" iyy="8.53e-06" iyz="-1.06e-06" izz="1.77e-06"/></inertial></link><link name="fr3_rightfinger"><visual name="fr3_rightfinger_visual"><origin rpy="0 0 0" xyz="0 0 0"/><geometry><mesh filename="package://franka_description/meshes/robot_ee/franka_hand_white/visual/finger.dae"/></geometry></visual><!-- screw mount --><collision><origin rpy="0 0 0" xyz="0 18.5e-3 11e-3"/><geometry><box size="22e-3 15e-3 20e-3"/></geometry></collision><!-- cartriage sledge --><collision><origin rpy="0 0 0" xyz="0 6.8e-3 2.2e-3"/><geometry><box size="22e-3 8.8e-3 3.8e-3"/></geometry></collision><!-- diagonal finger --><collision><origin rpy="-0.5235987755982988 0 3.141592653589793" xyz="0 15.9e-3 28.35e-3"/><geometry><box size="17.5e-3 7e-3 23.5e-3"/></geometry></collision><!-- rubber tip with which to grasp --><collision><origin rpy="0 0 0" xyz="0 7.58e-3 45.25e-3"/><geometry><box size="17.5e-3 15.2e-3 18.5e-3"/></geometry></collision><inertial><origin rpy="0 0 0" xyz="0 0.0152850 0.0219675"/><mass value="0.0291"/><inertia ixx="8.49e-06" ixy="0.0" ixz="0.0" iyy="8.53e-06" iyz="-1.06e-06" izz="1.77e-06"/></inertial></link><joint name="fr3_finger_joint1" type="prismatic"><parent link="fr3_hand"/><child link="fr3_leftfinger"/><origin rpy="0 0 0" xyz="0 0 0.0584"/><axis xyz="0 1 0"/><limit effort="100" lower="0.0" upper="0.04" velocity="0.2"/><dynamics damping="0.3"/></joint><joint name="fr3_finger_joint2" type="prismatic"><parent link="fr3_hand"/><child link="fr3_rightfinger"/><origin rpy="0 0 3.141592653589793" xyz="0 0 0.0584"/><axis xyz="0 1 0"/><limit effort="100" lower="0.0" upper="0.04" velocity="0.2"/><mimic joint="fr3_finger_joint1"/><dynamics damping="0.3"/></joint><ros2_control name="FrankaHardwareInterface" type="system"><hardware><param name="arm_id">fr3</param><param name="prefix"></param><plugin>franka_hardware/FrankaHardwareInterface</plugin><param name="robot_ip"></param><param name="arm_prefix"></param></hardware><joint name="fr3_joint1"><command_interface name="position"/><command_interface name="velocity"/><command_interface name="effort"/><!-- State Interfaces --><state_interface name="position"><param name="initial_value">0.0</param></state_interface><state_interface name="velocity"/><param name="initial_value">0.0</param><state_interface name="effort"/></joint><joint name="fr3_joint2"><command_interface name="position"/><command_interface name="velocity"/><command_interface name="effort"/><!-- State Interfaces --><state_interface name="position"><param name="initial_value">-0.7853981633974483</param></state_interface><state_interface name="velocity"/><param name="initial_value">0.0</param><state_interface name="effort"/></joint><joint name="fr3_joint3"><command_interface name="position"/><command_interface name="velocity"/><command_interface name="effort"/><!-- State Interfaces --><state_interface name="position"><param name="initial_value">0.0</param></state_interface><state_interface name="velocity"/><param name="initial_value">0.0</param><state_interface name="effort"/></joint><joint name="fr3_joint4"><command_interface name="position"/><command_interface name="velocity"/><command_interface name="effort"/><!-- State Interfaces --><state_interface name="position"><param name="initial_value">-2.356194490192345</param></state_interface><state_interface name="velocity"/><param name="initial_value">0.0</param><state_interface name="effort"/></joint><joint name="fr3_joint5"><command_interface name="position"/><command_interface name="velocity"/><command_interface name="effort"/><!-- State Interfaces --><state_interface name="position"><param name="initial_value">0.0</param></state_interface><state_interface name="velocity"/><param name="initial_value">0.0</param><state_interface name="effort"/></joint><joint name="fr3_joint6"><command_interface name="position"/><command_interface name="velocity"/><command_interface name="effort"/><!-- State Interfaces --><state_interface name="position"><param name="initial_value">1.5707963267948966</param></state_interface><state_interface name="velocity"/><param name="initial_value">0.0</param><state_interface name="effort"/></joint><joint name="fr3_joint7"><command_interface name="position"/><command_interface name="velocity"/><command_interface name="effort"/><!-- State Interfaces --><state_interface name="position"><param name="initial_value">0.7853981633974483</param></state_interface><state_interface name="velocity"/><param name="initial_value">0.0</param><state_interface name="effort"/></joint></ros2_control><link name="rgbd_camera_frame"><visual><origin rpy="0 0 0" xyz="0 0 0"/><geometry><mesh filename="/home/y/colcon_ws/src/Use_Pkg/QP_IBVS_Project/Robot_in_Igniton_Gazebo/aubo_robot_pkg/meshes/depth_d435/d435.dae" scale="1.0 1.0 1.0"/></geometry><material name="gray"><color rgba="0.8 0.8 0.8 1.0"/></material></visual></link><joint name="rgbd_camera_joint" type="fixed"><origin rpy="0 -1.5708 -1.5708" xyz="0.0 0.05 0.03"/><parent link="fr3_link8"/><child link="rgbd_camera_frame"/></joint><gazebo reference="rgbd_camera_frame"><sensor name="rgbd_camera" type="rgbd_camera"><ignition_frame_id>rgbd_camera_frame</ignition_frame_id><camera name="rgbd_camera_frame"><horizontal_fov>1.3962634</horizontal_fov><lens><intrinsics><fx>277.1</fx><fy>277.1</fy><cx>160.5</cx><cy>120.5</cy><s>0</s></intrinsics></lens><distortion><k1>0.104207</k1><k2>-0.255558</k2><k3>0.128694</k3><p1>0.000512</p1><p2>0.000319</p2><center>0.5 0.5</center></distortion><image><width>640</width><height>480</height><format>L8</format></image><clip><near>0.01</near><far>300</far></clip><depth_camera><clip><near>0.1</near><far>10</far></clip></depth_camera><noise><type>gaussian</type><mean>0</mean><stddev>0.003</stddev></noise></camera><always_on>1</always_on><update_rate>10</update_rate><visualize>1</visualize><topic>/d435/depth_camera</topic></sensor></gazebo><!-- 3. 定义“小车→机械臂”的固定关节(修正child link为base) --><joint name="car_to_arm_joint" type="fixed"><parent link="base_link"/><!-- 小车根链接(来自mbot_base_gazebo.xacro) --><child link="base"/><!-- 机械臂根链接(来自fr3.urdf.xacro的base) --><origin rpy="0 0 0" xyz="0 0 0.2"/><!-- 机械臂安装高度 --></joint></robot> <?xml version="1.0" ?><!-- =================================================================================== --><!-- | This document was autogenerated by xacro from /home/y/colcon_ws/install/franka_robot_ign_pkg/share/franka_robot_ign_pkg/urdf/combined_car_arm.xacro | --><!-- | EDITING THIS FILE BY HAND IS NOT RECOMMENDED | --><!-- =================================================================================== --><robot name="combined_car_arm"><!-- Defining the colors used in this robot --><material name="yellow"><color rgba="1 0.4 0 1"/></material><material name="black"><color rgba="0 0 0 0.95"/></material><material name="gray"><color rgba="0.75 0.75 0.75 1"/></material><link name="base_footprint"><visual><origin rpy="0 0 0" xyz="0 0 0"/><geometry><box size="0.001 0.001 0.001"/></geometry></visual></link><gazebo reference="base_footprint"><turnGravityOff>false</turnGravityOff></gazebo><joint name="base_footprint_joint" type="fixed"><origin rpy="0 0 0" xyz="0 0 0.11"/><parent link="base_footprint"/><child link="base_link"/></joint><link name="base_link"><visual><origin rpy="0 0 0" xyz=" 0 0 0"/><geometry><cylinder length="0.16" radius="0.2"/></geometry><material name="yellow"/></visual><collision><origin rpy="0 0 0" xyz=" 0 0 0"/><geometry><cylinder length="0.16" radius="0.2"/></geometry></collision><inertial><mass value="1"/><inertia ixx="0.012133333333333336" ixy="0" ixz="0" iyy="0.012133333333333336" iyz="0" izz="0.020000000000000004"/></inertial></link><gazebo reference="base_link"><material>Gazebo/Blue</material></gazebo><!-- ros2_control 硬件接口配置 --><ros2_control name="MbotBase" type="system"><hardware><plugin>ign_ros2_control/IgnitionSystem</plugin><!-- 适配Ignition的硬件插件 --></hardware><!-- 左车轮接口(速度控制) --><joint name="left_wheel_joint"><command_interface name="velocity"/><state_interface name="velocity"/><state_interface name="position"/></joint><!-- 右车轮接口(速度控制) --><joint name="right_wheel_joint"><command_interface name="velocity"/><state_interface name="velocity"/><state_interface name="position"/></joint></ros2_control><joint name="left_wheel_joint" type="continuous"><origin rpy="0 0 0" xyz="0 0.19 -0.05"/><parent link="base_link"/><child link="left_wheel_link"/><axis xyz="0 1 0"/></joint><link name="left_wheel_link"><visual><origin rpy="1.5707963 0 0" xyz="0 0 0"/><geometry><cylinder length="0.025" radius="0.06"/></geometry><material name="gray"/></visual><collision><origin rpy="1.5707963 0 0" xyz="0 0 0"/><geometry><cylinder length="0.025" radius="0.06"/></geometry></collision><inertial><mass value="0.2"/><inertia ixx="0.00019041666666666667" ixy="0" ixz="0" iyy="0.00019041666666666667" iyz="0" izz="0.00035999999999999997"/></inertial></link><gazebo reference="left_wheel_link"><material>Gazebo/Gray</material><mu1>100000.0</mu1><mu2>100000.0</mu2></gazebo><!-- Transmission is important to link the joints and the controller --><transmission name="left_wheel_joint_trans"><type>transmission_interface/SimpleTransmission</type><joint name="left_wheel_joint"><hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface></joint><actuator name="left_wheel_joint_motor"><hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface><mechanicalReduction>1</mechanicalReduction></actuator></transmission><joint name="right_wheel_joint" type="continuous"><origin rpy="0 0 0" xyz="0 -0.19 -0.05"/><parent link="base_link"/><child link="right_wheel_link"/><axis xyz="0 1 0"/></joint><link name="right_wheel_link"><visual><origin rpy="1.5707963 0 0" xyz="0 0 0"/><geometry><cylinder length="0.025" radius="0.06"/></geometry><material name="gray"/></visual><collision><origin rpy="1.5707963 0 0" xyz="0 0 0"/><geometry><cylinder length="0.025" radius="0.06"/></geometry></collision><inertial><mass value="0.2"/><inertia ixx="0.00019041666666666667" ixy="0" ixz="0" iyy="0.00019041666666666667" iyz="0" izz="0.00035999999999999997"/></inertial></link><gazebo reference="right_wheel_link"><material>Gazebo/Gray</material><mu1>100000.0</mu1><mu2>100000.0</mu2></gazebo><!-- Transmission is important to link the joints and the controller --><transmission name="right_wheel_joint_trans"><type>transmission_interface/SimpleTransmission</type><joint name="right_wheel_joint"><hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface></joint><actuator name="right_wheel_joint_motor"><hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface><mechanicalReduction>1</mechanicalReduction></actuator></transmission><joint name="front_caster_joint" type="fixed"><origin rpy="0 0 0" xyz="-0.18 0 -0.095"/><parent link="base_link"/><child link="front_caster_link"/></joint><link name="front_caster_link"><visual><origin rpy="0 0 0" xyz="0 0 0"/><geometry><sphere radius="0.015"/></geometry><material name="black"/></visual><collision><origin rpy="0 0 0" xyz="0 0 0"/><geometry><sphere radius="0.015"/></geometry></collision><inertial><mass value="0.2"/><inertia ixx="1.7999999999999997e-05" ixy="0" ixz="0" iyy="1.7999999999999997e-05" iyz="0" izz="1.7999999999999997e-05"/></inertial></link><gazebo reference="front_caster_link"><material>Gazebo/Black</material></gazebo><joint name="back_caster_joint" type="fixed"><origin rpy="0 0 0" xyz="0.18 0 -0.095"/><parent link="base_link"/><child link="back_caster_link"/></joint><link name="back_caster_link"><visual><origin rpy="0 0 0" xyz="0 0 0"/><geometry><sphere radius="0.015"/></geometry><material name="black"/></visual><collision><origin rpy="0 0 0" xyz="0 0 0"/><geometry><sphere radius="0.015"/></geometry></collision><inertial><mass value="0.2"/><inertia ixx="1.7999999999999997e-05" ixy="0" ixz="0" iyy="1.7999999999999997e-05" iyz="0" izz="1.7999999999999997e-05"/></inertial></link><gazebo reference="back_caster_link"><material>Gazebo/Black</material></gazebo><!-- controller --><!-- 小车根链接:base_link --><!-- safety_distance: Minimum safety distance in [m] by which the collision volumes are expanded and which is enforced during robot motions --><!-- arm_id: Namespace of the robot arm. Serves to differentiate between arms in case of multiple instances. --><!-- joint_limits: description of the joint limits that comes from a YAML file. Example definition: ${xacro.load_yaml('$(find franka_description)/robots/fr3/joint_limits.yaml')} --><!-- kinematics: description of the kinematics that comes from a YAML file. Example definition: ${xacro.load_yaml('$(find franka_description)/robots/fr3/kinematics.yaml')} --><!-- inertials: description of the inertials that comes from a YAML file. Example definition: ${xacro.load_yaml('$(find franka_description)/robots/fr3/inertials.yaml')} --><!-- dynamics: description of the dynamics that comes from a YAML file. Example definition: ${xacro.load_yaml('$(find franka_description)/robots/fr3/dynamics.yaml')} --><link name="base"> </link><joint name="fr3_base_joint" type="fixed"><parent link="base"/><child link="fr3_link0"/><origin rpy="0 0 0" xyz="0 0 0"/></joint><!-- sub-link defining detailed meshes for collision with environment --><link name="fr3_link0"><visual name="fr3_link0_visual"><geometry><mesh filename="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/visual/link0.dae"/></geometry></visual><collision name="fr3_link0_collision"><geometry><mesh filename="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/collision/link0.stl"/></geometry></collision><inertial><origin rpy="0 0 0" xyz="-0.0172 0.0004 0.0745"/><mass value="2.3966"/><inertia ixx="0.009" ixy="0.0" ixz="0.002" iyy="0.0115" iyz="0.0" izz="0.0085"/></inertial></link><!-- sub-link defining detailed meshes for collision with environment --><link name="fr3_link1"><visual name="fr3_link1_visual"><geometry><mesh filename="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/visual/link1.dae"/></geometry></visual><collision name="fr3_link1_collision"><geometry><mesh filename="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/collision/link1.stl"/></geometry></collision><inertial><origin rpy="0 0 0" xyz="0.0000004128 -0.0181251324 -0.0386035970"/><mass value="2.9274653454"/><inertia ixx="0.023927316485107913" ixy="1.3317903455714081e-05" ixz="-0.00011404774918616684" iyy="0.0224821613275756" iyz="-0.0019950320628240115" izz="0.006350098258530016"/></inertial></link><joint name="fr3_joint1" type="revolute"><origin rpy="0 0 0" xyz="0 0 0.333"/><parent link="fr3_link0"/><child link="fr3_link1"/><axis xyz="0 0 1"/><limit effort="87.0" lower="-2.7437" upper="2.7437" velocity="2.62"/><safety_controller k_position="100.0" k_velocity="40.0" soft_lower_limit="-2.7437" soft_upper_limit="2.7437"/><dynamics D="1" K="7000" damping="0.003" friction="0.2" mu_coulomb="0" mu_viscous="16"/></joint><!-- sub-link defining detailed meshes for collision with environment --><link name="fr3_link2"><visual name="fr3_link2_visual"><geometry><mesh filename="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/visual/link2.dae"/></geometry></visual><collision name="fr3_link2_collision"><geometry><mesh filename="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/collision/link2.stl"/></geometry></collision><inertial><origin rpy="0 0 0" xyz="0.0031828864 -0.0743221644 0.0088146084"/><mass value="2.9355370338"/><inertia ixx="0.041938946257609425" ixy="0.00020257331521090626" ixz="0.004077784227179924" iyy="0.02514514885014724" iyz="-0.0042252158006570156" izz="0.06170214472888839"/></inertial></link><joint name="fr3_joint2" type="revolute"><origin rpy="-1.570796326794897 0 0" xyz="0 0 0"/><parent link="fr3_link1"/><child link="fr3_link2"/><axis xyz="0 0 1"/><limit effort="87.0" lower="-1.7837" upper="1.7837" velocity="2.62"/><safety_controller k_position="100.0" k_velocity="40.0" soft_lower_limit="-1.7837" soft_upper_limit="1.7837"/><dynamics D="1" K="7000" damping="0.003" friction="0.2" mu_coulomb="0" mu_viscous="16"/></joint><!-- sub-link defining detailed meshes for collision with environment --><link name="fr3_link3"><visual name="fr3_link3_visual"><geometry><mesh filename="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/visual/link3.dae"/></geometry></visual><collision name="fr3_link3_collision"><geometry><mesh filename="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/collision/link3.stl"/></geometry></collision><inertial><origin rpy="0 0 0" xyz="0.0407015686 -0.0048200565 -0.0289730823"/><mass value="2.2449013699"/><inertia ixx="0.02410142547240885" ixy="0.002404694559042109" ixz="-0.002856269270114313" iyy="0.01974053266708178" iyz="-0.002104212683891874" izz="0.019044494482244823"/></inertial></link><joint name="fr3_joint3" type="revolute"><origin rpy="1.570796326794897 0 0" xyz="0 -0.316 0"/><parent link="fr3_link2"/><child link="fr3_link3"/><axis xyz="0 0 1"/><limit effort="87.0" lower="-2.9007" upper="2.9007" velocity="2.62"/><safety_controller k_position="100.0" k_velocity="40.0" soft_lower_limit="-2.9007" soft_upper_limit="2.9007"/><dynamics D="1" K="7000" damping="0.003" friction="0.2" mu_coulomb="0" mu_viscous="16"/></joint><!-- sub-link defining detailed meshes for collision with environment --><link name="fr3_link4"><visual name="fr3_link4_visual"><geometry><mesh filename="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/visual/link4.dae"/></geometry></visual><collision name="fr3_link4_collision"><geometry><mesh filename="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/collision/link4.stl"/></geometry></collision><inertial><origin rpy="0 0 0" xyz="-0.0459100965 0.0630492960 -0.0085187868"/><mass value="2.6155955791"/><inertia ixx="0.03452998321913202" ixy="0.01322552265982813" ixz="0.01015142998484113" iyy="0.028881621933049058" iyz="-0.0009762833870704552" izz="0.04125471171146641"/></inertial></link><joint name="fr3_joint4" type="revolute"><origin rpy="1.570796326794897 0 0" xyz="0.0825 0 0"/><parent link="fr3_link3"/><child link="fr3_link4"/><axis xyz="0 0 1"/><limit effort="87.0" lower="-3.0421" upper="-0.1518" velocity="2.62"/><safety_controller k_position="100.0" k_velocity="40.0" soft_lower_limit="-3.0421" soft_upper_limit="-0.1518"/><dynamics D="1" K="7000" damping="0.003" friction="0.2" mu_coulomb="0" mu_viscous="16"/></joint><!-- sub-link defining detailed meshes for collision with environment --><link name="fr3_link5"><visual name="fr3_link5_visual"><geometry><mesh filename="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/visual/link5.dae"/></geometry></visual><collision name="fr3_link5_collision"><geometry><mesh filename="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/collision/link5.stl"/></geometry></collision><inertial><origin rpy="0 0 0" xyz="-0.0016039605 0.0292536262 -0.0972965990"/><mass value="2.3271207594"/><inertia ixx="0.051610278463662895" ixy="-0.005715173387783472" ixz="-0.0035673167625872135" iyy="0.04787729713371481" iyz="0.010673985108535986" izz="0.016423625579357254"/></inertial></link><joint name="fr3_joint5" type="revolute"><origin rpy="-1.570796326794897 0 0" xyz="-0.0825 0.384 0"/><parent link="fr3_link4"/><child link="fr3_link5"/><axis xyz="0 0 1"/><limit effort="12.0" lower="-2.8065" upper="2.8065" velocity="5.26"/><safety_controller k_position="100.0" k_velocity="40.0" soft_lower_limit="-2.8065" soft_upper_limit="2.8065"/><dynamics D="1" K="7000" damping="0.003" friction="0.2" mu_coulomb="0" mu_viscous="16"/></joint><!-- sub-link defining detailed meshes for collision with environment --><link name="fr3_link6"><visual name="fr3_link6_visual"><geometry><mesh filename="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/visual/link6.dae"/></geometry></visual><collision name="fr3_link6_collision"><geometry><mesh filename="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/collision/link6.stl"/></geometry></collision><inertial><origin rpy="0 0 0" xyz="0.0597131221 -0.0410294666 -0.0101692726"/><mass value="1.8170376524"/><inertia ixx="0.005412333594383447" ixy="0.006193456360285834" ixz="0.0014219289306117652" iyy="0.014058329545509979" iyz="-0.0013140753741120031" izz="0.016080817924212554"/></inertial></link><joint name="fr3_joint6" type="revolute"><origin rpy="1.570796326794897 0 0" xyz="0 0 0"/><parent link="fr3_link5"/><child link="fr3_link6"/><axis xyz="0 0 1"/><limit effort="12.0" lower="0.5445" upper="4.5169" velocity="4.18"/><safety_controller k_position="100.0" k_velocity="40.0" soft_lower_limit="0.5445" soft_upper_limit="4.5169"/><dynamics D="1" K="7000" damping="0.003" friction="0.2" mu_coulomb="0" mu_viscous="16"/></joint><!-- sub-link defining detailed meshes for collision with environment --><link name="fr3_link7"><visual name="fr3_link7_visual"><geometry><mesh filename="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/visual/link7.dae"/></geometry></visual><collision name="fr3_link7_collision"><geometry><mesh filename="/home/y/colcon_ws/install/franka_description/share/franka_description/meshes/robot_arms/fr3/collision/link7.stl"/></geometry></collision><inertial><origin rpy="0 0 0" xyz="0.0045225817 0.0086261921 -0.0161633251"/><mass value="0.6271432862"/><inertia ixx="0.00021092389150104718" ixy="-2.433299114461931e-05" ixz="4.564480393778983e-05" iyy="0.00017718568002411474" iyz="8.744070223226438e-05" izz="5.993190599659971e-05"/></inertial></link><joint name="fr3_joint7" type="revolute"><origin rpy="1.570796326794897 0 0" xyz="0.088 0 0"/><parent link="fr3_link6"/><child link="fr3_link7"/><axis xyz="0 0 1"/><limit effort="12.0" lower="-3.0159" upper="3.0159" velocity="5.26"/><safety_controller k_position="100.0" k_velocity="40.0" soft_lower_limit="-3.0159" soft_upper_limit="3.0159"/><dynamics D="1" K="7000" damping="0.003" friction="0.2" mu_coulomb="0" mu_viscous="16"/></joint><link name="fr3_link8"/><joint name="fr3_joint8" type="fixed"><origin rpy="0 0 0" xyz="0 0 0.107"/><parent link="fr3_link7"/><child link="fr3_link8"/></joint><joint name="fr3_hand_joint" type="fixed"><parent link="fr3_link8"/><child link="fr3_hand"/><origin rpy="0 0 -0.7853981633974483" xyz="0 0 0"/></joint><!-- sub-link defining detailed meshes for collision with environment --><link name="fr3_hand"><visual name="fr3_hand_visual"><geometry><mesh filename="package://franka_description/meshes/robot_ee/franka_hand_white/visual/hand.dae"/></geometry></visual><collision name="fr3_hand_collision"><geometry><mesh filename="package://franka_description/meshes/robot_ee/franka_hand_white/collision/hand.stl"/></geometry></collision><inertial><origin rpy="0 0 0" xyz="-0.0000376 0.0119128 0.0207260"/><mass value="0.6544"/><inertia ixx="0.00186" ixy="0.0" ixz="0.0" iyy="0.0003" iyz="-2e-05" izz="0.00174"/></inertial></link><!-- Define the hand_tcp frame --><link name="fr3_hand_tcp"/><joint name="fr3_hand_tcp_joint" type="fixed"><origin rpy="0 0 0" xyz="0 0 0.1034"/><parent link="fr3_hand"/><child link="fr3_hand_tcp"/></joint><link name="fr3_leftfinger"><visual name="fr3_leftfinger_visual"><geometry><mesh filename="package://franka_description/meshes/robot_ee/franka_hand_white/visual/finger.dae"/></geometry></visual><!-- screw mount --><collision><origin rpy="0 0 0" xyz="0 18.5e-3 11e-3"/><geometry><box size="22e-3 15e-3 20e-3"/></geometry></collision><!-- cartriage sledge --><collision><origin rpy="0 0 0" xyz="0 6.8e-3 2.2e-3"/><geometry><box size="22e-3 8.8e-3 3.8e-3"/></geometry></collision><!-- diagonal finger --><collision><origin rpy="0.5235987755982988 0 0" xyz="0 15.9e-3 28.35e-3"/><geometry><box size="17.5e-3 7e-3 23.5e-3"/></geometry></collision><!-- rubber tip with which to grasp --><collision><origin rpy="0 0 0" xyz="0 7.58e-3 45.25e-3"/><geometry><box size="17.5e-3 15.2e-3 18.5e-3"/></geometry></collision><inertial><origin rpy="0 0 0" xyz="0 0.0152850 0.0219675"/><mass value="0.0291"/><inertia ixx="8.49e-06" ixy="0.0" ixz="0.0" iyy="8.53e-06" iyz="-1.06e-06" izz="1.77e-06"/></inertial></link><link name="fr3_rightfinger"><visual name="fr3_rightfinger_visual"><origin rpy="0 0 0" xyz="0 0 0"/><geometry><mesh filename="package://franka_description/meshes/robot_ee/franka_hand_white/visual/finger.dae"/></geometry></visual><!-- screw mount --><collision><origin rpy="0 0 0" xyz="0 18.5e-3 11e-3"/><geometry><box size="22e-3 15e-3 20e-3"/></geometry></collision><!-- cartriage sledge --><collision><origin rpy="0 0 0" xyz="0 6.8e-3 2.2e-3"/><geometry><box size="22e-3 8.8e-3 3.8e-3"/></geometry></collision><!-- diagonal finger --><collision><origin rpy="-0.5235987755982988 0 3.141592653589793" xyz="0 15.9e-3 28.35e-3"/><geometry><box size="17.5e-3 7e-3 23.5e-3"/></geometry></collision><!-- rubber tip with which to grasp --><collision><origin rpy="0 0 0" xyz="0 7.58e-3 45.25e-3"/><geometry><box size="17.5e-3 15.2e-3 18.5e-3"/></geometry></collision><inertial><origin rpy="0 0 0" xyz="0 0.0152850 0.0219675"/><mass value="0.0291"/><inertia ixx="8.49e-06" ixy="0.0" ixz="0.0" iyy="8.53e-06" iyz="-1.06e-06" izz="1.77e-06"/></inertial></link><joint name="fr3_finger_joint1" type="prismatic"><parent link="fr3_hand"/><child link="fr3_leftfinger"/><origin rpy="0 0 0" xyz="0 0 0.0584"/><axis xyz="0 1 0"/><limit effort="100" lower="0.0" upper="0.04" velocity="0.2"/><dynamics damping="0.3"/></joint><joint name="fr3_finger_joint2" type="prismatic"><parent link="fr3_hand"/><child link="fr3_rightfinger"/><origin rpy="0 0 3.141592653589793" xyz="0 0 0.0584"/><axis xyz="0 1 0"/><limit effort="100" lower="0.0" upper="0.04" velocity="0.2"/><mimic joint="fr3_finger_joint1"/><dynamics damping="0.3"/></joint><ros2_control name="FrankaHardwareInterface" type="system"><hardware><param name="arm_id">fr3</param><param name="prefix"></param><plugin>franka_hardware/FrankaHardwareInterface</plugin><param name="robot_ip"></param><param name="arm_prefix"></param></hardware><joint name="fr3_joint1"><command_interface name="position"/><command_interface name="velocity"/><command_interface name="effort"/><!-- State Interfaces --><state_interface name="position"><param name="initial_value">0.0</param></state_interface><state_interface name="velocity"/><param name="initial_value">0.0</param><state_interface name="effort"/></joint><joint name="fr3_joint2"><command_interface name="position"/><command_interface name="velocity"/><command_interface name="effort"/><!-- State Interfaces --><state_interface name="position"><param name="initial_value">-0.7853981633974483</param></state_interface><state_interface name="velocity"/><param name="initial_value">0.0</param><state_interface name="effort"/></joint><joint name="fr3_joint3"><command_interface name="position"/><command_interface name="velocity"/><command_interface name="effort"/><!-- State Interfaces --><state_interface name="position"><param name="initial_value">0.0</param></state_interface><state_interface name="velocity"/><param name="initial_value">0.0</param><state_interface name="effort"/></joint><joint name="fr3_joint4"><command_interface name="position"/><command_interface name="velocity"/><command_interface name="effort"/><!-- State Interfaces --><state_interface name="position"><param name="initial_value">-2.356194490192345</param></state_interface><state_interface name="velocity"/><param name="initial_value">0.0</param><state_interface name="effort"/></joint><joint name="fr3_joint5"><command_interface name="position"/><command_interface name="velocity"/><command_interface name="effort"/><!-- State Interfaces --><state_interface name="position"><param name="initial_value">0.0</param></state_interface><state_interface name="velocity"/><param name="initial_value">0.0</param><state_interface name="effort"/></joint><joint name="fr3_joint6"><command_interface name="position"/><command_interface name="velocity"/><command_interface name="effort"/><!-- State Interfaces --><state_interface name="position"><param name="initial_value">1.5707963267948966</param></state_interface><state_interface name="velocity"/><param name="initial_value">0.0</param><state_interface name="effort"/></joint><joint name="fr3_joint7"><command_interface name="position"/><command_interface name="velocity"/><command_interface name="effort"/><!-- State Interfaces --><state_interface name="position"><param name="initial_value">0.7853981633974483</param></state_interface><state_interface name="velocity"/><param name="initial_value">0.0</param><state_interface name="effort"/></joint></ros2_control><link name="rgbd_camera_frame"><visual><origin rpy="0 0 0" xyz="0 0 0"/><geometry><mesh filename="/home/y/colcon_ws/src/Use_Pkg/QP_IBVS_Project/Robot_in_Igniton_Gazebo/aubo_robot_pkg/meshes/depth_d435/d435.dae" scale="1.0 1.0 1.0"/></geometry><material name="gray"><color rgba="0.8 0.8 0.8 1.0"/></material></visual></link><joint name="rgbd_camera_joint" type="fixed"><origin rpy="0 -1.5708 -1.5708" xyz="0.0 0.05 0.03"/><parent link="fr3_link8"/><child link="rgbd_camera_frame"/></joint><gazebo reference="rgbd_camera_frame"><sensor name="rgbd_camera" type="rgbd_camera"><ignition_frame_id>rgbd_camera_frame</ignition_frame_id><camera name="rgbd_camera_frame"><horizontal_fov>1.3962634</horizontal_fov><lens><intrinsics><fx>277.1</fx><fy>277.1</fy><cx>160.5</cx><cy>120.5</cy><s>0</s></intrinsics></lens><distortion><k1>0.104207</k1><k2>-0.255558</k2><k3>0.128694</k3><p1>0.000512</p1><p2>0.000319</p2><center>0.5 0.5</center></distortion><image><width>640</width><height>480</height><format>L8</format></image><clip><near>0.01</near><far>300</far></clip><depth_camera><clip><near>0.1</near><far>10</far></clip></depth_camera><noise><type>gaussian</type><mean>0</mean><stddev>0.003</stddev></noise></camera><always_on>1</always_on><update_rate>10</update_rate><visualize>1</visualize><topic>/d435/depth_camera</topic></sensor></gazebo><!-- 3. 定义“小车→机械臂”的固定关节(修正child link为base) --><joint name="car_to_arm_joint" type="fixed"><parent link="base_link"/><!-- 小车根链接(来自mbot_base_gazebo.xacro) --><child link="base"/><!-- 机械臂根链接(来自fr3.urdf.xacro的base) --><origin rpy="0 0 0" xyz="0 0 0.2"/><!-- 机械臂安装高度 --></joint></robot> y@y-Dell-G15-5511:~/colcon_ws$ python3 - <<'PY' import xml.etree.ElementTree aspython3 - <<'PY' import xml.etree.ElementTree as ET, sys, os是刚才生成的文件 p = '/tmp/robot_clean.urdf' # <- 确保这里是刚才生成的文件 if not os.path.isfile(p):", p); sys.exit(1) print("No file found:", p); sys.exit(1) s = open(p,'r',encoding='utf-8').read() try:root = ET.fromstring(s) root = ET.fromstring(s) except Exception as e:rror:", e) print("XML parse error:", e) sys.exit(1)'name') for j in root.findall('.//joint')] names = [j.get('name') for j in root.findall('.//joint')] print("Found {} joints:".format(len(names))) for n in names: print(n) PY Found 31 joints: base_footprint_joint left_wheel_joint right_wheel_joint left_wheel_joint left_wheel_joint right_wheel_joint right_wheel_joint front_caster_joint back_caster_joint fr3_base_joint fr3_joint1 fr3_joint2 fr3_joint3 fr3_joint4 fr3_joint5 fr3_joint6 fr3_joint7 fr3_joint8 fr3_hand_joint fr3_hand_tcp_joint fr3_finger_joint1 fr3_finger_joint2 fr3_joint1 fr3_joint2 fr3_joint3 fr3_joint4 fr3_joint5 fr3_joint6 fr3_joint7 rgbd_camera_joint car_to_arm_joint y@y-Dell-G15-5511:~/colcon_ws$ 说实话,检测这个有什么用吗?是在这个命令里生成了一个urdf吧,但是这个会对我的代码有影响吗??还是只是为了看看?
最新发布
10-21
if self.device.type != 'cpu': Loading checkpoint shards: 100%|████████████████████████████████████████████████████████████| 4/4 [00:21<00:00, 5.26s/it] *****************模型加载成功! ****************[+] load time: 25.5681s [+] inference time: 4.18696s [' <s> Once upon a time, \xa0\xa0<unk><unk> <<unk><unk><unk> <<unk><unk> <<unk><unk><unk><unk><unk><unk><unk><unk> <<unk><unk><unk><unk><unk><unk><unk><unk><stoname'] 为什么推理输出是[' <s> Once upon a time, \xa0\xa0<unk><unk> <<unk><unk><unk> <<unk><unk> <<unk><unk><unk><unk><unk><unk><unk><unk> <<unk><unk><unk><unk><unk><unk><unk><unk><stoname']这样的????? 我编写的代码如下: import time import torch, torch_npu from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig # 替换成本地的模型权重路径 MODEL_PATH = "/models/7bv3_vllm" bnb_config = BitsAndBytesConfig( load_in_4bit=True, bnb_4bit_compute_dtype=torch.float16, # Support torch.float16, torch.float32, torch.bfloat16 bnb_4bit_quant_type="nf4", bnb_4bit_use_double_quant=False, bnb_4bit_quant_storage=torch.uint8 ) torch.npu.synchronize() start_time = time.time() model = AutoModelForCausalLM.from_pretrained( MODEL_PATH, device_map={"":0}, quantization_config=bnb_config, low_cpu_mem_usage=True, torch_dtype=torch.float16, # Support torch.float16, torch.float32, torch.bfloat16 use_safetensors=True, trust_remote_code=True ) torch.npu.synchronize() print("*****************模型加载成功!") print(f"****************[+] load time: {time.time() - start_time:.6}s") tokenizer = AutoTokenizer.from_pretrained( MODEL_PATH, trust_remote_code=True, local_files_only=True, use_fast=False ) model.eval() print("*****************分词器加载成功,开始推理!") prompt = "Once upon a time, " inputs = tokenizer([prompt], return_tensors="pt") input_ids = inputs.input_ids.npu() attention_mask = inputs.attention_mask.npu() torch.npu.synchronize() start_time = time.time() generated_ids = model.generate( input_ids=input_ids, attention_mask=attention_mask, max_new_tokens=32, do_sample=False, ) torch.npu.synchronize() print(f"[+] inference time: {time.time() - start_time:.6}s") print(tokenizer.batch_decode(generated_ids)) 有什么问题吗,我加载一个未量化模型,使用bitsandbytes库进行量化推理
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值