Raspberry Pi Sense HAT on Ubuntu Mate (ROS)


#1

Hello I’m working on a project for school. I’m using Sense Hat on Raspberry pi 3 B to display pixels on led matrix and IMU to get yaw. But the problem is that I’m trying to run IMU when Ubuntu Mate starts (on boot) in ROS. So I made a service that runs python script on boot. But I get an error from service:

If I run script manually everything works fine, but if I run the service I get the same error.

dec 28 01:25:57 pi-mate picobot-start[870]: File “/home/pi/catkin_ws/src/Picobot/picobot_imu/src/picobot_imu.py”, line 22, in gyroData
dec 28 01:25:57 pi-mate picobot-start[870]: sense.set_imu_config(False, True, True)
dec 28 01:25:57 pi-mate picobot-start[870]: File “/usr/lib/python2.7/dist-packages/sense_hat/sense_hat.py”, line 660, in set_imu_config
dec 28 01:25:57 pi-mate picobot-start[870]: self._init_imu() # Ensure imu is initialised
dec 28 01:25:57 pi-mate picobot-start[870]: File “/usr/lib/python2.7/dist-packages/sense_hat/sense_hat.py”, line 648, in _init_imu
dec 28 01:25:57 pi-mate picobot-start[870]: raise OSError(‘IMU Init Failed’)
dec 28 01:25:57 pi-mate picobot-start[870]: OSError: IMU Init Failed
dec 28 01:25:58 pi-mate picobot-start[870]: No handlers could be found for logger “roslaunch”
dec 28 01:25:58 pi-mate picobot-start[870]: [picobot_imu-6] process has died [pid 1515, exit code 1, cmd /home/pi/catkin_ws/src/Picobot/picobot

Here is my code:

#!/usr/bin/env python
import rospy
from sense_hat import SenseHat
import time
from random import randint
from std_msgs.msg import Float32

sense = SenseHat()

def randomColor():
 red_random = randint(0,255)
 blue_random = randint(0,255)
 green_random = randint(0,255)
 return (red_random,green_random,blue_random)


def gyroData():
    pub = rospy.Publisher('gyro', Float32, queue_size=10)
    rospy.init_node('picobot_imu')
    rate = rospy.Rate(10) # 10hz

    sense.set_imu_config(False, True, True)
    
    while not rospy.is_shutdown():
        o = sense.get_orientation()
       #pitch = o["pitch"]
       #roll = o["roll"]
        yaw = o["yaw"]
       #rospy.loginfo(yaw)
        pub.publish(yaw)
        rate.sleep()

def main():
    
    sense.clear((0, 0, 0))
    sense.low_light = True
    g =(0,153,153)
    bl = (0,153,0)
    b = (0,0,0)
    picobot_pixels = [
    g,g,b,g,b,g,g,b,
    g,g,b,g,b,g,b,b,
    g,b,b,g,b,g,g,b,
    b,b,b,b,b,b,b,b,
    g,g,g,b,bl,b,bl,b,
    g,b,g,b,b,bl,b,b,
    g,g,g,b,bl,bl,bl,b,
    b,b,b,b,b,b,b,b
    ]
    sense.set_pixels(picobot_pixels)
    gyroData()
if __name__ == '__main__':
     main()

#2

Just curious why you went with Ubuntu Mate?
I have two Sense Hats here running from Raspbian on Pi A+'s. I launch my python code on boot up via crontab.
They are setup as weather clocks displaying my info in a scrolling message on the Sense Hat LED matrix


#3

Because, ROS works best on Ubuntu Mate.


#4

OK, had to Google ROS so we’re both on the same page. ;)
I missed the link to it in your original post somehow. (insert embarrassed smiley here) =(
Can you delay the starting of your code run? I’m no expert but I’m thinking its running before other stuff it needs has fully started. Its launching to early in the boot process “maybe”?


#5

I tried putting a 15s start delay.

<node pkg="timed_roslaunch" type="timed_roslaunch.sh" args="15 picobot_imu picobot_imu.launch" name="timed_roslaunch2" output="screen" />

the error in service looks like this now:

Dec 29 10:46:06 pi-mate picobot-start[859]: NODES

Dec 29 10:46:06 pi-mate picobot-start[859]: /

Dec 29 10:46:06 pi-mate picobot-start[859]: picobot_imu (picobot_imu/picobot_imu.py)

Dec 29 10:46:06 pi-mate picobot-start[859]: ROS_MASTER_URI=http://127.0.0.1:11311

Dec 29 10:46:06 pi-mate picobot-start[859]: [96B blob data]

Dec 29 10:46:06 pi-mate picobot-start[859]: process[picobot_imu-1]: started with pid [1823]

Dec 29 10:46:06 pi-mate picobot-start[859]: all processes on machine have died, roslaunch will exit

Dec 29 10:46:06 pi-mate picobot-start[859]: shutting down processing monitor…

Dec 29 10:46:06 pi-mate picobot-start[859]: … shutting down processing monitor complete


#6

My Linux skills are pretty basic to be honest. I think your going to have to wait for somebody with a higher skill set to chime in on this one. I’ll keep watching though, maybe I’ll improve my skills in the process. Wish I could help more. =(