Tentando Executar um Script python no terminal LX com o TriggerCMD mas não estou conseguindo
-
@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)
-
-
@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 Boardmpu = 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 = 0def standup():
global count1, count2try: 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