python脚本实现rikirobot追寻红线功能,并实时保存数据的代码

2 篇文章 0 订阅
1 篇文章 0 订阅

import paramiko
import time
from threading import Thread




def ssh1():
    sum = 1
    sshClient = paramiko.SSHClient()
    sshClient.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    sshClient.connect(hostname = "192.168.123.213", port = 22, username = "firefly", password = "firefly")

    shell = sshClient.invoke_shell()
    shell.sendall("roslaunch rikirobot bringup.launch\n")
    # shell.sendall("ls\n")
    shell.sendall("exit\n")

    while True:
        # shell.sendall("^c\n")
        data = shell.recv(2048).decode()
        result = str(data)
        with open('result_line.txt','a') as file:
            file.write("{}\n".format(result))
        time.sleep(0.4)
        sum = sum + 1
        if (sum==30):
            break
        # if  0xff == ord('q'):
            # break
        print(data, end = "")
    # sshClient.close()
def ssh2():
    sum2 = 1
    sshClient2 = paramiko.SSHClient()
    sshClient2.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    sshClient2.connect(hostname="192.168.123.213", port=22, username="firefly", password="firefly")

    shell2 = sshClient2.invoke_shell()
    # shell2.sendall("roslaunch riki_follower follower.launch\n")
    shell2.sendall("roslaunch openni2_launch openni2.launch\n")
    # shell2.sendall("ifconfig\n")
    shell2.sendall("exit\n")
    while True:
        data2 = shell2.recv(2048).decode()
        result2 = str(data2)
        with open('result_line2.txt','a') as file2:
            file2.write("{}\n".format(result2))
        time.sleep(0.3)
        sum2 = sum2+1
        if sum2 == 30:
            print("quit now")
            break
        # print(data2, end = "")
        print(data2, end="")
    # sshClient2.close()

if __name__ == '__main__':
    t1 = Thread(target=ssh1())
    t2 = Thread(target=ssh2())
    t1.start()
    t2.start()


再开第二个代码

import paramiko
import time
from threading import Thread
#这是跟随红线模式
def ssh1():
    sum = 1
    sshClient = paramiko.SSHClient()
    sshClient.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    sshClient.connect(hostname = "192.168.123.213", port = 22, username = "firefly", password = "firefly")

    shell = sshClient.invoke_shell()
    shell.sendall("roslaunch rikirobot bringup.launch\n")
    # shell.sendall("ls\n")
    shell.sendall("exit\n")

    while True:
        # shell.sendall("^c\n")
        data = shell.recv(2048).decode()
        result = str(data)
        with open('result_people.txt','a') as file:
            file.write("{}\n".format(result))
        time.sleep(0.4)
        sum = sum + 1
        if (sum==35):
            break
        # if  0xff == ord('q'):
            # break
        print(data, end = "")
    # sshClient.close()
def ssh2():
    sum2 = 1
    sshClient2 = paramiko.SSHClient()
    sshClient2.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    sshClient2.connect(hostname="192.168.123.213", port=22, username="firefly", password="firefly")
    shell2 = sshClient2.invoke_shell()
    shell2.sendall("roslaunch openni2_launch openni2.launch\n")
    # shell2.sendall("ifconfig\n")
    shell2.sendall("exit\n")
    while True:
        data2 = shell2.recv(2048).decode()
        result2 = str(data2)
        with open('result_people2.txt','a') as file2:
            file2.write("{}\n".format(result2))
        time.sleep(0.3)
        sum2 = sum2+1
        if sum2 == 30:
            print("quit now")
            break
        # print(data2, end = "")
        print(data2, end="")
    sshClient2.close()

def ssh3():
    sum3 = 1
    sshClient3 = paramiko.SSHClient()
    sshClient3.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    sshClient3.connect(hostname="192.168.123.213", port=22, username="firefly", password="firefly")

    shell3 = sshClient3.invoke_shell()
    shell3.sendall("roslaunch  riki_line_follower  riki_line.launch\n")
    # shell2.sendall("ifconfig\n")
    shell3.sendall("exit\n")
    while True:
        data3 = shell3.recv(2048).decode()
        result3 = str(data3)
        with open('result_line3.txt','a') as file3:
            file3.write("{}\n".format(result3))
        if 0xff == ord('q'):
            break
        print(data3, end="")
    sshClient3.close()

if __name__ == '__main__':
    # t1 = Thread(target=ssh1())
    # t2 = Thread(target=ssh2())
    t3 = Thread(target=ssh3())
    # t1.start()
    # t2.start()
    t3.start()
    print("结束")

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值