<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to solve the problem of RVIZ freezing?]]></title><description><![CDATA[<p dir="auto"><strong>Question:</strong><br />
The main content of this post is that the robotic arm starts <strong>RVIZ</strong> in the <strong>ROS</strong> environment, which will cause the system to <strong>freeze,</strong> affecting the program's crash. Is there any way to improve the stability of <strong>RVIZ</strong> and enable it to operate normally?<br />
<strong>Operation:</strong><br />
I run the program with two versions of <strong><a href="https://www.elephantrobotics.com/en/mycobot-pi/" target="_blank" rel="noopener noreferrer nofollow ugc">myCobot280</a></strong> series robotic arm. One is the robotic arm with M5Stack master control, and another is the robotic arm with Raspberry Pi 4B master control.<br />
The <strong>M5Stack's</strong> robotic arm runs in a laptop configuration, and the Raspberry Pi's robotic arm runs in its own Raspberry Pi 4B <strong>(64-bit 1.5GHz quad-core).</strong><br />
<img src="https://static.elephantrobotics.com/wp-content/uploads/2022/02/%E8%B4%AD%E4%B9%B0%E5%8C%BA%E4%BA%A7%E5%93%81.png" alt="alt text" class=" img-fluid img-markdown" /><br />
Figure is <strong>myCobot280-M5Stack</strong><br />
<img src="https://static.elephantrobotics.com/wp-content/uploads/2022/03/pic-9.png" alt="alt text" class=" img-fluid img-markdown" /><br />
Figure is <strong>myCobot280-Pi</strong><br />
<strong>Here are a few ways to use myCobot280 with RVIZ.<br />
Slider Control：</strong><br />
Move the slider to control the movement of myCobot280, and the movement of myCobot280 will be fed into the RVIZ interface in real time.<br />
<img src="/assets/uploads/files/1661500523526-slider-control-resized.png" alt="0_1661500522007_slider control.png" class=" img-fluid img-markdown" /><br />
<strong>Movement Planning：</strong><br />
Given two positions, one is position A, and the other is position B, send commands to the myCobot280 to move from A to B.<br />
<img src="https://docs.elephantrobotics.com/docs/gitbook-en/resourse/12-ApplicationBaseROS/moveit-2.gif" alt="alt text" class=" img-fluid img-markdown" /><br />
<strong>Artificial Intelligence Kit：</strong><br />
Guide the robot through robot vision and realize intelligent grabbing simultaneously. The intellectual grabbing of wood blocks and the intelligent grabbing of image objects have been developed.<br />
<img src="/assets/uploads/files/1661500671673-1234.png" alt="0_1661500670214_1234.png" class=" img-fluid img-markdown" /><br />
<img src="/assets/uploads/files/1661500693693-aikit-resized.jpg" alt="0_1661500692158_aikit.jpg" class=" img-fluid img-markdown" /><br />
<strong>Problems</strong><br />
1: After the myCobot280 generally runs for a while, the machine heats up, and the RVIZ cannot run normally.<br />
2: On the Raspberry Pi version, after opening the RVIZ,  I found that the computer's CPU was instantly occupied and could not run stably.<br />
<strong>Try to solve</strong></p>
<ol>
<li>At first, I thought that the file <strong>(URDF)</strong> of the built model was too large, which made RVIZ freeze. We optimized the model file <strong>(URDF)</strong> and found little improvement.<br />
<strong>Reflections：</strong><br />
1: It is relatively stable to run programs with a small amount of code, so is it possible to optimize the code to improve the stability of <strong>RVIZ?</strong> We are currently trying to migrate its adaptation environment from <strong>ROS1</strong> to <strong>ROS2</strong> to see if the whole will be more stable.<br />
2: When the <strong>RVIZ</strong> is turned on, the <strong>CPU</strong> is full. We try to start with the <strong>CPU</strong> to see if we can improve the performance of the <strong>CPU</strong> processing to be more stable.</li>
<li>After I modified the <strong>CPU</strong> processing capability of the virtual machine, it was much more stable when I used it again. You may think that Raspberry Pi is a computer. How to upgrade the <strong>CPU?</strong> Is it going to have to change the motherboard? We use a socket method to connect to the Raspberry Pi (like a <strong>TCP/IP</strong> connection) to solve this problem.<br />
<strong>Socket function:</strong><br />
The principle of the socket method is to use its virtual machine to establish a connection with <strong>myCobot280-Pi</strong> (remote control), and the virtual machine sends instructions to <strong>myCobot280-Pi</strong> instead of sending instructions to the robotic arm in its Pi motherboard. This solves the problem of low <strong>CPU</strong> performance.<br />
code:</li>
</ol>
<pre><code>def get_logger(name):
    logger = logging.getLogger(name)
    logger.setLevel(logging.DEBUG)

    LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
    #DATE_FORMAT = "%m/%d/%Y %H:%M:%S %p"

    formatter = logging.Formatter(LOG_FORMAT)
    # console = logging.StreamHandler()
    # console.setFormatter(formatter)

    save = logging.handlers.RotatingFileHandler(
        "/home/ubuntu/mycobot_server.log", maxBytes=10485760, backupCount=1)
    save.setFormatter(formatter)

    logger.addHandler(save)
    # logger.addHandler(console)
    return logger


class MycobotServer(object):

    def __init__(self, host, port):
        try:
            GPIO.setwarnings(False)
        except:
            pass
        self.logger = get_logger("AS")
        self.mc = None
        self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.s.bind((host, port))
        print "Binding succeeded!"
        self.s.listen(1)
        self.connect()

    def connect(self):
        while True:
            try:
                print "waiting connect!------------------"
                conn, addr = self.s.accept()
                port_baud = []
                while True:
                    try:
                        print "waiting data--------"
                        data = conn.recv(1024)
                        command = data.decode('utf-8')
                        if data.decode('utf-8') == "":
                            print("close disconnect!")
                            break
                        res = b'1'
                        command = command.replace(" ", "")
                        if len(port_baud) &lt; 3:

                            port_baud.append(command)
                            if len(port_baud) == 3:
                                self.mc = serial.Serial(
                                    port_baud[0], port_baud[1], timeout=float(port_baud[1]))
                                port_baud.append(1)
                        else:
                            self.logger.info(command)
                            command = self.re_data_2(command)
                            if command[3] == 170:
                                if command[4] == 0:
                                    GPIO.setmode(GPIO.BCM)
                                else:
                                    GPIO.setmode(GPIO.BOARD)
                            elif command[3] == 171:
                                if command[5]:
                                    GPIO.setup(command[4], GPIO.OUT)
                                else:
                                    GPIO.setup(command[4], GPIO.IN)

                            elif command[3] == 172:
                                GPIO.output(command[4], command[5])

                            elif command[3] == 173:
                                res = bytes(GPIO.input(command[4]))

                            self.write(command)
                            res = self.read()
                            if res == None:
                                res = b'1'
                        conn.sendall(res)
                    except Exception as e:
                        self.logger.error(str(e))
                        conn.sendall(str.encode("ERROR:"+str(e)))
                        break
            except Exception as e:
                self.logger.error(str(e))
                conn.close()

    def write(self, command):
        self.mc.write(command)
        self.mc.flush()
        time.sleep(0.05)

    def read(self):
        data = None
        if self.mc.inWaiting() &gt; 0:
            data = self.mc.read(self.mc.inWaiting())
        return data

    def re_data_2(self, command):
        r2 = re.compile(r'[[](.*?)[]]')
        data_str = re.findall(r2, command)[0]
        data_list = data_str.split(",")
        data_list = [int(i) for i in data_list]
        return data_list
</code></pre>
<p dir="auto"><em>（The essence of the socket approach is to use a virtual machine to connect to the Raspberry Pi, and we then boost the CPU processing power of the virtual machine.）</em><br />
<strong>Discuss:</strong><br />
For now, our solution for RVIZ is just this. I am wondering whether there is a better way to handle your RVIZ related issues. Everyone is welcome to discuss, and I will learn from your opinions and put them into practice.</p>
]]></description><link>https://community.m5stack.com/topic/4559/how-to-solve-the-problem-of-rviz-freezing</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 21:00:29 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/4559.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 26 Aug 2022 08:04:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to solve the problem of RVIZ freezing? on Wed, 31 Aug 2022 01:05:21 GMT]]></title><description><![CDATA[<p dir="auto">This looks like a good suggestion.</p>
]]></description><link>https://community.m5stack.com/post/18505</link><guid isPermaLink="true">https://community.m5stack.com/post/18505</guid><dc:creator><![CDATA[ElephantRobotics]]></dc:creator><pubDate>Wed, 31 Aug 2022 01:05:21 GMT</pubDate></item><item><title><![CDATA[Reply to How to solve the problem of RVIZ freezing? on Mon, 29 Aug 2022 08:58:48 GMT]]></title><description><![CDATA[<p dir="auto">Please check that you are using gpu acceleration and not just software rendering. This can be seen in the output of rviz at startup for example</p>
]]></description><link>https://community.m5stack.com/post/18482</link><guid isPermaLink="true">https://community.m5stack.com/post/18482</guid><dc:creator><![CDATA[kehu]]></dc:creator><pubDate>Mon, 29 Aug 2022 08:58:48 GMT</pubDate></item></channel></rss>