自主导航nav_test.py代码分析

本文介绍了一个基于ROS的Python脚本,实现机器人在预设地点间的随机导航。通过加载机器人模型和地图信息,脚本能够控制机器人按指定路径移动并停留一段时间。适用于真实环境或模拟器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#这段代码的作用是实现在地图中随机导航。在ros下需要先加载机器人和相关配置,详请参阅 古-月 的博客http://blog.youkuaiyun.com/hcx25909/article/details/12110959
#这里主要是用于自己来理解这段代码

#!/usr/bin/env python

import rospy
import actionlib
from actionlib_msgs.msg import *
from geometry_msgs.msg import Pose, PoseWithCovarianceStamped, Point, Quaternion, Twist
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
from random import sample
from math import pow, sqrt

class NavTest():
    def __init__(self):
        rospy.init_node('nav_test', anonymous=True)
        
        rospy.on_shutdown(self.shutdown)#rospyAPI:on_shutdown()
        
        # How long in seconds should the robot pause at each location?
        #在每个目标点停留的时间
        self.rest_time = rospy.get_param("~rest_time", 10)#API get_param
        
        # Are we running in the fake simulator?
        #是否是在模拟环境中运行
        self.fake_test = rospy.get_param("~fake_test", False)
        
        # Goal state return values
        #目标状态返回值
        goal_states = ['PENDING', 'ACTIVE', 'PREEMPTED', 
                       'SUCCEEDED', 'ABORTED', 'REJECTED',
                       'PREEMPTING', 'RECALLING', 'RECALLED',
                       'LOST']
        
        # Set up the goal locations. Poses are defined in the map frame.  
        #设置目标位置,在地图坐标系中的姿态
        # An easy way to find the pose coordinates is to point-and-click
        #找到某一姿态的坐标,选中然后单击
        # Nav Goals in RViz when running in the simulator.
        #
        # Pose coordinates are then displayed in the terminal
        # that was used to launch RViz.
        locations = dict()
        #这里定义了六个定位点的姿态
        locations['hall_foyer'] = Pose(Point(0.643, 4.720, 0.000), Quaternion(0.000, 0.000, 0.223, 0.975))
        locations['hall_kitchen'] = Pose(Point(-1.994, 4.382, 0.000), Quaternion(0.000, 0.000, -0.670, 0.743))
        locations['hall_bedroom'] = Pose(Point(-3.719, 4.401, 0.000), Quaternion(0.000, 0.000, 0.733, 0.680))
        locations['living_room_1'] = Pose(Point(0.720, 2.229, 0.000), Quaternion(0.000, 0.000, 0.786, 0.618))
        locations['living_room_2'] = Pose(Point(1.471, 1.007, 0.000), Quaternion(0.000, 0.000, 0.480, 0.877))
        locations['dining_room_1'] = Pose(Point(-0.861, -0.019, 0.000), Quaternion(0.000, 0.000, 0.892, -0.451))
        
        # Publisher to manually control the robot (e.g. to stop it)
        #发布控制机器人的消息
        self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist)
        
        # Subscribe to the move_base action server
        #订阅move_base动作服务
        self.move_base = actionlib.SimpleActionClient("move_base", MoveBaseAction)
        
        rospy.loginfo("Waiting for move_base action server...")
        
        # Wait 60 seconds for the action server to become available
        #等60s
        self.move_base.wait_for_server(rospy.Duration(60))
        
        rospy.loginfo("Connected to move base server")
        
        # A variable to hold the initial pose of the robot to be set by 
        #用户在rviz中设置机器人的初始位姿的变量
        # the user in RViz
        initial_pose = PoseWithCovarianceStamped()
        
        # Variables to keep track of success rate, running time,
        #保存成功率、运行时间、运动距离的变量们
        # and distance traveled
        n_locations = len(locations)
        n_goals = 0
        n_successes = 0
        i = n_locations
        distance_traveled = 0
        start_time = rospy.Time.now()
        running_time = 0
        location = ""
        last_location = ""
        
        # Get the initial pose from the user
        #由用户处获取初始位姿
        rospy.loginfo("*** Click the 2D Pose Estimate button in RViz to set the robot's initial pose...")
        rospy.wait_for_message('initialpose', PoseWithCovarianceStamped)
        self.last_location = Pose()
        rospy.Subscriber('initialpose', PoseWithCovarianceStamped, self.update_initial_pose)
        
        # Make sure we have the initial pose
        #确保有初始位姿
        while initial_pose.header.stamp == "":
            rospy.sleep(1)
            
        rospy.loginfo("Starting navigation test")
        
        # Begin the main loop and run through a sequence of locations
        #开始主循环,跑一个定位的序列
        while not rospy.is_shutdown():
            # If we've gone through the current sequence,
            #如果结束了当前序列,开始一个新的序列
            # start with a new random sequence
            if i == n_locations:
                i = 0
                sequence = sample(locations, n_locations)####
                # Skip over first location if it is the same as
                # the last location
                #如果最后一个位置和第一个位置一样,则跳过第一个位置
                if sequence[0] == last_location:
                    i = 1
            
            # Get the next location in the current sequence
            #获取当前序列中的下一个位置
            location = sequence[i]
                        
            # Keep track of the distance traveled.
            #跟踪行驶的距离
            # Use updated initial pose if available.
            #使用更新的初始位姿
            if initial_pose.header.stamp == "":
                distance = sqrt(pow(locations[location].position.x - 
                                    locations[last_location].position.x, 2) +
                                pow(locations[location].position.y - 
                                    locations[last_location].position.y, 2))
            else:
                rospy.loginfo("Updating current pose.")
                distance = sqrt(pow(locations[location].position.x - 
                                    initial_pose.pose.pose.position.x, 2) +
                                pow(locations[location].position.y - 
                                    initial_pose.pose.pose.position.y, 2))
                initial_pose.header.stamp = ""
            
            # Store the last location for distance calculations
            #存储上一个位置来计算距离
            last_location = location
            
            # Increment the counters
            #计数器增加1
            i += 1
            n_goals += 1
        
            # Set up the next goal location
            #设置下一个目标点
            self.goal = MoveBaseGoal()###
            self.goal.target_pose.pose = locations[location]
            self.goal.target_pose.header.frame_id = 'map'
            self.goal.target_pose.header.stamp = rospy.Time.now()
            
            # Let the user know where the robot is going next
            #告诉用户下一个位置
            rospy.loginfo("Going to: " + str(location))
            
            # Start the robot toward the next location
            #开始向下一个位置前进
            self.move_base.send_goal(self.goal)#move_base.send_goal()
            
            # Allow 5 minutes to get there
            #设置时间,5分钟之内到达
            finished_within_time = self.move_base.wait_for_result(rospy.Duration(300)) 
            
            # Check for success or failure
            #检查是否成功到达
            if not finished_within_time:
                self.move_base.cancel_goal()#move_base.cancle_goal()
                rospy.loginfo("Timed out achieving goal")
            else:
                state = self.move_base.get_state()#move_base.get_state()
                if state == GoalStatus.SUCCEEDED:
                    rospy.loginfo("Goal succeeded!")
                    n_successes += 1
                    distance_traveled += distance
                    rospy.loginfo("State:" + str(state))
                else:
                  rospy.loginfo("Goal failed with error code: " + str(goal_states[state]))
            
            # How long have we been running?
            #已经运行了多长时间
            running_time = rospy.Time.now() - start_time
            running_time = running_time.secs / 60.0
            
            # Print a summary success/failure, distance traveled and time elapsed
            #打印一个总结信息,成功与否,形驶的距离和消耗的时间
            rospy.loginfo("Success so far: " + str(n_successes) + "/" + 
                          str(n_goals) + " = " + 
                          str(100 * n_successes/n_goals) + "%")
            rospy.loginfo("Running time: " + str(trunc(running_time, 1)) + 
                          " min Distance: " + str(trunc(distance_traveled, 1)) + " m")
            rospy.sleep(self.rest_time)
    
    #更新初始位姿的函数        
    def update_initial_pose(self, initial_pose):
        self.initial_pose = initial_pose

    #关机处理函数
    def shutdown(self):
        rospy.loginfo("Stopping the robot...")
        self.move_base.cancel_goal()
        rospy.sleep(2)
        self.cmd_vel_pub.publish(Twist())
        rospy.sleep(1)
      
def trunc(f, n):
    # Truncates/pads a float f to n decimal places without rounding
    #拉长/缩短一个浮点数f到一个n位小数
    slen = len('%.*f' % (n, f))
    return float(str(f)[:slen])

if __name__ == '__main__':
    try:
        NavTest()
        rospy.spin()
    except rospy.ROSInterruptException:
        rospy.loginfo("AMCL navigation test finished.")
原文转自:http://blog.youkuaiyun.com/dulaiduwangduxing/article/details/42967441
. ├── cliff_distance_measurement │ ├── CMakeLists.txt │ ├── include │ │ └── cliff_distance_measurement │ ├── package.xml │ └── src │ ├── core │ ├── ir_ranging.cpp │ └── platform ├── robot_cartographer │ ├── config │ │ └── fishbot_2d.lua │ ├── map │ │ ├── fishbot_map.pgm │ │ └── fishbot_map.yaml │ ├── package.xml │ ├── readme.md │ ├── resource │ │ └── robot_cartographer │ ├── robot_cartographer │ │ ├── __init__.py │ │ └── robot_cartographer.py │ ├── rviz │ ├── setup.cfg │ └── setup.py ├── robot_control_service │ ├── bash │ │ └── pwm_control_setup.sh │ ├── CMakeLists.txt │ ├── config │ │ └── control_params.yaml │ ├── include │ │ └── robot_control_service │ ├── package.xml │ ├── readme.md │ └── src │ ├── control_client_camera.cpp │ ├── control_client_cliff.cpp │ ├── control_client_ir.cpp │ ├── control_client_ir_four.cpp │ ├── control_client_master.cpp │ ├── control_client_ros.cpp │ ├── control_client_ultrasonic.cpp │ ├── control_service.cpp │ ├── DirectMotorControl.cpp │ ├── PIDControl.cpp │ ├── publisher_control_view.cpp │ └── publisher_human_realized.cpp ├── robot_control_view │ ├── config │ │ └── icare_robot.rviz │ ├── __init__.py │ ├── launch │ │ └── start_init_view.launch.py │ ├── package.xml │ ├── resource │ │ └── robot_control_view │ ├── robot_control_view │ │ ├── app │ │ ├── blood_oxygen_pulse │ │ ├── __init__.py │ │ ├── __pycache__ │ │ ├── robot_automatic_cruise_server.py │ │ ├── robot_automatic_recharge_server.py │ │ ├── robot_automatic_slam_server.py │ │ ├── robot_blood_oxygen_pulse.py │ │ ├── robot_city_locator_node.py │ │ ├── robot_control_policy_server.py │ │ ├── robot_local_websocket.py │ │ ├── robot_log_clear_node.py │ │ ├── robot_main_back_server.py │ │ ├── robot_network_publisher.py │ │ ├── robot_network_server.py │ │ ├── robot_odom_publisher.py │ │ ├── robot_speech_server.py │ │ ├── robot_system_info_node.py │ │ ├── robot_ultrasonic_policy_node.py │ │ ├── robot_view_manager_node.py │ │ ├── robot_websockets_client.py │ │ ├── robot_websockets_server.py │ │ ├── robot_wifi_server_node.py │ │ ├── start_account_view.py │ │ ├── start_bluetooth_view.py │ │ ├── start_chat_view.py │ │ ├── start_clock_view.py │ │ ├── start_feedback_view.py │ │ ├── start_health_view.py │ │ ├── start_init_view.py │ │ ├── start_lifecycle_view.py │ │ ├── start_main_view.py │ │ ├── start_member_view.py │ │ ├── start_movie_view.py │ │ ├── start_music_view.py │ │ ├── start_radio_view.py │ │ ├── start_schedule_view.py │ │ ├── start_setting_view.py │ │ ├── start_test_view.py │ │ ├── start_view_manager.py │ │ ├── start_weather_view.py │ │ └── start_wifi_view.py │ ├── setup.cfg │ ├── setup.py │ ├── test │ │ ├── my_test.py │ │ ├── test_copyright.py │ │ ├── test_flake8.py │ │ └── test_pep257.py │ └── urdf │ ├── first_robot.urdf.xacro │ ├── fishbot.urdf │ ├── fishbot.urdf.xacro │ ├── fist_robot.urdf │ ├── icare_robot.urdf │ ├── icare_robot.urdf.xacro │ ├── ramand.md │ └── xacro_template.xacro ├── robot_costmap_filters │ ├── CMakeLists.txt │ ├── include │ │ └── robot_costmap_filters │ ├── launch │ │ ├── start_costmap_filter_info_keepout.launch.py │ │ ├── start_costmap_filter_info.launch.py │ │ └── start_costmap_filter_info_speedlimit.launch.py │ ├── package.xml │ ├── params │ │ ├── filter_info.yaml │ │ ├── filter_masks.yaml │ │ ├── keepout_mask.pgm │ │ ├── keepout_mask.yaml │ │ ├── keepout_params.yaml │ │ ├── speedlimit_params.yaml │ │ ├── speed_mask.pgm │ │ └── speed_mask.yaml │ ├── readme.md │ └── src ├── robot_description │ ├── launch │ │ └── gazebo.launch.py │ ├── package.xml │ ├── readme.md │ ├── resource │ │ └── robot_description │ ├── robot_description │ │ └── __init__.py │ ├── rviz │ │ └── urdf_config.rviz │ ├── setup.cfg │ ├── setup.py │ ├── urdf │ │ ├── fishbot_gazebo.urdf │ │ ├── fishbot_v0.0.urdf │ │ ├── fishbot_v1.0.0.urdf │ │ ├── test.urdf │ │ └── three_wheeled_car_model.urdf │ └── worlds │ └── empty_world.world ├── robot_interfaces │ ├── CMakeLists.txt │ ├── include │ │ └── robot_interfaces │ ├── msg │ │ ├── AlarmClockMsg.msg │ │ ├── CameraMark.msg │ │ ├── DualRange.msg │ │ ├── HuoerSpeed.msg │ │ ├── IrSensorArray.msg │ │ ├── IrSignal.msg │ │ ├── NavigatorResult.msg │ │ ├── NavigatorStatus.msg │ │ ├── NetworkDataMsg.msg │ │ ├── PoseData.msg │ │ ├── RobotSpeed.msg │ │ ├── SensorStatus.msg │ │ ├── TodayWeather.msg │ │ └── WifiDataMsg.msg │ ├── package.xml │ ├── readme.md │ ├── src │ └── srv │ ├── LightingControl.srv │ ├── MotorControl.srv │ ├── NewMotorControl.srv │ ├── SetGoal.srv │ ├── StringPair.srv │ ├── String.srv │ └── VoicePlayer.srv ├── robot_launch │ ├── config │ │ └── odom_imu_ekf.yaml │ ├── launch │ │ ├── start_all_base_sensor.launch.py │ │ ├── start_cartographer.launch.py │ │ ├── start_control_service.launch.py │ │ ├── start_navigation.launch.py │ │ ├── start_navigation_service.launch.py │ │ ├── start_navigation_speed_mask.launch.py │ │ ├── start_navigation_with_speed_and_keepout.launch.py │ │ ├── start_ros2.launch.py │ │ ├── test_camera_2.launch.py │ │ ├── test_camera.launch.py │ │ ├── test_car_model.launch.py │ │ ├── test_cliff.launch.py │ │ ├── test_ir.launch.py │ │ ├── test_self_checking.launch.py │ │ ├── test_video_multiplesing.launch.py │ │ └── test_visualization.launch.py │ ├── package.xml │ ├── readme.md │ ├── resource │ │ └── robot_launch │ ├── robot_launch │ │ └── __init__.py │ ├── setup.cfg │ └── setup.py ├── robot_navigation │ ├── config │ │ ├── nav2_filter.yaml │ │ ├── nav2_params.yaml │ │ └── nav2_speed_filter.yaml │ ├── maps │ │ ├── fishbot_map.pgm │ │ └── fishbot_map.yaml │ ├── package.xml │ ├── readme.md │ ├── resource │ │ └── robot_navigation │ ├── robot_navigation │ │ ├── __init__.py │ │ └── robot_navigation.py │ ├── setup.cfg │ └── setup.py ├── robot_navigation2_service │ ├── package.xml │ ├── readme.md │ ├── resource │ │ └── robot_navigation2_service │ ├── robot_navigation2_service │ │ ├── camera_follower_client.py │ │ ├── go_to_pose_service.py │ │ ├── __init__.py │ │ ├── leave_no_parking_zone_client_test_2.py │ │ ├── pose_init.py │ │ ├── real_time_point_client.py │ │ ├── recharge_point_client.py │ │ ├── repub_speed_filter_mask.py │ │ └── save_pose.py │ ├── setup.cfg │ └── setup.py ├── robot_sensor │ ├── bash │ │ └── isr_brushless.sh │ ├── CMakeLists.txt │ ├── config │ │ └── sensor_params.yaml │ ├── include │ │ └── robot_sensor │ ├── package.xml │ ├── readme.md │ └── src │ ├── robot_battery_state_publisher.cpp │ ├── robot_battery_voltage_publisher.cpp │ ├── robot_charging_status_publisher.cpp │ ├── robot_cliff_distance_publisher.cpp │ ├── robot_encode_speed_publisher.cpp │ ├── robot_imu_publisher.cpp │ ├── robot_ir_four_signal_publisher.cpp │ ├── robot_ir_signal_publisher.cpp │ ├── robot_keyboard_control_publisher.cpp │ ├── robot_lighting_control_server.cpp │ ├── robot_map_publisher.cpp │ ├── robot_odom_publisher.cpp │ ├── robot_smoke_alarm_publisher.cpp │ ├── robot_ultrasonic_publisher.cpp │ └── robot_wireless_alarm_publisher.cpp ├── robot_sensor_self_check │ ├── check_report │ │ ├── sensor_diagnostic_report_20250226_144435.json │ │ ├── sensor_diagnostic_report_20250226_144435.txt │ │ ├── sensor_diagnostic_report_20250226_144850.json │ │ ├── sensor_diagnostic_report_20250226_144850.txt │ │ ├── sensor_diagnostic_report_20250226_144927.json │ │ ├── sensor_diagnostic_report_20250226_144927.txt │ │ ├── sensor_diagnostic_report_20250226_144958.json │ │ └── sensor_diagnostic_report_20250226_144958.txt │ ├── config │ │ └── sensors_config.yaml │ ├── package.xml │ ├── resource │ │ └── robot_sensor_self_check │ ├── robot_sensor_self_check │ │ ├── __init__.py │ │ ├── robot_sensor_self_check.py │ │ └── test_topic.py │ ├── setup.cfg │ ├── setup.py │ └── test │ ├── test_copyright.py │ ├── test_flake8.py │ └── test_pep257.py ├── robot_visual_identity │ ├── cfg │ │ ├── nanotrack.yaml │ │ ├── rknnconfig.yaml │ │ └── stgcnpose.yaml │ ├── face_feature │ │ ├── mss_face_encoding.npy │ │ ├── wd_face_encoding.npy │ │ └── yls_face_encoding.npy │ ├── package.xml │ ├── resource │ │ ├── robot_visual_identity │ │ └── ros_rknn_infer │ ├── rknn_model │ │ ├── blood_detect.rknn │ │ ├── blood-seg-last-cbam.rknn │ │ ├── face_detect.rknn │ │ ├── face_emotion.rknn │ │ ├── face_keypoint.rknn │ │ ├── face_verify.rknn │ │ ├── head_detect.rknn │ │ ├── nanotrack_backbone127.rknn │ │ ├── nanotrack_backbone255.rknn │ │ ├── nanotrack_head.rknn │ │ ├── people_detect.rknn │ │ ├── stgcn_pose.rknn │ │ ├── yolo_kpt.rknn │ │ └── yolov8s-pose.rknn │ ├── robot_visual_identity │ │ ├── 人体跟随与避障控制系统文档.md │ │ ├── __init__.py │ │ ├── rknn_infer │ │ ├── robot_behavior_recognition.py │ │ ├── robot_emotion_recognition.py │ │ ├── robot_people_rgb_follow.py │ │ ├── robot_people_scan_follow.py │ │ └── robot_people_track.py │ ├── setup.cfg │ ├── setup.py │ └── test │ ├── test_copyright.py │ ├── test_flake8.py │ └── test_pep257.py ├── video_multiplexing │ ├── bash │ │ ├── test_config.linphonerc │ │ ├── test_video_stream.sh │ │ └── video_stream.pcap │ ├── COLCON_IGNORE │ ├── package.xml │ ├── resource │ │ └── video_multiplexing │ ├── setup.cfg │ ├── setup.py │ ├── test │ │ ├── test_copyright.py │ │ ├── test_flake8.py │ │ └── test_pep257.py │ └── video_multiplexing │ ├── __init__.py │ ├── __pycache__ │ ├── rtp_utils.py │ ├── video_freeswitch.py │ ├── video_linphone_bridge.py │ ├── video_publisher.py │ └── video_test_freeswitch.py └── ydlidar_ros2_driver-humble ├── CMakeLists.txt ├── config │ └── ydlidar.rviz ├── details.md ├── images │ ├── cmake_error.png │ ├── EAI.png │ ├── finished.png │ ├── rviz.png │ ├── view.png │ └── YDLidar.jpg ├── launch │ ├── ydlidar_launch.py │ ├── ydlidar_launch_view.py │ └── ydlidar.py ├── LICENSE.txt ├── package.xml ├── params │ └── TminiPro.yaml ├── README.md ├── src │ ├── ydlidar_ros2_driver_client.cpp │ └── ydlidar_ros2_driver_node.cpp └── startup └── initenv.sh 93 directories, 299 files 我的机器人ros2系统是有显示和主控页面的居家服务型移动机器人,用户点击下载更新就开始执行更新流程,整个系统更新功能应该怎么设计,在开发者应该编写哪些代码和做哪些准备,如何设计流程
最新发布
07-21
后端项目结构深度解析:testrealend 项目 一、项目根目录核心文件 plaintext testrealend/ ├── app.py # Flask应用主入口 │ # 职责:创建应用实例、配置扩展、注册API路由 ├── requirements.txt # 依赖清单(pip install -r 安装) ├── add_user_script.py # 管理员账户初始化脚本 ├── update_user_script.py # 用户信息更新脚本 ├── temp_qrcode.png # 临时二维码图片(水印功能相关) ├── embed/ # 水印嵌入后ZIP文件存储目录 │ # 文件名格式:员工ID_时间戳_嵌入结果.zip ├── compare/ # 水印比对文件目录(原始/提取水印对比) ├── static/ # 静态资源目录(CSS/JS/图片,当前项目未直接使用) └── templates/ # HTML模板目录(后端渲染页面时使用,当前项目为空) 二、核心功能模块解析 (1)API 接口层:resource/ plaintext src/resource/ ├── common_resource.py # 通用接口:注册(Register)、登录(Login)、登出(Logout) ├── adm_resource.py # 管理员接口:员工管理、水印操作 ├── emp_resource.py # 员工接口:数据申请、下载、查看 ├── shp_data_resource.py # SHP数据接口:列表查询、ID检索(重点修改模块) ├── application_resource.py # 数据申请接口:提交/审批流程 ├── nav_resource.py # 导航菜单接口:权限动态渲染 ├── generate_watermark.py # 水印生成接口:二维码/文本转水印 ├── embed_watermark.py # 水印嵌入接口:SHP文件处理 ├── download_file_resource.py # 文件下载接口:权限控制 ├── receive_zip_to_extract.py # ZIP上传接口:解压与验证 └── __init__.py # 初始化文件 核心逻辑: • 每个.py文件对应一类业务场景,通过Flask-RESTful的Resource类定义 HTTP 接口(GET/POST/PUT/DELETE) • 接口路径通过api.add_resource(ResourceClass, '/api/path')在app.py中注册 (2)业务逻辑层:server/ plaintext src/server/ ├── shp_data_server.py # SHP数据业务逻辑:数据库查询、文件处理 ├── adm_server.py # 管理员业务逻辑:账户管理、权限校验 ├── emp_server.py # 员工业务逻辑:数据权限控制 ├── common_server.py # 通用业务逻辑:用户认证、 token管理 ├── application_server.py # 数据申请业务逻辑:流程状态管理(注意:拼写应为application) └── __init__.py # 初始化文件 设计模式: • 资源类(Resource)接收请求后,调用对应服务类(Server)的方法执行具体逻辑 • 实现接口层与业务层解耦,便于单元测试和逻辑复用 (3)数据模型层:model/ plaintext src/model/ ├── Shp_Data.py # SHP文件模型:存储文件元信息(路径/属性/状态) ├── Adm_Account.py # 管理员账户模型:用户名/密码哈希/权限等级 ├── Employee_Info.py # 员工信息模型:基本资料/部门/角色 ├── Application.py # 数据申请模型:申请记录/审批状态/时间戳 └── __init__.py # 初始化文件 技术细节: • 使用SQLAlchemy ORM映射数据库表,支持db.Model继承 • 字段定义含String/Integer/DateTime等类型,部分字段设置unique/index索引 (4)算法模块:algorithm/ plaintext src/algorithm/ ├── NC.py # 归一化相关系数算法(水印相似度计算) ├── embed.py # 水印嵌入算法:SHP文件空间域修改 ├── extract.py # 水印提取算法:信号检测与解码 ├── get_coor.py # 坐标提取工具:从SHP获取几何坐标 ├── is_multiple.py # 倍数判断工具:坐标精度处理 ├── to_geodataframe.py # 地理数据转换:SHP转GeoDataFrame ├── embed/ # 水印嵌入测试数据目录 └── __init__.py # 初始化文件 (5)扩展与工具:extension/ & utils/ • extension/ plaintext src/extension/ ├── extension.py # 扩展初始化:db(SQLAlchemy)/limiter(请求限流) └── __init__.py • utils/ plaintext src/utils/ ├── required.py # 请求参数校验:必填字段检查 └── __init__.py (6)通用工具:common/ plaintext src/common/ ├── api_tools.py # API辅助函数:响应格式化/错误处理 ├── constants.py # 项目常量:状态码/路径前缀/权限标识 └── __init__.py 三、数据库与配置模块 (1)数据库迁移:migrations/ plaintext src/migrations/ ├── alembic.ini # Alembic配置文件 ├── env.py # 数据库连接配置(生产/开发环境区分) ├── script.py.mako # 迁移脚本模板 └── versions/ # 具体迁移脚本目录(每个版本一个.py文件) 使用场景: • 模型变更时通过flask db migrate生成脚本,flask db upgrade更新数据库 (2)IDE 配置与缓存:.idea/ & pycache/ • .idea/:PyCharm 项目配置(勿手动修改,已加入.gitignore) • __pycache__/:Python 字节码缓存(自动生成,提升模块加载速度) 这是什么等级的项目,这是我一个朋友的项目,我觉得他的这个很好,你参考一下,结合多个csdn的文章,做一个最好最全面的后端设计
07-03
def read_goal(filename): goal = MoveBaseGoal() file_to_read = open(filename) index = 0 for line in file_to_read.readlines(): line = line.strip() index += 1 if index == 2: pattern = re.compile(r"(?<=\[).*?(?=\])") query = pattern.search(line) listFromLine = query.group().split(',') goal.target_pose.pose.position.x = float(listFromLine[0]) goal.target_pose.pose.position.y = float(listFromLine[1]) if index == 3: pattern = re.compile(r"(?<=\[).*?(?=\])") query = pattern.search(line) listFromLine = query.group().split(',') goal.target_pose.pose.orientation.z = float(listFromLine[2]) goal.target_pose.pose.orientation.w = float(listFromLine[3]) print(goal.target_pose.pose) return goal def pick_aruco(): os.system("python /home/robuster/beetle_ai/scripts/3pick.py") def place(): os.system("python /home/robuster/beetle_ai/scripts/place_2.py") def reach_test1(): os.system("python /home/robuster/beetle_ai/scripts/reach_place1.py") def test_2(): os.system("python /home/robuster/beetle_ai/scripts/2test_2.py") def test_1(): os.system("python /home/robuster/beetle_ai/scripts/2test_1.py") def test(): os.system("python /home/robuster/beetle_ai/scripts/2test.py") def test_3(): os.system("python /home/robuster/beetle_ai/scripts/2test3.py") def forward(): print("forward...") move_cmd = Twist() pub = rospy.Publisher('cmd_vel', Twist, queue_size=1) count = 15 rate = rospy.Rate(count) # 20hz while count > 0: move_cmd.linear.x = 0.1 pub.publish(move_cmd) rate.sleep() print("forward...") count -= 1 def backward(): print("backward...") move_cmd = Twist() pub = rospy.Publisher('cmd_vel', Twist, queue_size=1) count = 5 rate = rospy.Rate(count) # 20hz while count > 0: move_cmd.linear.x = -0.1 pub.publish(move_cmd) rate.sleep() print("forward...") count -= 1 def moblie_fetch_demo(): goal1 = read_goal("goal_1.txt") goal2 = read_goal("goal_2.txt") # pick cube from goal1 goal_number = 1 reach_test1() pick_aruco() test() pick_aruco() test_1() pick_aruco() test_2() pick_aruco() test_3() # pick cube from goal2 goal_number = 2 send_goal(goal_number, goal2) return "Mission Finished." if __name__ == '__main__': rospy.init_node('send_goals_python', anonymous=True) result = moblie_fetch_demo() rospy.loginfo(result)
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值