電子發(fā)燒友App

硬聲App

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示
創(chuàng)作
電子發(fā)燒友網(wǎng)>電子資料下載>電子資料>帶有Arduino和Python的AI助手機(jī)器人

帶有Arduino和Python的AI助手機(jī)器人

2022-10-18 | zip | 0.05 MB | 次下載 | 免費(fèi)

資料介紹

描述

介紹:

我們都熟悉《鋼鐵俠》電影和漫威系列中的“賈維斯”AI手機(jī)器人。自己動(dòng)手做東西一直是程序員的夢(mèng)想。今天我將展示一種使用 Python 編程制作這樣一個(gè)助手的簡(jiǎn)單方法。而且,我還會(huì)給那個(gè)機(jī)器人做一個(gè)物理化身,這樣每當(dāng)我們和機(jī)器人說(shuō)話的時(shí)候,它就可以做一些動(dòng)作。這將比僅僅一個(gè)軟件機(jī)器人更令人驚奇。因?yàn)槿绻猩眢w,那就很酷了。所以今天我們將學(xué)習(xí)使用Arduino和Python編程來(lái)制作一個(gè)可以控制您的計(jì)算機(jī)并與您閑聊的AIrobot。讓我們跳進(jìn)去!

為什么我將機(jī)器人命名為“黃疸”?因?yàn)槲野阉砍牲S色,非常非常黃!

部分:

電子產(chǎn)品 -

Arduino Nano – 1x

微型伺服 Sg90 – 3x

超聲波傳感器 HCsr04– 1x

身體 -

PVC片材(最好是白色的,上色更好,我用的是藍(lán)色的)

伺服輪(用于支架)

工具:

切刀

剪刀

熱膠

噴漆

軟件-

Python3

Arduino.ide

原則:

在進(jìn)入實(shí)際建筑之前,很高興知道我們將要做什么。

那么,主要代碼或AI部分代碼會(huì)在電腦上運(yùn)行,為什么呢?因?yàn)樗С?python 并且比小 Arduino 具有更多的處理能力,而且 AI bot 將控制/自動(dòng)化我的電腦的一些任務(wù),它必須在我的電腦上運(yùn)行。因此,Arduinoboard 使用 USB 電纜連接到我的計(jì)算機(jī)。

這個(gè)想法是運(yùn)行一個(gè) python 程序,它將執(zhí)行 Speech totext 部分,處理文本并且還將執(zhí)行 Text to Speech。意味著機(jī)器人會(huì)傾聽(tīng)、理解和回話。對(duì)于身體運(yùn)動(dòng),我在 Arduino 板上保存了一些運(yùn)動(dòng)(封裝在函數(shù)中)。每個(gè)動(dòng)作的功能由python代碼執(zhí)行。

例如——如果機(jī)器人必須說(shuō)“Hi/hello”,python 代碼將發(fā)送一個(gè)字節(jié)“h”,Arduino 然后執(zhí)行 hi() 函數(shù)。就如此容易。

現(xiàn)在您有了一個(gè)想法,讓我們繼續(xù)下一個(gè)過(guò)程。

電路和電子

schematic_try2_2020-11-15_05-56-45_3WXd4ccplp.png?auto=compress%2Cformat&w=740&h=555&fit=max

1 / 2

電路是讓大多數(shù)制造商煩惱的事情。如果出現(xiàn)問(wèn)題,您可能會(huì)燒掉一些昂貴的零件。為此,我設(shè)計(jì)了一個(gè)可用于制作大量項(xiàng)目的 PCB 板。它有微型 SD 卡插槽、藍(lán)牙模塊插槽、5v 外部電源,整個(gè)設(shè)備由 Arduino Nano 供電

我使用 EasyEDA 設(shè)計(jì)了一個(gè) PCB ,并使用PCBWay在線服務(wù)進(jìn)行了打印。他們的服務(wù)很棒。我訂購(gòu)了PCB 即時(shí)報(bào)價(jià),他們的系統(tǒng)自動(dòng)為我完成了所有工作。三天之內(nèi),我從中國(guó)一路拿到了板子到孟加拉國(guó)。質(zhì)量非常好,阻焊層完美,線條/痕跡,光潔度盡可能好。

無(wú)論如何,我使用了.300 mmtraces,因?yàn)樗梢猿惺?1Amp 電流。

您可以從這里下載 PCB 文件。

焊接?xùn)|西和測(cè)試電路:

pcb_Rp4t3zU6IH.jpg?auto=compress%2Cformat&w=740&h=555&fit=max

在這一步中,我焊接了所有東西。小心不要吸入煙霧,它可能會(huì)致癌。

我沒(méi)有使用藍(lán)牙模塊或 TF 模塊,所以我沒(méi)有焊接那些。好消息是,我使用了 3 個(gè)伺服電機(jī)和一個(gè)聲納傳感器,所有東西都可以通過(guò)我們連接的 USB 電纜輕松供電,以對(duì) Arduino 進(jìn)行編程。這很棒,因?yàn)槲覀儾槐乜紤]其他電源。

但是,如果您仍然想使用外部電池,那么請(qǐng)使用 lipo 2s (7.4V) 電池,不僅如此,伺服器也會(huì)燒毀。

制作身體:

back_rubhV9FPgK.PNG?auto=compress%2Cformat&w=740&h=555&fit=max

1 / 13

我用PVC板做身體,你也可以用紙板。首先,我為主要部分做了一個(gè)盒子,里面有主板和伺服電機(jī)。這就像制作盒子一樣。我以同樣的方式制作了頭部,為傳感器制作了兩個(gè)孔(作為眼睛)。我已經(jīng)添加了你需要的所有圖片。我把一只手做成扳手,另一只手做成插頭。我實(shí)際上使用了一個(gè)插頭并使用熱膠將其添加到一個(gè)手臂上。

方面?實(shí)際上沒(méi)有,因?yàn)樗悄愕臋C(jī)器人,你可以使用一些簡(jiǎn)單的工具來(lái)制作它,讓它隨心所欲,讓它成為任何形狀和大小。

在關(guān)閉身體之前要非常小心地添加所有電子設(shè)備。在我放置傳感器和所有電子設(shè)備后,我畫了車身。不要那樣做,我已經(jīng)把我的 Arduino 染成了黃色。

所以,在車身上涂漆,然后放上所有的電子設(shè)備。

編碼1(Python):

python_add_to_path_rRkSskGfeN.png?auto=compress%2Cformat&w=740&h=555&fit=max

從此站點(diǎn)下載Python,確保在安裝時(shí)將 python 添加到您的路徑中。

安裝 Python 后,您需要從命令提示符/終端運(yùn)行一些命令來(lái)安裝用于語(yǔ)音識(shí)別、音頻支持、文本到語(yǔ)音、瀏覽器自動(dòng)化、串行通信目的的庫(kù)。運(yùn)行這些命令 -

?

pip installspeechrecognition
pip install pyaudio
pip install pyttsx3
pip install pywhatkit
pip install pyserial

?

然后從下面下載 pythoncode或從下面復(fù)制。前往coding2步驟。

?

 """ JAUNDICE: AI Assistant robot with Arduino and Python
author: ashraf minhaj
mail: ashraf_minhaj@yahoo.com
Last Edit: Nov 2020
License: Copyright (C) Ashraf Minhaj.
General Public License (GPL3+)
"""
import speech_recognition as sr   # voice recognition library
import random                     # to choose random words from list
import pyttsx3                    # offline Text to Speech
import datetime                   # to get date and time
import webbrowser                 # to open and perform web tasks
import serial                     # for serial communication
import pywhatkit                  # for more web automation
# Declare robot name (Wake-Up word)
robot_name = 'jaundice'
# random words list
hi_words = ['hi', 'hello', 'yo baby', 'salam']
bye_words = ['bye', 'tata', 'hasta la vista']
r_u_there = ['are you there', 'you there']
# initilize things
engine = pyttsx3.init()                    # init text to speech engine
#voices = engine.getProperty('voices')      #check for voices
#engine.setProperty('voice', voices[1].id)  # female voice
listener = sr.Recognizer()                 # initialize speech recognition API
# connect with NiNi motor driver board over serial communication
try:
   port = serial.Serial("COM15", 9600)
   print("Phycial body, connected.")
except:
   print("Unable to connect to my physical body")
def listen():
	""" listen to what user says"""
	try:
		with sr.Microphone() as source:                         # get input from mic
			print("Talk>>")
			voice = listener.listen(source)                     # listen from microphone
			command = listener.recognize_google(voice).lower()  # use google API
			# all words lowercase- so that we can process easily
			#command = command.lower()         
			print(command)
			# look for wake up word in the beginning
			if (command.split(' ')[0] == robot_name):
				# if wake up word found....
				print("[wake-up word found]")
				process(command)                 # call process funtion to take action
	except:
		pass
def process(words):
	""" process what user says and take actions """
	print(words) # check if it received any command
	# break words in
	word_list = words.split(' ')[1:]   # split by space and ignore the wake-up word
	if (len(word_list)==1):
		if (word_list[0] == robot_name):
		    talk("How Can I help you?")
		    #.write(b'l')
		    return
	if word_list[0] == 'play':
		"""if command for playing things, play from youtube"""
		talk("Okay boss, playing")
		extension = ' '.join(word_list[1:])                    # search without the command word
		port.write(b'u')
		pywhatkit.playonyt(extension)   
		port.write(b'l')          
		return
	elif word_list[0] == 'search':
		"""if command for google search"""
		port.write(b'u')
		talk("Okay boss, searching")
		port.write(b'l')
		extension = ' '.join(word_list[1:])
		pywhatkit.search(extension)
		return
	if (word_list[0] == 'get') and (word_list[1] == 'info'):
		"""if command for getting info"""
		port.write(b'u')
		talk("Okay, I am right on it")
		port.write(b'u')
		extension = ' '.join(word_list[2:])                    # search without the command words
		inf = pywhatkit.info(extension)
		talk(inf)                                              # read from result             
		return
	elif word_list[0] == 'open':
		"""if command for opening URLs"""
		port.write(b'l')
		talk("Opening, sir")
		url = f"http://{''.join(word_list[1:])}"   # make the URL
		webbrowser.open(url)
		return
	elif word_list[0] == 'uppercut':
		port.write(b'U')
	elif word_list[0] == 'smash':
		port.write(b's')
	elif word_list[0] == 'punch':
		port.write(b'p')
   # now check for matches
	for word in word_list:
		if word in hi_words:
			""" if user says hi/hello greet him accordingly"""
			port.write(b'h')               # send command to wave hand
			talk(random.choice(hi_words))
		elif word in bye_words:
			""" if user says bye etc"""
			talk(random.choice(bye_words))
def talk(sentence):
	""" talk / respond to the user """
	engine.say(sentence)
	engine.runAndWait()
# run the app
while True:
   listen()  # runs listen one time

?

編碼2(Arduino):

這部分很容易,無(wú)需安裝。使用Arduino.ide對(duì)開(kāi)發(fā)板進(jìn)行編程。如果您以前從未使用過(guò) Arduino,請(qǐng)從此處下載。

正如我之前提到的,Arduino 程序等待串行數(shù)據(jù),如果它接收到任何數(shù)據(jù),它會(huì)檢查字節(jié)數(shù)據(jù)。如果數(shù)據(jù)與預(yù)定義的命令匹配,則它執(zhí)行一條語(yǔ)句。如果發(fā)送'u',它會(huì)使兩只手都向上,就像那樣。

從下面的副本下載代碼。

?

 /** JAUNDICE: AI Assistant robot with Arduino and Python **
*  
*  author: ashraf minhaj
*  mail: ashraf_minhaj@yahoo.com
*  Last Edit: Nov 2020
*  
*  License: Copyright (C) Ashraf Minhaj.
*  General Public License (GPL3+)
*/
#include
Servo head;
Servo l_hand;
Servo r_hand;
// define sonar sensor's pins
int trig = 4;
int echo = 5;
// received data
byte val = "";
void setup() {
 // put your setup code here, to run once:
 head.attach(2);
 l_hand.attach(3);
 r_hand.attach(4);
 Serial.begin(9600); // for communicating via serial port with Python
}
void standby(){
 // all motors to these positions
 head.write(90);
 int r_pos = 30;
 int l_pos = map(r_pos, 0, 180, 180, 0);
 l_hand.write(l_pos);
 r_hand.write(r_pos);
}
void hi(){
 // all motors to these positions
 head.write(90);
 int i = 0;
 for(i=30; i<= 170; i++){
   r_hand.write(i);
   delay(5);
 }
 for(i=170; i>= 100; i--){
   r_hand.write(i);
   delay(5);
 }
 for(i=100; i<= 170; i++){
   r_hand.write(i);
   delay(5);
 }
 for(i=170; i>= 30; i--){
   r_hand.write(i);
   delay(5);
 }
 standby();
}
void hands_up(){
 // do this on every command (nothing much just move hands a bit)
 //head.write(150);
 //delay(300);
 //head.write(90);
 int i = 0;
 for(i=30; i<= 170; i++){
   int r_pos = i;
   int l_pos = map(r_pos, 0, 180, 180, 0);
   l_hand.write(l_pos);
   r_hand.write(r_pos);
   delay(5);
 }
 delay(600);
 for(i=170; i>= 30; i--){
   int r_pos = i;
   int l_pos = map(r_pos, 0, 180, 180, 0);
   l_hand.write(l_pos);
   r_hand.write(r_pos);
   delay(5);
 }
}
void weight_lift(){
 // lift weight using both hands
 int i = 0;
 for(i=30; i<= 170; i++){
   int r_pos = i;
   int l_pos = map(r_pos, 0, 180, 180, 0);
   l_hand.write(l_pos);
   r_hand.write(r_pos);
   delay(5);
 }
 for(int count=0; count<=4; count++){
   for(i=170; i>= 60; i--){
     int r_pos = i;
     int l_pos = map(r_pos, 0, 180, 180, 0);
     l_hand.write(l_pos);
     r_hand.write(r_pos);
     delay(5);
     }
   for(i=60; i<= 170; i++){
     int r_pos = i;
     int l_pos = map(r_pos, 0, 180, 180, 0);
     l_hand.write(l_pos);
     r_hand.write(r_pos);
     delay(5);
     }
   }
 for(i=170; i>= 30; i--){
   int r_pos = i;
   int l_pos = map(r_pos, 0, 180, 180, 0);
   l_hand.write(l_pos);
   r_hand.write(r_pos);
   delay(5);
 }
}
void excited(){
 return;
}
void look_left(){
 // rotate hed to left
 head.write(180);
}
void confused(){
 for(int count=0; count<=1; count++){
   head.write(30);
   r_hand.write(170);
   delay(700);
   r_hand.write(30);
   head.write(120);
   l_hand.write(30);
   delay(700);
   l_hand.write(160);
   }
 standby();
}
void double_punch(){
 // do a punch
 int i = 0;
 for(i=30; i>= 0; i--){
     int r_pos = i;
     int l_pos = map(r_pos, 0, 180, 180, 0);
     l_hand.write(l_pos);
     r_hand.write(r_pos);
     delay(5);
     }
 delay(2000);
 int r_pos = 80;
 int l_pos = map(r_pos, 0, 180, 180, 0);
 l_hand.write(l_pos);
 r_hand.write(r_pos);
 delay(500);
 standby();
}
void r_upper_cut(){
 // make right upper-cut
 int i = 0;
 for(i=30; i<= 170; i++){
   int r_pos = i;
   int l_pos = map(r_pos, 0, 180, 180, 0);
   l_hand.write(l_pos);
   r_hand.write(r_pos);
   delay(5);
 }
 for(int count=0; count<=4; count++){
   int i = 0;
   for(i=170; i>= 60; i--){
     r_hand.write(i);
     delay(1);
     }
   for(i=60; i<= 170; i++){
     r_hand.write(i);
     delay(1);
     }
   }
  standby();
  delay(100);
}
void smash(){
 // smash things
 int i = 0;
 for(i=30; i<= 170; i++){
   int r_pos = i;
   int l_pos = map(r_pos, 0, 180, 180, 0);
   l_hand.write(l_pos);
   r_hand.write(r_pos);
   delay(5);
 }
 delay(2000);
 for(i=170; i>= 0; i--){
   int r_pos = i;
   int l_pos = map(r_pos, 0, 180, 180, 0);
   l_hand.write(l_pos);
   r_hand.write(r_pos);
   delay(1);
 }
 delay(300);
 int r_pos = 180;
 int l_pos = map(r_pos, 0, 180, 180, 0);
 l_hand.write(l_pos);
 r_hand.write(r_pos);
 delay(1000);
 standby();
}
void eye_detect(){
 // do something if eye sensor detect motion
 return;
}
void loop() {
 // put your main code here, to run repeatedly:
 standby();
 while(Serial.available() > 0)  //look for serial data available or not
 {
   val = Serial.read();        //read the serial value
   if(val == 'h'){
     // do hi
      hi();
   }
   if(val == 'p'){
     // do hi
      double_punch();
   }
   if(val == 'u'){
     hands_up();
     delay(3000);
   }
   if(val == 'l'){
     standby();
     look_left();
     delay(2000);
   }
   if(val == 'U'){
     // uppercut
     r_upper_cut();
     delay(2000);
   }
   if(val == 's'){
     smash();
     delay(2000);
   }
 }
}

?

上傳代碼。

將所有內(nèi)容放在一起并完成:

完成所有這些步驟后,我使用 USB 電纜將我的 Arduino 連接到 pc,然后運(yùn)行 ??python 程序。當(dāng)您使用它時(shí),請(qǐng)確保在 python 代碼中添加正確的 Arduino 端口。如果你按照我提到的那樣做所有事情,機(jī)器人應(yīng)該像魅力一樣工作。

謝謝你!

下載該資料的人也在下載 下載該資料的人還在閱讀
更多 >

評(píng)論

查看更多

下載排行

本周

  1. 1山景DSP芯片AP8248A2數(shù)據(jù)手冊(cè)
  2. 1.06 MB  |  532次下載  |  免費(fèi)
  3. 2RK3399完整板原理圖(支持平板,盒子VR)
  4. 3.28 MB  |  339次下載  |  免費(fèi)
  5. 3TC358743XBG評(píng)估板參考手冊(cè)
  6. 1.36 MB  |  330次下載  |  免費(fèi)
  7. 4DFM軟件使用教程
  8. 0.84 MB  |  295次下載  |  免費(fèi)
  9. 5元宇宙深度解析—未來(lái)的未來(lái)-風(fēng)口還是泡沫
  10. 6.40 MB  |  227次下載  |  免費(fèi)
  11. 6迪文DGUS開(kāi)發(fā)指南
  12. 31.67 MB  |  194次下載  |  免費(fèi)
  13. 7元宇宙底層硬件系列報(bào)告
  14. 13.42 MB  |  182次下載  |  免費(fèi)
  15. 8FP5207XR-G1中文應(yīng)用手冊(cè)
  16. 1.09 MB  |  178次下載  |  免費(fèi)

本月

  1. 1OrCAD10.5下載OrCAD10.5中文版軟件
  2. 0.00 MB  |  234315次下載  |  免費(fèi)
  3. 2555集成電路應(yīng)用800例(新編版)
  4. 0.00 MB  |  33566次下載  |  免費(fèi)
  5. 3接口電路圖大全
  6. 未知  |  30323次下載  |  免費(fèi)
  7. 4開(kāi)關(guān)電源設(shè)計(jì)實(shí)例指南
  8. 未知  |  21549次下載  |  免費(fèi)
  9. 5電氣工程師手冊(cè)免費(fèi)下載(新編第二版pdf電子書)
  10. 0.00 MB  |  15349次下載  |  免費(fèi)
  11. 6數(shù)字電路基礎(chǔ)pdf(下載)
  12. 未知  |  13750次下載  |  免費(fèi)
  13. 7電子制作實(shí)例集錦 下載
  14. 未知  |  8113次下載  |  免費(fèi)
  15. 8《LED驅(qū)動(dòng)電路設(shè)計(jì)》 溫德?tīng)栔?/a>
  16. 0.00 MB  |  6656次下載  |  免費(fèi)

總榜

  1. 1matlab軟件下載入口
  2. 未知  |  935054次下載  |  免費(fèi)
  3. 2protel99se軟件下載(可英文版轉(zhuǎn)中文版)
  4. 78.1 MB  |  537798次下載  |  免費(fèi)
  5. 3MATLAB 7.1 下載 (含軟件介紹)
  6. 未知  |  420027次下載  |  免費(fèi)
  7. 4OrCAD10.5下載OrCAD10.5中文版軟件
  8. 0.00 MB  |  234315次下載  |  免費(fèi)
  9. 5Altium DXP2002下載入口
  10. 未知  |  233046次下載  |  免費(fèi)
  11. 6電路仿真軟件multisim 10.0免費(fèi)下載
  12. 340992  |  191187次下載  |  免費(fèi)
  13. 7十天學(xué)會(huì)AVR單片機(jī)與C語(yǔ)言視頻教程 下載
  14. 158M  |  183279次下載  |  免費(fèi)
  15. 8proe5.0野火版下載(中文版免費(fèi)下載)
  16. 未知  |  138040次下載  |  免費(fèi)