在学习古月老师ROS第四课,启动机器人的键盘控制launch文件时报了这个error,下面是报错的内容:

process[mbot_teleop-1]: started with pid [4942]File "/home/zxf/catkin_ws/src/mbot_teleop/scripts/mbot_teleop.py", line 78print msg^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(msg)?
[mbot_teleop-1] process has died [pid 4942, exit code 1, cmd /home/zxf/catkin_ws/src/mbot_teleop/scripts/mbot_teleop.py __name:=mbot_teleop __log:=/home/zxf/.ros/log/4e9341ca-0155-11ec-8ec5-cf95496c0738/mbot_teleop-1.log].
log file: /home/zxf/.ros/log/4e9341ca-0155-11ec-8ec5-cf95496c0738/mbot_teleop-1*.log

网上搜索了一圈发现是因为python2.x的版本与python3.x版本不兼容的问题。报错的原因就出在print输出语法上,一个简单的例子hello ROS

python2.x
print "hello ROS"
输出:hello ROS
print 'hello ROS'
输出:hello ROS
print ('hello ROS')
输出:hello ROS
print ("hello ROS")
输出:hello ROS

上面四种方法在python2.x中都可以适用,但在python3.x中却不一定

python3.x
print("hello ROS")
输出:hello ROS
print(hello ROS)
输出:hello ROS

我用的是ubuntu20.04,所以是python3的版本,与古月老师用的不一样所以需要修改~/catkin_ws/src/mbot_teleop/scripts/mbot_teleop.py文件

#!/usr/bin/env python
# -*- coding: utf-8 -*-import rospy
from geometry_msgs.msg import Twist
import sys, select, termios, ttymsg = """
Control mbot!
---------------------------
Moving around:u    i    oj    k    lm    ,    .q/z : increase/decrease max speeds by 10%
w/x : increase/decrease only linear speed by 10%
e/c : increase/decrease only angular speed by 10%
space key, k : force stop
anything else : stop smoothlyCTRL-C to quit
"""moveBindings = {'i':(1,0),'o':(1,-1),'j':(0,1),'l':(0,-1),'u':(1,1),',':(-1,0),'.':(-1,1),'m':(-1,-1),}speedBindings={'q':(1.1,1.1),'z':(.9,.9),'w':(1.1,1),'x':(.9,1),'e':(1,1.1),'c':(1,.9),}def getKey():tty.setraw(sys.stdin.fileno())rlist, _, _ = select.select([sys.stdin], [], [], 0.1)if rlist:key = sys.stdin.read(1)else:key = ''termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)return keyspeed = .2
turn = 1def vels(speed,turn):return "currently:\tspeed %s\tturn %s " % (speed,turn)if __name__=="__main__":settings = termios.tcgetattr(sys.stdin)rospy.init_node('mbot_teleop')pub = rospy.Publisher('/cmd_vel', Twist, queue_size=5)x = 0th = 0status = 0count = 0acc = 0.1target_speed = 0target_turn = 0control_speed = 0control_turn = 0try:print(msg)print(vels(speed,turn))while(1):key = getKey()# 运动控制方向键(1:正方向,-1负方向)if key in moveBindings.keys():x = moveBindings[key][0]th = moveBindings[key][1]count = 0# 速度修改键elif key in speedBindings.keys():speed = speed * speedBindings[key][0]  # 线速度增加0.1倍turn = turn * speedBindings[key][1]    # 角速度增加0.1倍count = 0print(vels(speed,turn))if (status == 14):print(msg)status = (status + 1) % 15# 停止键elif key == ' ' or key == 'k' :x = 0th = 0control_speed = 0control_turn = 0else:count = count + 1if count > 4:x = 0th = 0if (key == '\x03'):break# 目标速度=速度值*方向值target_speed = speed * xtarget_turn = turn * th# 速度限位,防止速度增减过快if target_speed > control_speed:control_speed = min( target_speed, control_speed + 0.02 )elif target_speed < control_speed:control_speed = max( target_speed, control_speed - 0.02 )else:control_speed = target_speedif target_turn > control_turn:control_turn = min( target_turn, control_turn + 0.1 )elif target_turn < control_turn:control_turn = max( target_turn, control_turn - 0.1 )else:control_turn = target_turn# 创建并发布twist消息twist = Twist()twist.linear.x = control_speed; twist.linear.y = 0; twist.linear.z = 0twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = control_turnpub.publish(twist)except:print(e)finally:twist = Twist()twist.linear.x = 0; twist.linear.y = 0; twist.linear.z = 0twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = 0pub.publish(twist)termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)

大概就是在78、79、93、95、141行上的print输出语句上加上()。

如果写的有什么问题,欢迎大家在评论区留言讨论。

SyntaxError: Missing parentheses in call to ‘print‘. Did you mean print(e)?相关推荐

  1. python 错误之SyntaxError: Missing parentheses in call to 'print'

    SyntaxError: Missing parentheses in call to 'print' 由于python的版本差异,造成的错误. python2: print "hello ...

  2. SyntaxError: Missing parentheses in call to 'print' 这个错误原因是Python版本问题

    问题 print "www.baidu.com"           Python2 print ("www.baidu.com")     Python3 出 ...

  3. SyntaxError: Missing parentheses in call to ‘print‘. 正解

    SyntaxError: Missing parentheses in call to 'print'. 报错是由于Python3和Python2版本不同,print函数语法也不同造成的.这样的原因很 ...

  4. 问题记录:SyntaxError: Missing parentheses in call to ‘print‘.

    scripts/kconfig/conf --silentoldconfig Kconfig   CHK     include/config.h   GEN     include/autoconf ...

  5. Python SyntaxError: Missing parentheses in call to 'print'

    下面的代码 print "hello world" 会出现下面的错误 SyntaxError: Missing parentheses in call to 'print' 因为写 ...

  6. 解决 Python 报错SyntaxError: Missing parentheses in call to 'print'

    报错:SyntaxError: Missing parentheses in call to 'print' 解析: python2.X版本与python3.X版本输出方式有点不同,在2.X中直接输出 ...

  7. python报错系列(9)--SyntaxError: Missing parentheses in call to ‘print‘. Did you mean print()

    系列文章目录 文章目录 系列文章目录 前言 1.SyntaxError: Missing parentheses in call to 'print'. Did you mean print() 2. ...

  8. 使用print时出错 SyntaxError: Missing parentheses in call to ‘print‘ Did you mean print(““)

    使用print时出错 SyntaxError: Missing parentheses in call to 'print' Did you mean print("") 错误原因 ...

  9. [报错] SyntaxError: Missing parentheses in call to ‘exec‘

    报错信息 在 Debug Python 程序的时候(PyCharm),直接就报了以下错误: ImportError: cannot import name 'InteractiveConsole' f ...

最新文章

  1. 单身程序猿适合找单身程序媛吗?
  2. 分布式计算的模式语言读后感
  3. 想避免宕机,数据中心运营商还要不断演练实践
  4. mysql root远程访问权限_mysql8.0 Server在Windows平台中的安装、初始化和远程访问设置...
  5. Java 11的期望
  6. 淘宝弹性布局方案lib-flexible实践
  7. php 接受 amp,php中amp;amp;和||的用法
  8. 64位树莓派运行linux,树莓派3B+安装64位debian GUN/Linux系统
  9. java pkcs8_java – 如何在python中创建PKCS8 RSA签名
  10. 所用计算机网卡品牌得的型号,惠普无线网卡驱动,详细教您如何
  11. 一、大话HTTP协议-HTTP的前世今生
  12. 灵活操作MS SQL 2005 中的数据库 - 分离、附加、离线、在线、日志截断
  13. 杂项-Mac关闭系统更新提示(macOS10.15.2可用)
  14. 阿里云ocr身份证识别接口调用
  15. 散户炒股七大绝招 巨额获利风险小 (网摘)
  16. 数据分析好用的软件工具
  17. cesium开发加载shapefile制作的白膜
  18. 2018 杭州见习报告
  19. tesseract-ocr引擎学习笔记
  20. 序号计算机软件工程协会网,序号

热门文章

  1. Tensorboard报错的解决
  2. 【计算机网络】第九章:无线网络
  3. mysql 获取农历年份_iOS 获取公历、农历日期的年月日
  4. vue3+vite UC浏览器兼容
  5. SeedLab10: Linux Firewall Exploration Lab
  6. oracle 计算 符号优先级,oracle 表达式运算符优先级
  7. html图片轮播思路,css3如何实现轮播图?css3实现轮播图片的方法
  8. 御坂坂的C++学习之路(2)
  9. 在mtk移植个linux内核,移植 Linux Kernel 造成無法開機之解決方案以及除錯工具
  10. adguard自定义_openwrt上装adguard以及实用教程