Search code examples
pythonrobotpeppernao-robotchoregraphe

Pepper robot keeps showing the same Image


I am programing a pepper robot with choregraphe and when I show and image and try to show another image in the same behavior or a different behavior it shows the same image. Does anyone know how to actually show the image I want?


Solution

  • this is from a different thread, I cant find it again but make sure your show image box looks like this (look at the bottom for additional code)

    def onLoad(self):
        pass
    
    def onUnload(self):
        pass
    
    def _getTabletService(self):
        tabletService = None
        try:
            tabletService = self.session().service("ALTabletService")
        except Exception as e:
            self.logger.error(e)
        return tabletService
    
    def _getAbsoluteUrl(self, partial_url):
        import os
        subPath = os.path.join(self.packageUid(), os.path.normpath(partial_url).lstrip("\\/"))
        # We create TabletService here in order to avoid
        # problems with connections and disconnections of the tablet during the life of the application
        return "http://%s/apps/%s" %(self._getTabletService().robotIp(), subPath.replace(os.path.sep, "/"))
    
    def onInput_onStart(self):
        # We create TabletService here in order to avoid
        # problems with connections and disconnections of the tablet during the life of the application
        import time
        tabletService = self._getTabletService()
        if tabletService:
            try:
                url = self.getParameter("ImageUrl")
                if url == '':
                    self.logger.error("URL of the image is empty")
                if not url.startswith('http'):
                    url = self._getAbsoluteUrl(url)
                url += "?" + str(time.time())
                tabletService.showImage(url)
            except Exception as err:
                self.logger.error("Error during ShowImage : %s " % err)
                self.onStopped()
        else:
            self.logger.warning("No ALTabletService, can't display the image.")
            self.onStopped()
    
    def onInput_onHideImage(self):
        # We create TabletService here in order to avoid
        # problems with connections and disconnections of the tablet during the life of the application
        tabletService = self._getTabletService()
        if tabletService:
            try:
                tabletService.hideImage()
            except Exception as err:
                self.logger.error("Error during HideImage : %s " % err)
                self.onStopped()
        else:
            self.logger.warning("No ALTabletService, can't hide the image.")
            self.onStopped()
    
    def onInput_onPreLoadImage(self):
        # We create TabletService here in order to avoid
        # problems with connections and disconnections of the tablet during the life of the application
        tabletService = self._getTabletService()
        if tabletService:
            try:
                partialUrl = self.getParameter("ImageUrl")
                fullUrl = self._getAbsoluteUrl(partialUrl)
                self.logger.warning(fullUrl)
                os.remove(fullUrl)
            except Exception as err:
                self.logger.warning("Error during preLoadImage : %s " % err)
                self.onStopped()
        else:
            self.logger.warning("No ALTabletService, can't preload the image.")
            self.onStopped()
    
    def onInput_onStop(self):
        self.onUnload()
        self.onStopped()
    
    def _getAppName(self):
        import os
        if self.frameManager:
            behaviorPath = os.path.normpath(self.frameManager.getBehaviorPath(self.behaviorId))
            appsFolderFragment = os.path.join("PackageManager", "apps")
            if not (appsFolderFragment in behaviorPath):
                self.logger.error("appsFolderFragment is not in behaviorPath")
            fragment = behaviorPath.split(appsFolderFragment, 1)[1]
            #Additional code:from here
            fragment = fragment.split('/')[1]
            #Additional code:So far
            return fragment.lstrip("\\/")
        else:
            self.logger.warning("No ALFrameManager")