Segmentation fault

asked 2015-11-25 01:24:39 -0500

Kazuki Kadonaka gravatar image

updated 2015-11-25 02:03:59 -0500

gvdhoorn gravatar image

Please teach me the solution. I use ubuntu 14.04 on Raspberry Pi 2.

#!/usr/bin/env python

import rospy
import roslib
import sys
import RPi.GPIO as GPIO

# Initialize the LED to not be lit.
lit = False

def run():

        # Initialize to use BCM numbering.
    GPIO.setmode(GPIO.BCM)

        # We want pin 18 to be an output pin, and it should start out with a low value.
    GPIO.setup(24, GPIO.OUT, initial=GPIO.LOW)

    rospy.init_node("led_blink", anonymous=False)

        # Set up a timer to toggle the LED state once per second.
    rospy.Timer(rospy.Duration(1.0), timer_callback)
        rospy.spin()
    GPIO.cleanup()


def timer_callback(event):
    global lit

        # Toggle the LED state.
    lit = not lit
    if lit:
        GPIO.output(24, 1)
    else:
        GPIO.output(24, 0)


def main(args):
    run()


if __name__ == "__main__":
    main(sys.argv)

error:

ubuntu@ubuntu:~/catkin_ws/src/rpi_examples_indigo$ rosrun ros_start led_blink.py
Traceback (most recent call last):
  File "/home/ubuntu/catkin_ws/src/rpi_examples_indigo/src/led_blink.py", line 43, in <module>
    main(sys.argv)
  File "/home/ubuntu/catkin_ws/src/rpi_examples_indigo/src/led_blink.py", line 39, in main
    run()
  File "/home/ubuntu/catkin_ws/src/rpi_examples_indigo/src/led_blink.py", line 17, in run
    GPIO.setup(24, GPIO.OUT, initial=GPIO.LOW)
RuntimeError: No access to /dev/mem.  Try running as root!
ubuntu@ubuntu:~$ sudo su
root@ubuntu:/home/ubuntu# source catkin_ws/devel/setup.bash
root@ubuntu:/home/ubuntu# rosrun ros_start led_blink.py
Segmentation fault (コアダンプ)
edit retag flag offensive close merge delete