TRIGGERcmd
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Tentando Executar um Script python no terminal LX com o TriggerCMD mas não estou conseguindo

    Raspberry Pi
    2
    80
    4.9k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • RussR
      Russ @Antonio Francisco S.Santos
      last edited by Russ

      @Antonio-Francisco-S-Santos, it's saying you don't have access, so you'll need to prefix the command with sudo, like this:

      sudo kill -9 $(pgrep -f "/usr/bin/python3 /home/pi/TonyPi/Extend/ApriltagTrack.py")
      

      I see you're running the TRIGGERcmd background agent, which runs as root, so you don't need the sudo prefix when you add it to your commands.json.

      You'll need to escape the command's quotes too, like this:

      "offCommand": "kill -9 $(pgrep -f \"/usr/bin/python3 /home/pi/TonyPi/Extend/ApriltagTrack.py\")"
      

      Russell VanderMey

      1 Reply Last reply Reply Quote 0
      • Antonio Francisco S.SantosA
        Antonio Francisco S.Santos
        last edited by

        @Russ said in Tentando Executar um Script python no terminal LX com o TriggerCMD mas não estou conseguindo:

        Quando tento montar o comando ele só salvar dessa maneira:
        {"trigger":"Sonar_barrier.py","command":"/home/pi/TonyPi/Extend/Caminhar.sh","offCommand":"kill -9 $(pgrep -f","ground":"background","voice":"Caminhar","allowParams": "false"}

        RussR 1 Reply Last reply Reply Quote 0
        • RussR
          Russ @Antonio Francisco S.Santos
          last edited by Russ

          @Antonio-Francisco-S-Santos, you need "allowParam": "true". Otherwise the agent will ignore the offCommand field.

          Please try this entry.

           {
            "trigger": "Sonar Barrier",
            "command": "/home/pi/TonyPi/Extend/Caminhar.sh",
            "offCommand": "kill -9 $(pgrep -f \"/usr/bin/python3 /home/pi/TonyPi/Extend/ApriltagTrack.py\")",
            "ground": "foreground",
            "voice": "Caminhar",
            "voiceReply": "",
            "allowParams": "true"
           }
          

          Russell VanderMey

          Antonio Francisco S.SantosA 1 Reply Last reply Reply Quote 0
          • Antonio Francisco S.SantosA
            Antonio Francisco S.Santos
            last edited by

            Olá, Com esse ultimo comando que você me mandou não faz nenhuma ação
            {"trigger":"ApriltagTrack.py","command":"/home/pi/TonyPi/Extend/Pegar_Objeto.sh","offCommand":"kill -9 $(pgrep -f "/usr/bin/python3 /home/pi/TonyPi/Extend/ApriltagTrack.py")","ground":"foreground","voice":"Fechar Objeto","voiceReplay": "","allowParams": "true"}

            1 Reply Last reply Reply Quote 0
            • Antonio Francisco S.SantosA
              Antonio Francisco S.Santos @Russ
              last edited by

              @Russ Esse comando executa a função perfeitamente mas quando executo o comando de fechar nada acontece:
              {"trigger":"Pegar_Objeto.sh","command":"/home/pi/TonyPi/Extend/Pegar_Objeto.sh","ground":"background","voice":"Pegar Objeto","allowParams": "false"},

              RussR 1 Reply Last reply Reply Quote 0
              • RussR
                Russ @Antonio Francisco S.Santos
                last edited by Russ

                @Antonio-Francisco-S-Santos, I don't know why it's not killing your python script. Maybe try killing your Pegar_Objeto.sh bash script instead.

                "offCommand": "kill -9 $(pgrep -f \"/bin/bash /home/pi/TonyPi/Extend/Pegar_Objeto.sh\")",
                

                How do you know it's not killing your script. Are you listing your processes with ps -ef after you run the command with "off" as the parameter?

                Russell VanderMey

                Antonio Francisco S.SantosA 1 Reply Last reply Reply Quote 0
                • Antonio Francisco S.SantosA
                  Antonio Francisco S.Santos @Russ
                  last edited by

                  @Russ Olá Professor não consegue fechar os Script quando executado pelo TriggerCMD, se executar dentro do Debian no Terminal e abrir outro terminal com o comando Kill consegue fechar. o que pode ser professor?

                  RussR 1 Reply Last reply Reply Quote 0
                  • RussR
                    Russ @Antonio Francisco S.Santos
                    last edited by Russ

                    @Antonio-Francisco-S-Santos, Google translated that as, "... cannot close the Script when executed by TriggerCMD, if you run it inside Debian in Terminal and open another terminal with the Kill command you can close it."

                    So I think you're saying this kill command only kills the Pegar_Objeto.sh script when you run the Pegar_Objeto.sh script manually, but not if you run it via TRIGGERcmd?

                    kill -9 $(pgrep -f "/bin/bash /home/pi/TonyPi/Extend/Pegar_Objeto.sh")
                    

                    If you look at the pgrep command's help, you'll see that the -f parameter specifies the full process name, but I found that you can specify a partial process name.

                    $ pgrep --help
                    Usage:
                     pgrep [options] <pattern>
                    
                    Options:
                     -d, --delimiter <string>  specify output delimiter
                     -l, --list-name           list PID and process name
                     -a, --list-full           list PID and full command line
                     -v, --inverse             negates the matching
                     -w, --lightweight         list all TID
                     -c, --count               count of matching processes
                     -f, --full                use full process name to match
                    

                    So please try this instead:

                    kill -9 $(pgrep -f Pegar_Objeto.sh)
                    

                    In your commands.json it would look like this:

                    "offCommand": "kill -9 $(pgrep -f Pegar_Objeto.sh)",
                    

                    Russell VanderMey

                    Antonio Francisco S.SantosA 1 Reply Last reply Reply Quote 0
                    • Antonio Francisco S.SantosA
                      Antonio Francisco S.Santos
                      last edited by

                      Executei esse comando manualmente mas não reve efeito:
                      kill -9 $(pgrep -f "/bin/bash /home/pi/TonyPi/Extend/Pegar_Objeto.sh")

                      Coloquei tambem o endereço do código principal:
                      kill -9 $(pgrep -f "/bin/bash /home/pi/TonyPi/Extend/ApriltagTrack.py")
                      Mesmo assim não fechou o Script

                      Antonio Francisco S.SantosA 1 Reply Last reply Reply Quote 0
                      • Antonio Francisco S.SantosA
                        Antonio Francisco S.Santos @Russ
                        last edited by

                        @Russ said in Tentando Executar um Script python no terminal LX com o TriggerCMD mas não estou conseguindo:

                        kill -9 $(pgrep -f Pegar_Objeto.sh)

                        Agora colando dessa forma no terminal ele consegue fechar:
                        kill -9 $(pgrep -f ApriltagTrack.py)

                        Ainda não testei esse comando la no TriggerCMD

                        1 Reply Last reply Reply Quote 0
                        • Antonio Francisco S.SantosA
                          Antonio Francisco S.Santos @Antonio Francisco S.Santos
                          last edited by

                          @Antonio-Francisco-S-Santos Testei esse comando no TriggerCMD, funcionou perfeitamente só um Script que ficou dando esse erro:
                          64e7dafc-1627-45ad-acba-6d3c72549238-2023-06-03-211559_1920x1080_scrot.png

                          RussR Antonio Francisco S.SantosA 2 Replies Last reply Reply Quote 0
                          • RussR
                            Russ @Antonio Francisco S.Santos
                            last edited by

                            @Antonio-Francisco-S-Santos, that kill command requires root access, so if you prefix that command with sudo it should work. You could also run the script with sudo like this:

                            sudo /home/pi/TonyPi/Extend/Stop_Caminhar.sh
                            

                            Russell VanderMey

                            1 Reply Last reply Reply Quote 0
                            • Antonio Francisco S.SantosA
                              Antonio Francisco S.Santos @Antonio Francisco S.Santos
                              last edited by

                              @Antonio-Francisco-S-Santos Professor Você é um gênio os Comandos agora funcionaram perfeitamente, com o sudo no inicio como você mencionou. Obrigado meu irmão.
                              Agora uma outra dúvida:
                              Como saber o nível da bateria que alimenta o Raspberry pi pelo Trigger CMD? Seria isso mais ou menos:
                              battery_monitor

                              RussR 1 Reply Last reply Reply Quote 0
                              • RussR
                                Russ @Antonio Francisco S.Santos
                                last edited by

                                @Antonio-Francisco-S-Santos, awesome! I'm glad it's all working now.

                                About monitoring your battery - I don't think the Raspberry Pi can monitor its input power voltage without an external circuit, maybe like this HAT:
                                https://www.elecrow.com/wiki/index.php?title=Current/Voltage/Power_Monitor_HAT_for_Raspberry_Pi

                                Russell VanderMey

                                1 Reply Last reply Reply Quote 0
                                • Antonio Francisco S.SantosA
                                  Antonio Francisco S.Santos
                                  last edited by

                                  Professor, Tenho outra dúvida, esse código .py abrindo ele na IDE Thoony Python ele funciona normal mas se criar um Script .sh ele reconhece o Giroscópio e o Acelerómetro mas não faz nenhuma ação. aparece esse erro:
                                  latin-1' codec can't encode character '\uff01' in position 12: ordinal not in range(256)

                                  Aqui estar o Código:
                                  import time
                                  import hiwonder.Board as Board

                                  print('''


                                  功能:幻尔科技TonyPi扩展板,PWM舵机控制例程



                                  Official website:http://www.hiwonder.com
                                  Online mall:https://huaner.tmall.com/

                                  以下指令均需在LX终端使用,LX终端可通过ctrl+alt+t打开,或点
                                  击上栏的黑色LX终端图标。

                                  Usage:
                                  python3 BusServoMove.py

                                  Version: --V1.2 2021/07/03

                                  Tips:

                                  • 按下Ctrl+C可关闭此次程序运行,若失败请多次尝试!

                                  ''')

                                  while True:
                                  # 参数:参数1:舵机接口编号; 参数2:位置; 参数3:运行时间
                                  Board.setPWMServoPulse(2, 1500, 500) # 2号舵机转到1500位置,用时500ms
                                  time.sleep(0.5) # 延时时间和运行时间相同

                                  Board.setPWMServoPulse(2, 1800, 800) #舵机的转动范围0-180度,对应的脉宽为500-2500,即参数2的范围为500-2500
                                  time.sleep(0.5)
                                  
                                  Board.setPWMServoPulse(2, 1500, 300)
                                  time.sleep(0.2)
                                  
                                  Board.setPWMServoPulse(2, 1800, 800)  
                                  Board.setPWMServoPulse(1, 1800, 800)
                                  time.sleep(0.5)
                                  
                                  Board.setPWMServoPulse(2, 1500, 800)  
                                  Board.setPWMServoPulse(1, 1500, 800)
                                  time.sleep(0.5)
                                  
                                  Antonio Francisco S.SantosA 1 Reply Last reply Reply Quote 0
                                  • Antonio Francisco S.SantosA
                                    Antonio Francisco S.Santos @Antonio Francisco S.Santos
                                    last edited by

                                    @Antonio-Francisco-S-Santos Erro.png Equilibrio.png

                                    Antonio Francisco S.SantosA 1 Reply Last reply Reply Quote 0
                                    • Antonio Francisco S.SantosA
                                      Antonio Francisco S.Santos @Antonio Francisco S.Santos
                                      last edited by

                                      @Antonio-Francisco-S-Santos Desculpe, O Código que me refiro é esse aqui:

                                      #!/usr/bin/python3

                                      coding=utf8

                                      import sys
                                      import time
                                      import math
                                      import hiwonder.Mpu6050 as Mpu6050
                                      import hiwonder.ActionGroupControl as AGC
                                      import hiwonder.Board as Board

                                      mpu = Mpu6050.mpu6050(0x68)#启动Mpu6050
                                      mpu.set_gyro_range(mpu.GYRO_RANGE_2000DEG)#设置Mpu6050的陀螺仪的工作范围
                                      mpu.set_accel_range(mpu.ACCEL_RANGE_2G)#设置Mpu6050的加速度计的工作范围

                                      count1 = 0
                                      count2 = 0

                                      def standup():
                                      global count1, count2

                                      try:
                                          accel_date = mpu.get_accel_data(g=True) #获取传感器值
                                          angle_y = int(math.degrees(math.atan2(accel_date['y'], accel_date['z']))) #将获得的数据转化为角度值
                                          
                                          if abs(angle_y) > 105: #y轴角度大于160,count1加1,否则清零
                                              count1 += 1
                                          else:
                                              count1 = 0
                                      
                                          if abs(angle_y) < 85: #y轴角度小于10,count2加1,否则清零
                                              count2 += 1
                                          else:
                                              count2 = 0
                                      
                                          time.sleep(0.1)
                                          
                                          if count1 >= 1: #往前倒了一定时间后起来
                                              count1 = 0  
                                              print("equilibrio_1!")#打印执行的动作名
                                              AGC.runActionGroup('equilibrio_1')#执行动作
                                              Board.setPWMServoPulse(1, 1300, 700)
                                              Board.setPWMServoPulse(2, 1500, 700)
                                              time.sleep(0.8)
                                              AGC.runActionGroup('stand') 
                                          
                                          elif count2 >= 1: #往后倒了一定时间后起来
                                              count2 = 0
                                              print("equilibrio_2!")#打印执行的动作名
                                              AGC.runActionGroup('equilibrio_2')#执行动作            
                                              Board.setPWMServoPulse(1, 1500, 700)
                                              Board.setPWMServoPulse(2, 1500, 700)
                                              time.sleep(0.8)
                                              AGC.runActionGroup('stand') 
                                          
                                      except BaseException as e:
                                          print(e)
                                      

                                      if name == 'main':
                                      print("Fall_and_Stand Init")
                                      print("Fall_and_Stand Start")
                                      while True : #循环检测机器人的状态
                                      standup()
                                      key = time.sleep(0.1)
                                      if key == 27:
                                      break

                                      1 Reply Last reply Reply Quote 0
                                      • First post
                                        Last post