1-p01_arg_trans-python基础

Python函数参数详解
本文深入探讨了Python中函数参数的多种使用方式,包括位置参数、关键字参数、不定长参数等,通过具体示例展示了参数传递的机制及注意事项。
def m(a, b):
    print('in m')
    a = 100
    b = 200


x = 1
y = 2
m(x, y)
print(x, y)


def m2(a):
    a[0] = 100

x = [1, 2]
m2(x)
print(x)


def m3(*a):
    for v in a:
        print(v)

print('-' * 200)
m3(1, 2, 3, 'abc', 'def')
print('-' * 200)
m3(10, 20)


def m4(**a):
    for key in a:
        print(key, '=', a[key])
print('-' * 200)
m4(aa=123, bb=456, cc=True)


def m5(*a, **b):
    print('=' * 200)
    for v in a:
        print(v, end=',')
    print()
    print('-' * 200)
    for key in b:
        print(key, '=', b[key])

m5(1, 2, 3, True, False, aa='aaa', bb='bbb', cc='ccc')

x = [1, 2, 3, True, False]
y = {'aa': 'aaa', 'bb': 'bbb', 'cc': 'ccc'}
m5(*x, **y)在这里插入代码片
D:\Anaconda\python.exe D:/AI20/06_codes/deeplearning_20/p01_arg_trans.py
in m
1 2
[100, 2]
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1
2
3
abc
def
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
10
20
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
aa = 123
bb = 456
cc = True
========================================================================================================================================================================================================
1,2,3,True,False,
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
aa = aaa
bb = bbb
cc = ccc
========================================================================================================================================================================================================
1,2,3,True,False,
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
aa = aaa
bb = bbb
cc = ccc

Process finished with exit code 0
在这里插入代码片
有一个ros中一个小车添加ur5机械臂的项目,这是小车运动控制文件: <robot name="my_car_move" xmlns:xacro="http://wiki.ros.org/xacro"> <xacro:macro name="joint_trans" params="joint_name"> <transmission name="${joint_name}_trans"> <type>transmission_interface/SimpleTransmission</type> <joint name="${joint_name}"> <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface> </joint> <actuator name="${joint_name}_motor"> <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface> <mechanicalReduction>1</mechanicalReduction> </actuator> </transmission> </xacro:macro> <xacro:joint_trans joint_name="left_wheel2base_link" /> <xacro:joint_trans joint_name="right_wheel2base_link" /> <xacro:joint_trans joint_name="front_wheel2base_link" /> <xacro:joint_trans joint_name="back_wheel2base_link" /> <gazebo> <plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so"> <rosDebugLevel>Debug</rosDebugLevel> <publishWheelTF>false</publishWheelTF> <robotNamespace>/</robotNamespace> <publishTf>1</publishTf> <publishWheelJointState>false</publishWheelJointState> <alwaysOn>true</alwaysOn> <updateRate>100.0</updateRate> <legacyMode>true</legacyMode> <leftJoint>left_wheel2base_link</leftJoint> <!-- 左轮 --> <rightJoint>right_wheel2base_link</rightJoint> <!-- 右轮 --> <wheelSeparation>${base_link_radius * 2}</wheelSeparation> <!-- 车轮间距 --> <wheelDiameter>${wheel_radius * 2}</wheelDiameter> <!-- 车轮直径 --> <broadcastTF>0</broadcastTF> <wheelTorque>30</wheelTorque> <wheelAcceleration>1.8</wheelAcceleration> <commandTopic>cmd_vel</commandTopic> <!-- 运动控制话题 --> <odometryFrame>odom</odometryFrame> <odometryTopic>odom</odometryTopic> <!-- 里程计话题 --> <robotBaseFrame>base_footprint</robotBaseFrame> <!-- 根坐标系 --> </plugin> </gazebo> </robot> 以下是启动文件内容: <?xml version="1.0"?> <launch> <!-- Main entry point for loading a single UR5 into Gazebo, in isolation, in the empty world. A set of ros_control controllers similar to those loaded by ur_robot_driver will be loaded by 'ur_control.launch.xml' (note: *similar*, *not* identical). This bringup .launch file is intentionally given the same name as the one in the ur_robot_driver package, as it fulfills a similar role: loading the configuration and starting the necessary ROS nodes which in the end provide a ROS API to a Universal Robots UR5. Only in this case, instead of a real robot, a virtual model in Gazebo is used. NOTE 1: as this is not a real robot, there are limits to the faithfulness of the simulation. Dynamic behaviour will be different from a real robot. Only a subset of topics, actions and services is supported. Specifically, interaction with the Control Box itself is not supported, as Gazebo does not simulate a Control Box. This means: no Dashboard server, no URScript topic and no force-torque sensor among other things. NOTE 2: users wishing to integrate a UR5 with other models into a more complex simulation should NOT modify this file. Instead, if it would be desirable to reuse this file with a custom simulation, they should create a copy and update this copy so as to accomodate required changes. In those cases, treat this file as an example, showing one way how a Gazebo simulation for UR robots *could* be launched. It is not necessary to mimic this setup completely. --> <rosparam file="$(find robotiq_2f_85_gripper_gazebo)/config/gazebo_controller.yaml" command="load" /> <!--Robot description and related parameter files --> <arg name="robot_description_file" default="$(dirname)/inc/load_ur5.launch.xml" doc="Launch file which populates the 'robot_description' parameter."/> <arg name="joint_limit_params" default="$(find ur_description)/config/ur5/joint_limits.yaml"/> <arg name="kinematics_params" default="$(find ur_description)/config/ur5/default_kinematics.yaml"/> <arg name="physical_params" default="$(find ur_description)/config/ur5/physical_parameters.yaml"/> <arg name="visual_params" default="$(find ur_description)/config/ur5/visual_parameters.yaml"/> <arg name="transmission_hw_interface" default="hardware_interface/EffortJointInterface" doc="The hardware_interface to expose for each joint in the simulated robot (one of: [hardware_interface/PositionJointInterface, hardware_interface/VelocityJointInterface, hardware_interface/EffortJointInterface])"/> <!-- Controller configuration --> <arg name="controller_config_file" default="$(find ur_gazebo)/config/ur5_controllers.yaml" doc="Config file used for defining the ROS-Control controllers."/> <arg name="controllers" default="joint_state_controller left_wheel_velocity_controller right_wheel_velocity_controller eff_joint_traj_controller" doc="Controllers that are activated by default."/> <arg name="stopped_controllers" default="joint_group_eff_controller" doc="Controllers that are initally loaded, but not started."/> <!-- robot_state_publisher configuration --> <arg name="tf_prefix" default="" doc="tf_prefix used for the robot."/> <arg name="tf_pub_rate" default="125" doc="Rate at which robot_state_publisher should publish transforms."/> <!-- Gazebo parameters --> <arg name="paused" default="false" doc="Starts Gazebo in paused mode" /> <arg name="gui" default="true" doc="Starts Gazebo gui" /> <!-- Load urdf on the parameter server --> <include file="$(arg robot_description_file)"> <arg name="joint_limit_params" value="$(arg joint_limit_params)"/> <arg name="kinematics_params" value="$(arg kinematics_params)"/> <arg name="physical_params" value="$(arg physical_params)"/> <arg name="visual_params" value="$(arg visual_params)"/> <arg name="transmission_hw_interface" value="$(arg transmission_hw_interface)"/> </include> <!-- 先加载 PID gains --> <rosparam file="$(find urdf02_gazebo)/config/gazebo_ros_control_params.yaml" command="load"/> <!-- Robot state publisher --> <node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher"> <param name="publish_frequency" type="double" value="$(arg tf_pub_rate)" /> <param name="tf_prefix" value="$(arg tf_prefix)" /> </node> <!-- Start the 'driver' (ie: Gazebo in this case) --> <include file="$(dirname)/inc/ur_control.launch.xml"> <arg name="controller_config_file" value="$(arg controller_config_file)"/> <arg name="controllers" value="$(arg controllers)"/> <arg name="gui" value="$(arg gui)"/> <arg name="paused" value="$(arg paused)"/> <arg name="stopped_controllers" value="$(arg stopped_controllers)"/> </include> </launch> 以下是ur5控制yaml文件内容: joint_state_controller: type: joint_state_controller/JointStateController publish_rate: &loop_hz 125 left_wheel_velocity_controller: type: velocity_controllers/JointVelocityController joint: left_wheel2base_link right_wheel_velocity_controller: type: velocity_controllers/JointVelocityController joint: right_wheel2base_link eff_joint_traj_controller: type: effort_controllers/JointTrajectoryController action_monitor_rate: 10 joints: &robot_joints - shoulder_pan_joint - shoulder_lift_joint - elbow_joint - wrist_1_joint - wrist_2_joint - wrist_3_joint gains: # Required because we're controlling an effort interface shoulder_pan_joint: {p: 4000, d: 200, i: 1, i_clamp: 1} shoulder_lift_joint: {p: 10000, d: 200, i: 1, i_clamp: 1} elbow_joint: {p: 2000, d: 20, i: 1, i_clamp: 1} wrist_1_joint: {p: 500, d: 1, i: 1, i_clamp: 1} wrist_2_joint: {p: 500, d: 1, i: 1, i_clamp: 1} wrist_3_joint: {p: 10, d: 0.1, i: 0, i_clamp: 1} constraints: goal_time: 0.6 stopped_velocity_tolerance: 0.05 shoulder_pan_joint: {trajectory: 0.1, goal: 0.1} shoulder_lift_joint: {trajectory: 0.1, goal: 0.1} elbow_joint: {trajectory: 0.1, goal: 0.1} wrist_1_joint: {trajectory: 0.1, goal: 0.1} wrist_2_joint: {trajectory: 0.1, goal: 0.1} wrist_3_joint: {trajectory: 0.1, goal: 0.1} stop_trajectory_duration: 0.5 state_publish_rate: *loop_hz action_monitor_rate: 10 # arm_controller: # type: effort_controllers/JointTrajectoryController # joints: # - shoulder_pan_joint # - shoulder_lift_joint # - elbow_joint # - wrist_1_joint # - wrist_2_joint # - wrist_3_joint joint_group_eff_controller: type: effort_controllers/JointGroupEffortController joints: - shoulder_pan_joint - shoulder_lift_joint - elbow_joint - wrist_1_joint - wrist_2_joint - wrist_3_joint pos_joint_traj_controller: type: position_controllers/JointTrajectoryController joints: *robot_joints constraints: goal_time: 0.6 stopped_velocity_tolerance: 0.05 shoulder_pan_joint: {trajectory: 0.1, goal: 0.1} shoulder_lift_joint: {trajectory: 0.1, goal: 0.1} elbow_joint: {trajectory: 0.1, goal: 0.1} wrist_1_joint: {trajectory: 0.1, goal: 0.1} wrist_2_joint: {trajectory: 0.1, goal: 0.1} wrist_3_joint: {trajectory: 0.1, goal: 0.1} stop_trajectory_duration: 0.5 state_publish_rate: *loop_hz action_monitor_rate: 10 joint_group_pos_controller: type: position_controllers/JointGroupPositionController joints: *robot_joints 现在出现一个问题是单独启动小车文件并通过控制节点能正常控制小车,但是通过我提供的启动文件启动小车和机械臂组合模型,控制会出现异常,检查过控制节点发布信息,并没有问题,请基于我提供的内容检查问题所在,以我提供的内容为准,不要编造内容
最新发布
12-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值