翻译:java中怎样使用树结构(How to Use Trees)(二)

博客涉及Java、Swing、HTML和REST等信息技术领域内容,虽未给出具体内容,但这些技术在后端开发、前端开发等方面有重要应用,Java常用于后端,Swing用于桌面应用,HTML是前端基础,REST是接口设计风格。

个性化树显示

     如前所述,树的每一个节点通常有一个图标和一些文字.你可以定制这些图标和文字.

     一个tree通常会展示一些特殊外观来显示节点间的联系.你可以通过简单的几步来自定义这些外观样式.首先,你可以用tree.setRootVisible(true)来显示根节点,用tree.setRootVisible(false)来隐藏根节点.然后,通过调用tree.setShowsRootHandles(true),可以让tree的顶级节点—根节点(如果可见)或者其子节点—展开或者收缩.最后,如果你采用java风格样式,你还可以自定义是否显示线条来展示树节点间的关系.

     默认的,java风格会在节点间画出一个带直角的直线.通过设置Tree.lineStyle属性,你可以指定不同的样式.例如,如果采用java风格,通过调用如下代码,可以用横线来组织各节点.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

use_sim_time: True amcl: ros__parameters: use_sim_time: ${use_sim_time} # 继承全局时间配置 alpha1: 0.2 alpha2: 0.2 alpha3: 0.2 alpha4: 0.2 alpha5: 0.2 base_frame_id: "base_link" beam_skip_distance: 0.5 beam_skip_error_threshold: 0.9 beam_skip_threshold: 0.3 do_beamskip: False global_frame_id: "map" lambda_short: 0.1 laser_likelihood_max_dist: 2.0 laser_max_range: 100.0 laser_min_range: -1.0 laser_model_type: "likelihood_field" max_beams: 60 max_particles: 2000 min_particles: 500 odom_frame_id: "odom" pf_err: 0.05 pf_z: 0.99 recovery_alpha_fast: 0.0 recovery_alpha_slow: 0.0 resample_interval: 1 robot_model_type: "differential" # 根据机器人类型调整(差速/全向) save_pose_rate: 0.5 sigma_hit: 0.2 tf_broadcast: True transform_tolerance: 0.5 update_min_a: 0.2 update_min_d: 0.25 z_hit: 0.5 z_max: 0.05 z_rand: 0.5 z_short: 0.05 # 行为导航器配置 bt_navigator: ros__parameters: use_sim_time: ${use_sim_time} global_frame: map robot_base_frame: base_link odom_topic: /odom # 使用绝对路径确保找到正确的BT文件,避免路径冲突 default_bt_xml_filename: "/opt/ros/humble/share/nav2_bt_navigator/behavior_trees/navigate_to_pose_w_replanning.xml" plugin_lib_names: - nav2_compute_path_to_pose_action_bt_node - nav2_compute_path_through_poses_action_bt_node # 添加路径贯穿多个目标点的插件 - nav2_follow_path_action_bt_node - nav2_back_up_action_bt_node - nav2_spin_action_bt_node - nav2_wait_action_bt_node - nav2_clear_costmap_service_bt_node - nav2_is_stuck_condition_bt_node - nav2_goal_reached_condition_bt_node - nav2_goal_updated_condition_bt_node - nav2_initial_pose_received_condition_bt_node - nav2_reinitialize_global_localization_service_bt_node - nav2_rate_controller_bt_node - nav2_distance_controller_bt_node - nav2_speed_controller_bt_node - nav2_truncate_path_action_bt_node - nav2_goal_updater_node_bt_node - nav2_recovery_node_bt_node - nav2_pipeline_sequence_bt_node - nav2_round_robin_node_bt_node - nav2_transform_available_condition_bt_node - nav2_time_expired_condition_bt_node - nav2_path_expiring_timer_condition - nav2_distance_traveled_condition_bt_node - nav2_remove_passed_goals_action_bt_node # 控制器配置(本地规划) controller_server: ros__parameters: use_sim_time: ${use_sim_time} controller_frequency: 20.0 min_x_velocity_threshold: 0.001 min_y_velocity_threshold: 0.5 # 差速机器人可设为0.0 min_theta_velocity_threshold: 0.001 failure_tolerance: 0.3 progress_checker_plugin: "progress_checker" goal_checker_plugins: ["general_goal_checker"] controller_plugins: ["FollowPath"] # 进度检查器参数 progress_checker: plugin: "nav2_controller::SimpleProgressChecker" required_movement_radius: 0.5 movement_time_allowance: 10.0 # 超时未移动则触发恢复行为 # 目标检查器参数 general_goal_checker: plugin: "nav2_controller::SimpleGoalChecker" xy_goal_tolerance: 0.25 # 位置误差容忍度(米) yaw_goal_tolerance: 0.25 # 角度误差容忍度(弧度) stateful: True # DWB本地规划器参数 FollowPath: plugin: "dwb_core::DWBLocalPlanner" debug_trajectory_details: True min_vel_x: 0.0 max_vel_x: 0.26 # 最大线速度(根据机器人调整) min_vel_y: 0.0 max_vel_y: 0.0 # 差速机器人Y方向速度为0 min_vel_theta: -1.82 max_vel_theta: 1.82 acc_lim_x: 2.5 acc_lim_y: 0.0 acc_lim_theta: 3.2 decel_lim_x: -2.5 decel_lim_y: 0.0 decel_lim_theta: -3.2 vx_samples: 20 vy_samples: 1 # 差速机器人Y方向采样数设为1 vtheta_samples: 20 sim_time: 1.7 linear_granularity: 0.05 angular_granularity: 0.025 transform_tolerance: 0.5 xy_goal_tolerance: 0.25 yaw_goal_tolerance: 0.25 trans_stopped_velocity: 0.25 rot_stopped_velocity: 0.25 prune_plan: True critics: ["RotateToGoal", "Oscillation", "BaseObstacle", "GoalAlign", "PathAlign", "PathDist", "GoalDist"] BaseObstacle.scale: 0.02 PathAlign.scale: 32.0 PathAlign.forward_point_distance: 0.1 GoalAlign.scale: 24.0 GoalAlign.forward_point_distance: 0.1 PathDist.scale: 32.0 GoalDist.scale: 24.0 RotateToGoal.scale: 32.0 RotateToGoal.slowing_factor: 5.0 RotateToGoal.lookahead_time: -1.0 # 局部代价地图配置 local_costmap: local_costmap: ros__parameters: use_sim_time: ${use_sim_time} update_frequency: 5.0 # 更新频率(Hz) publish_frequency: 2.0 # 发布频率(Hz) global_frame: odom # 局部地图参考系(里程计) robot_base_frame: base_link rolling_window: true # 滚动窗口(跟随机器人移动) width: 3 # 宽度(米) height: 3 # 高度(米) resolution: 0.05 # 分辨率(米/格) transform_tolerance: 0.5 plugins: ["voxel_layer", "inflation_layer"] voxel_layer: plugin: "nav2_costmap_2d::VoxelLayer" enabled: True publish_voxel_map: True origin_z: 0.0 z_resolution: 0.05 z_voxels: 16 max_obstacle_height: 2.0 mark_threshold: 0 observation_sources: scan # 激光雷达数据来源 scan: topic: /scan # 激光雷达话题(确保与实际一致) max_obstacle_height: 2.0 clearing: True # 允许清除障碍物 marking: True # 允许标记障碍物 data_type: "LaserScan" raytrace_max_range: 3.0 raytrace_min_range: 0.0 obstacle_max_range: 2.5 obstacle_min_range: 0.0 inflation_layer: plugin: "nav2_costmap_2d::InflationLayer" enabled: True inflation_radius: 0.55 # 膨胀半径(根据机器人半径调整) cost_scaling_factor: 10.0 inflate_unknown: False always_send_full_costmap: True # 全局代价地图配置 global_costmap: global_costmap: ros__parameters: use_sim_time: ${use_sim_time} update_frequency: 1.0 publish_frequency: 1.0 global_frame: map # 全局地图参考系(地图) robot_base_frame: base_link robot_radius: 0.22 # 机器人半径(米,根据实际调整) resolution: 0.05 transform_tolerance: 0.2 plugins: ["static_layer", "obstacle_layer", "inflation_layer"] static_layer: plugin: "nav2_costmap_2d::StaticLayer" enabled: True map_subscribe_transient_local: True obstacle_layer: plugin: "nav2_costmap_2d::ObstacleLayer" enabled: True observation_sources: scan scan: topic: /scan max_obstacle_height: 2.0 clearing: True marking: True data_type: "LaserScan" raytrace_max_range: 3.0 raytrace_min_range: 0.0 obstacle_max_range: 2.5 obstacle_min_range: 0.0 inflation_layer: plugin: "nav2_costmap_2d::InflationLayer" enabled: True inflation_radius: 0.55 cost_scaling_factor: 10.0 inflate_unknown: False always_send_full_costmap: True # 地图服务器配置 map_server: ros__parameters: use_sim_time: ${use_sim_time} # 确保地图文件路径正确(.yaml和.pgm文件需在同一目录) yaml_filename: "/home/yahboom/hex_aqacs_planner/map.yaml" # 规划器服务器配置(全局规划) planner_server: ros__parameters: use_sim_time: ${use_sim_time} expected_planner_frequency: 20.0 planner_plugins: ["AQACSPlanner"] # 使用AQACS规划器 AQACSPlanner: # 修正插件名称格式,使用命名空间形式 plugin: "hex_aqacs_planner::AQACSPlanner" alpha: 1.0 beta: 2.0 rho: 0.1 ant_count: 50 q: 100.0 hex_side: 0.1 # 六边形边长(米) # 生命周期管理器配置(关键:管理节点启动顺序) lifecycle_manager_navigation: ros__parameters: use_sim_time: ${use_sim_time} # 节点启动顺序:先启动地图和定位,再启动规划和控制 node_names: ["map_server", "amcl", "planner_server", "controller_server", "bt_navigator"] autostart: True # 自动启动所有节点 bond_timeout: 10000 # 超时时间(毫秒) 帮我修改一下吧
10-27
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值