Tentando Executar um Script python no terminal LX com o TriggerCMD mas não estou conseguindo
-
{"trigger":"Pegar_Objeto.sh","command":"/home/pi/TonyPi/Extend/Pegar_Objeto.sh","ground":"background","voice":"Pegar Objeto","allowParams": "false"},
-
{"trigger":"ApriltagTrack.py","command":"/home/pi/TonyPi/Extend/Pegar_Objeto.sh","offCommand":"killall python3","ground":"background","voice":"Pegar Objeto","allo$
-
@Antonio-Francisco-S-Santos, please try this as your offCommand after you confirm it works manually.
kill -9 $(pgrep -f "/usr/bin/python3 /home/pi/TonyPi/Extend/ApriltagTrack.py")
-
Executando direto do terminal aparece:
pi@TonyPiPro:~ $ kill -9 $(pgrep -f "/usr/bin/python3 /home/pi/TonyPi/Extend/ApriltagTrack.py")
-bash: kill: (1683) - Opera▒▒o n▒o permitida
pi@TonyPiPro:~ $ -
@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\")"
-
@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"} -
@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" }
-
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"} -
@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"}, -
@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?
-
@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?
-
@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)",
-
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 -
@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
-
@Antonio-Francisco-S-Santos Testei esse comando no TriggerCMD, funcionou perfeitamente só um Script que ficou dando esse erro:
-
@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
-
@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 -
@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 -
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 Boardprint('''
功能:幻尔科技TonyPi扩展板,PWM舵机控制例程
Official website:http://www.hiwonder.com
Online mall:https://huaner.tmall.com/以下指令均需在LX终端使用,LX终端可通过ctrl+alt+t打开,或点
击上栏的黑色LX终端图标。Usage:
python3 BusServoMove.pyVersion: --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)
-