###環境
・Ubuntu Server 16.04 LTS
・Raspberry pi3
・ROSを使用してPimouseを動かしている
###参考書
・上田隆一「RaspberryPiで学ぶROSロボット入門」
###問題点
デバイスファイル/dev/rtbuzzer0をPython2.7の環境でreadlineしようとすると以下のエラー文が発生します。
$ ls -l /dev/rt* crw-rw-rw- 1 root root 242, 0 4月 9 16:09 /dev/rtbuzzer0 crw-rw-rw- 1 root root 233, 0 4月 9 16:09 /dev/rtcounter0 crw-rw-rw- 1 root root 234, 0 4月 9 16:09 /dev/rtcounter_l0 ..... $ python >>> f=open("/dev/rtbuzzer0","r") >>> data=f.readline() Traceback (most recent call last): File "<stdin>", line 1, in <module> IOError: [Errno 22] Invalid argument
参考書では.pyファイルに以下のような内容を書いて同様のエラーがrostestで発生し、pythonに直打ち(上記)してもまたエラーが発生したので質問させていただきました。
python
1#!/usr/bin/env python 2import rospy, unittest, rostest 3import rosnode 4import time 5from std_msgs.msg import UInt16 6 7class BuzzerTest(unittest.TestCase): 8 def test_node_exist(self): 9 nodes=rosnode.get_node_names() 10 self.assertIn('/buzzer',nodes,"node does not exist") 11 def test_put_value(self): 12 pub=rospy.Publisher('/buzzer',UInt16) 13 for i in range(10): 14 pub.publish(1234) 15 time.sleep(0.1) 16 17 with open('/dev/rtbuzzer0','r') as f: 18 data=f.readline().strip() 19 self.assertEqual(data,"1234\n","value does not wrriten to rtbuzzer0") 20 21if __name__=='__main__': 22 time.sleep(3) 23 rospy.init_node('travis_test_buzzer') 24 rostest.rosrun('pimouse_ros','travis_test_buzzer',BuzzerTest) 25
$ rostest pimouse_ros test.launch ... logging to /home/ubuntu/.ros/log/rostest-ubuntu-7615.log [ROSUNIT] Outputting test results to /home/ubuntu/.ros/test_results/pimouse_ros/rostest-launch_test.xml [Testcase: testtest_buzzer] ... ok [ROSTEST]----------------------------------------------------------------------- [pimouse_ros.rosunit-test_buzzer/test_node_exist][passed] [pimouse_ros.rosunit-test_buzzer/test_put_value][ERROR]------------------------- [Errno 22] Invalid argument File "/usr/lib/python2.7/unittest/case.py", line 329, in run testMethod() File "/home/ubuntu/catkin_ws/src/pimouse_ros/test/travis_test_buzzer.py", line 18, in test_put_value data=f.readline().strip() -------------------------------------------------------------------------------- SUMMARY * RESULT: FAIL * TESTS: 2 * ERRORS: 1 * FAILURES: 0
ご協力、ご教授のほど宜しくお願い致します。
あなたの回答
tips
プレビュー