Skip to content

NCTU_First_upload #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions arc_design_contest/2019/NCTU_Voice_Control_Car/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Voice Control Meal Delivery Car
This is a car make for Meal Delivery, which can go through the route that been set by voice control or by direct coding. And include two ultra-sonic distance sensor to detect whether the car has been blocked, at the same time keep updating the information about the car to the cloud, and can be seen by the kitchen or the cook. Most of the proses will be calculated on IOTDK.

* [Introduction](#introduction)
* [Function](#function)
* [System Architecture](#system-architecture)
* [Control Method](#control-method)
* [Hardware and Software Setup](#hardware-and-software-setup)
* [Required Hardware](#required-hardware)
* [Required Software](#required-software)
* [Hardware Connection](#hardware-connection)
* [User Manual](#user-manual)
* [Before Running This Application](#before-running-this-application)
* [Run This Application](#run-this-application)

## Introduction
**Voice Control Meal Delivery**

### Function

- **Set the route that the car can deliver meals to the right table number**
- **Voice control** (To only control the car or set the route step by step with voice.)
- **Cloud management** (The meal provider can know every car's states through online cloud)
- **Front Detection** (There are two distance detecter to stop the car from accidentally crash into something)
- **Controller based**(Through improving the Controller we can make the car move more smoothly and precisely)

![all-sys][0]

### System Architecture

![system_architecture][1]
![system_architecture_2][7]
**Timer interrupt**
![code-interr][8]

### Control Method

![controlleri][2]

## Hardware and Software Setup
### Required Hardware
- 1 [ARC IoT Development Kit(IOTDK)][30]
- 2 Li-ion Battery 18650 3.7v
- 1 Li-ion Battery Box with MD line(for protect board)
- 1 2S 10A 18650 Lithium Battery Protection Board
- 1 XL6009 Boost Buck DC Adjustable Step Up Down Converter
- 1 L298N DC Motor Driver Dual H Bridge
- 1 SPH0645LM4H I2S Microphone
- 2 Motor with Hall Sensor
- 2 HC-SR04 Ultrasonic Distance Rangefinder
- 1 NodeMCU ESP8266 Lua WiFi Internet Development Board
- WiFi Hotspot(SSID:**Prophet**, Password:**1mProphet**, WPA/WPA2 encypted)
- PC to write the code onto the board

This is the car been assambled
![whole_car][10]

![whole_car_2][11]

### Required Software
- embarc_osp
- ARC Gnu IDE
- digilent.adept

### Hardware Connection
Connect the IOTDK through micor USB to write the code.
And the wires connection is down below.
![hardware_connect][12]
![power][13]

## User Manual
### Before Running This Application
You have to download thw embarc_ops and install the IDE and Driver, and download the code from the github,but because the voice recognition model is from **Cyberon** so you have to get licence from it.

And set up the environment by follow the [guide][31].
To use NodeMCU, you have to set up the arduino IDE according to your NodeMCU WiFi board version.

And download the **wifi** folder for NodeMCU WiFi module.

### Run This Application

Under Win10, put **src/voice** folder in the embarc_osp(from the synopsys or the [link][31]) open powershell at the voice folder,

(path: `embarc_osp/voice`):

make BOARD=iotdk TOOLCHAIN=gnu run
![screenshot_powershell][14]

And you can see some recognition result with putty through serial port.

![putty][15]





[0]: ./doc/pic/all.png "all-sys"
[1]: ./doc/pic/code_structure.png "system_architecture"
[2]: ./doc/pic/controller.png "controller"
[3]: ./doc/screenshots/wearable_node.jpg "wearable_node"
[4]: ./doc/screenshots/wifi_connected_info.PNG "wifi_connected_info"
[5]: ./doc/screenshots/lwm2m_started_info.PNG "lwm2m_started_info"
[6]: ./doc/screenshots/lamp_work_info.PNG "lamp_work_info"
[7]: ./doc/pic/code_struction_2.png "system_architecture_2"
[8]: ./doc/pic/code-interr.png "code-interr"
[9]: ./doc/pic/controller.png "controller"
[10]: ./doc/pic/whole_car.png "whole_car"
[11]: ./doc/pic/whole_car_2.png "whole_car_2"
[12]: ./doc/pic/hardware_connect.png "hardware_connect"
[13]: ./doc/pic/power.png "power"
[14]: ./doc/pic/powershell.PNG "screenshot_powershell"
[15]: ./doc/pic/putty.PNG "putty"


[30]: https://embarc.org/embarc_osp/doc/build/html/board/iotdk.html "v"
[31]: https://embarc.org/embarc_osp/doc/build/html/getting_started/getting_started.html
[32]: https://www.invensense.com/products/motion-tracking/6-axis/mpu-6050/ "Acceleration sensor(MPU6050)"
[33]: http://www.electronics-lab.com/max30102/ "Heartrate sensor(MAX30102)"
[34]: https://developer.mbed.org/components/MLX90614-I2C-Infrared-Thermometer/ "Temperature sensor(MLX90614)"
[35]: https://github.com/XiangcaiHuang/ibaby.git "iBaby Smarthome Gateway"
[36]: https://github.com/XiangcaiHuang/ibaby.git "iBaby Freeboard UI"
[37]: http://www.openmobilealliance.org/release/LightweightM2M/V1_0_1-20170704-A/OMA-TS-LightweightM2M-V1_0_1-20170704-A.pdf "LwM2M Protocol"
[38]: http://www.openmobilealliance.org/wp/OMNA/LwM2M/LwM2MRegistry.html#omalabel "LwM2M Object and Resource"
[39]: http://www.freertos.org/a00106.html "FreeRTOS API"
[40]: http://embarc.org/embarc_osp/doc/embARC_Document/html/page_example.html " embARC Example User Guide"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
181 changes: 181 additions & 0 deletions arc_design_contest/2019/NCTU_Voice_Control_Car/src/voice/Spotter_IC.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
#include <stdio.h>
#include <stdlib.h>

#include <limits.h>
#include "CSpotterSDK.h"
#include "conf.h"

#define DISABLE_MALLOC
#if defined DEBUG
#define LOG(args...) {printf(args); putchar('\n');}
#else
#define LOG(args...)
#endif


#ifdef DISABLE_MALLOC
#define k_nMemSize (20 * 256* sizeof(int)) //Memory alloc size for CSpotter. Modify it, if need.
#endif

#define k_nStateSize (19* sizeof(int))
#define k_nMaxTime 300
#define k_nFrameSize 160//256

#define k_nMaxGroupSize 5
#define k_nLevel2TimeOut (5*16000) //interval of level 2 recognize time. After time out, it would back to level 1

typedef struct
{
HANDLE hCSpotter;
int groupId;
int cmdId;
BYTE lpbyState[k_nStateSize] ;
#ifndef DISABLE_MALLOC
BYTE *lpbyMemPool;
#else
#pragma message "Spotter.c: use fixed memory size"
BYTE lpbyMemPool[k_nMemSize];
#endif
int groupList[k_nMaxGroupSize+1];
int level2RemainTime;
}Spotter;

static Spotter gSpotter= {0};
void Spotter_Release(void);
int Spotter_Init2(BYTE *lpbyCYBase, BYTE **lppbyModel, void* lpbyRejModel){
int n;
int nGroups, nCmds;
int err;
if (gSpotter.hCSpotter!= 0){
Spotter_Release();
}

for(nGroups= 0, nCmds= 0; nGroups<= k_nMaxGroupSize; nGroups++){
if(lppbyModel[nGroups]== 0) break;
nCmds+= CSpotter_GetNumWord(lppbyModel[nGroups]);
gSpotter.groupList[nGroups]= nCmds;
}
// LOG("cmd num: %d\n", nCmds);
gSpotter.groupList[nGroups]= INT_MAX;
// Check the memory usage
n = CSpotter_GetMemoryUsage_MultiWithExtRejModel(lpbyCYBase , lppbyModel , nGroups, k_nMaxTime, lpbyRejModel);
#ifndef DISABLE_MALLOC
gSpotter.lpbyMemPool= malloc(n);
if( gSpotter.lpbyMemPool== 0 ) {
#else
if( n > k_nMemSize ) {
#endif
LOG("CSpotter init fail: memory need %d\n", n);
return -2;
}

gSpotter.hCSpotter = CSpotter_Init_MultiWithExtRejModel(lpbyCYBase , lppbyModel , nGroups, k_nMaxTime, (BYTE*)lpbyRejModel, (BYTE*)gSpotter.lpbyMemPool , n , gSpotter.lpbyState , k_nStateSize , &err ) ;
if( err != CSPOTTER_SUCCESS ) {
#ifndef DISABLE_MALLOC
free(gSpotter.lpbyMemPool);
gSpotter.lpbyMemPool= 0;
#endif
LOG("CSpotter init fail:error code is %d\n", err);
return err;
}
gSpotter.level2RemainTime= 0;
return CSPOTTER_SUCCESS;
}

int Spotter_Init(BYTE *lpbyCYBase, BYTE *lppbyModel[]){
return Spotter_Init2(lpbyCYBase, lppbyModel, 0);
}

static void calResult(void){
int cmd= CSpotter_GetResult(gSpotter.hCSpotter);
int i;
for(i= 0; ; i++){
if(cmd< gSpotter.groupList[i]) {
gSpotter.groupId= i;
if(i> 0){
gSpotter.cmdId= cmd- gSpotter.groupList[i- 1];
}else{
gSpotter.cmdId= cmd;
}
return;
}
}
}

LED_MODE led;
int Spotter_AddSample(SHORT *lpsSample, INT nNumSample){
int nRet= CSpotter_AddSample(gSpotter.hCSpotter, lpsSample, nNumSample);
if(nRet== CSPOTTER_SUCCESS){
calResult();
if(gSpotter.groupId== 0){
gSpotter.level2RemainTime= k_nLevel2TimeOut; //goto level 2
led = LED_LIGHT;
//printf("ledd\n",led );
LOG("trigger, jump to level 2");
}else if(gSpotter.level2RemainTime<= 0){
nRet= CSPOTTER_ERR_NeedMoreSample; //false alarm
LOG("ignore cmd");
}else{
gSpotter.level2RemainTime= 0; //detect level 2 cmd, back to level 1
led = LED_DARK_TASK;
set_work_status_EXE_CMD();
LOG("detect cmd");
}
}else if(gSpotter.level2RemainTime> 0){
gSpotter.level2RemainTime-= nNumSample;
if(gSpotter.level2RemainTime<= 0){
printf("timoutttttttttttttt\n" );
led = LED_DARK;
LOG("time out");
}
}

return nRet;
}


int Spotter_GetResultId(void){
return gSpotter.cmdId;
}

int Spotter_GetResultGroupId(void){
return gSpotter.groupId;
}

void Spotter_Reset(void){
CSpotter_Reset(gSpotter.hCSpotter);
}

void Spotter_Release(void){
if(!gSpotter.hCSpotter) return;
CSpotter_Release(gSpotter.hCSpotter);
gSpotter.hCSpotter= 0;
#ifndef DISABLE_MALLOC
free(gSpotter.lpbyMemPool);
gSpotter.lpbyMemPool= 0;
#endif
}

const char* Spotter_GetVersion(void){
return CSpotter_GetVersion();
}

int Spotter_VAD_Enable(int isEnabled){
#if SUPPORT_VAD
return CSpotter_VAD_Enable(gSpotter.hCSpotter , isEnabled);
#else
return -1;
#endif
}

int Spotter_VAD_SetMinEnergyThreshd(int nThreshold){
#if SUPPORT_VAD
return CSpotter_VAD_SetMinEnergyThreshd(gSpotter.hCSpotter , nThreshold);
#else
return -1;
#endif
}

HANDLE Spotter_GetHandle(){
return gSpotter.hCSpotter;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 6.4.5.0.20190823(trial)(synopsys_limited)
--------------------------------------
-mcpu=em4_fpuda -mlittle-endian -mcode-density -mdiv-rem -mswap -mnorm -mmpy-option=6 -mbarrel-shifter -mfpu=fpuda_all
--------------------------------------
target: arc-elf32
gcc_version: '8.2.1 20180814 (ARCompact/ARCv2 ISA elf32 toolchain 2018.09) '
Loading