Compare commits
7 Commits
b04-pcotto
...
b01-d0.2-h
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77dfccba79 | ||
|
|
5e6b280a49 | ||
|
|
ceb5469c17 | ||
|
|
61bc985d5c | ||
|
|
a6547e4184 | ||
|
|
d6e22519d5 | ||
|
|
657cdf2691 |
BIN
README.assets/144262e7fd3707720962e083d5304a7e.mp4
Normal file
BIN
README.assets/144262e7fd3707720962e083d5304a7e.mp4
Normal file
Binary file not shown.
BIN
README.assets/20230208200017.jpg
Normal file
BIN
README.assets/20230208200017.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 86 KiB |
BIN
README.assets/qwe.png
Normal file
BIN
README.assets/qwe.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.9 MiB |
37
README.md
37
README.md
@ -1,15 +1,44 @@
|
||||
# 下位机
|
||||
|
||||
下位机根据传送带脉冲等触发相机,接收上位机给的数据,按其要求控制阀板,用在各种分选机上。
|
||||
糖果分选机的下位机根据传送带脉冲等触发相机,接收上位机给的数据,按其要求控制阀板,用在各种分选机上。本次下位机采用的硬件是[广州致远电子股份有限公司 ](https://www.zlg.cn/)(周立功)的[EPC-9600I-L工控主板](https://www.zlg.cn/ipc/ipc/product/id/77.html)(简称EPC9600),自带各种接口,但是除了网口和DI/DO接口,其他接口统统用不到。阀板接口、触发相机的接口、编码器接口,都是连接自己做的IO扩展板,将IO扩展板插在底板DI/DO接口上,叠起来,因此称为叠板。
|
||||
|
||||

|
||||
|
||||
图中左到右分别为EPC9600,IO扩展板,糖果分选机整机,相机,上位机,编码器。其中,相机的触发线、编码器连接到IO扩展板,相机、上位机、EPC9600连接到以太网交换机。
|
||||
|
||||
IO扩展板提供了
|
||||
|
||||
- 1个12V电源输入
|
||||
- 2个相机触发,1个为冗余
|
||||
- 2个编码器输入,1个为冗余
|
||||
- 4个阀板接口,3个为冗余
|
||||
|
||||
要注意,IO扩展板上的供电接口仅仅用于IO扩展板自身的供电,EPC9600的供电需要另外提供。<br>下面是接线图:
|
||||
|
||||

|
||||
|
||||
## 目录结构
|
||||
|
||||
- binary为编译好的可执行文件
|
||||
- doc为说明文档,包括开发和部署细节、硬件设计的描述等
|
||||
- [deploy.md](./doc/deploy.md)为开发和部署说明,首先看这个文档
|
||||
- [hardware_description.md](./doc/hardware_description.md)为PCB设计说明
|
||||
- script为配置系统、安装环境、安装可执行文件、卸载可执行文件等的脚本
|
||||
- protocol为上位机和下位机通信的协议
|
||||
- hardware下位机主板、接口板、底板等的硬件设计
|
||||
- source为可执行文件的源程序
|
||||
|
||||
## 喷阀原理
|
||||
|
||||
喷嘴由两片CNC加工的金属工件拼合而成,每一片工件上有48个深度为喷嘴宽度的一半的沟槽,两片拼合形成截面为矩形的48个喷嘴,通过软管连接到喷阀的气流出口。打开相应喷阀就会在喷嘴处射出气流。喷嘴以喷出气流向下的方向安装,整体平行于传送带滚筒,在传送带末端上方。如图:
|
||||
|
||||
<img src="README.assets/20230208200017.jpg" alt="20230208200017" style="zoom: 50%;" />
|
||||
|
||||
工作时射出的气流将瑕疵糖果向下吹走,正常糖果被传送带喷出,如下视频
|
||||
|
||||
<video src="README.assets/144262e7fd3707720962e083d5304a7e.mp4"></video>
|
||||
|
||||
|
||||
|
||||
## 版本
|
||||
|
||||
由于经常有不同类型的新要求出现,比如分选糖果、分选烟梗、同为糖果也具有不同的参数,因此不同的下位机型号(注意不是更新,比如同一台机器需要设置新的参数)应建立不同的分支,**主分支无实际意义**
|
||||
@ -27,10 +56,10 @@ b分支编号-p生产环境项目名-t分选对象[-其他特点1[-其他特点2
|
||||
版本号遵循定义如下(不使用中文,小写无空格)
|
||||
|
||||
```shell
|
||||
b分支编号-n编译号-h硬件版本-p协议版本-s脚本版本-r代码版本
|
||||
b分支编号[-d文档版本]-hPCB设计版本[-lFPGA设计版本]-p协议版本[-s脚本版本]-aAPP代码版本[-i驱动版本][-c系统编译配置版本][-e设备树版本]
|
||||
```
|
||||
|
||||
分支编号和分支命名中编号一致
|
||||
中括号在这里表示可省略的项,中括号本身不应出现在实际命名中。分支编号和分支命名中编号一致。各部分版本应在相应目录下创建文件注明,比如`2.1`版本的PCB设计:PCB工程目录中建立`version`文本文件,内容为文本`2.1`。对于涉及整体设计的大改动版本号加`1`,其余改动版本号加`0.1`。每个分支的版本各自独立,新分支的版本从`1.0`起计算
|
||||
|
||||
## 作者
|
||||
|
||||
|
||||
BIN
binary/target
BIN
binary/target
Binary file not shown.
BIN
doc/deploy.assets/20230208183606.jpg
Normal file
BIN
doc/deploy.assets/20230208183606.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 442 KiB |
BIN
doc/deploy.assets/5e6af30fa23d9.jpg
Normal file
BIN
doc/deploy.assets/5e6af30fa23d9.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 419 KiB |
67
doc/deploy.md
Normal file
67
doc/deploy.md
Normal file
@ -0,0 +1,67 @@
|
||||
# 下位机的部署步骤
|
||||
|
||||
按下面标题的顺序进行,不要轻易跳过步骤,除非你知道你在做什么
|
||||
|
||||
## 硬件连接
|
||||
|
||||
### 启动方式选择
|
||||
|
||||
EPC-9600I-L支持从NAND或者SD卡启动,通过 S7拨码开关控制,拨码开关如图全部设置为OFF,表示从NAND启动。
|
||||
|
||||
<img src="deploy.assets/5e6af30fa23d9.jpg" alt="5e6af30fa23d9" style="zoom:33%;" />
|
||||
|
||||
### IO和供电连接
|
||||
|
||||
完成以下步骤后,应如下图所示
|
||||
|
||||
1. 将IO扩展板插入J1牛角座
|
||||
2. 按接线图连接相机触发线、编码器的任一相、阀板
|
||||
3. 按接线图连接IO扩展板的电源
|
||||
4. 按接线图连接EPC9600的电源
|
||||
5. 按接线图连接网线到交换机
|
||||
6. 连接调试用电脑到交换机
|
||||
|
||||
<img src="deploy.assets/20230208183606.jpg" alt="20230208183606" style="zoom: 33%;" />
|
||||
|
||||
|
||||
|
||||
启动交换机、EPC9600、IO扩展板的电源
|
||||
|
||||
## 软件配置
|
||||
|
||||
### 登录和配置
|
||||
|
||||
断开并禁用电脑连接的其他网络和网络适配器(包括无线网),将电脑连接EPC9600的网口设置到192.168.1.0/24网络中
|
||||
|
||||
SSH登录账号`root`,密码`root`<br>出厂默认IP为`192.168.1.136`
|
||||
|
||||
可以使用任何SSH软件进行登录,推荐`Xshell`,连接后执行下面的命令设置新的时间和IP:
|
||||
|
||||
```shell
|
||||
[root@epc-9600 ~]# date 2023.02.08-15:34:00
|
||||
[root@epc-9600 ~]# hwclock -w
|
||||
[root@epc-9600 ~]# eeprom net set ip 192.168.2.9
|
||||
```
|
||||
|
||||
时间不要照抄上面的命令,设置为当前时间即可,IP必须为`192.168.2.9`,执行下面命令重启
|
||||
|
||||
```shell
|
||||
[root@epc-9600 ~]# reboot
|
||||
```
|
||||
|
||||
### 安装下位机软件
|
||||
|
||||
因为设置了新的IP,所以将电脑连接EPC9600的网口设置为`192.168.2.11/24`,重新SSH连接IP为`192.168.2.9`的EPC9600。同时启动SFTP软件,推荐`Xftp`,将[script/S90target](../script/S90target)传输到EPC9600的`/tmp`中,运行下面命令配置下位机软件自启动:
|
||||
|
||||
```shell
|
||||
[root@epc-9600 ~]# wr mv /tmp/S90target /etc/init.d/
|
||||
[root@epc-9600 ~]# wr chmod 755 /etc/init.d/S90target
|
||||
```
|
||||
|
||||
用相同的放将本仓库release中`app.zip`解压出的下位机软件`target`传输到EPC9600的`/tmp`中,运行下面命令安装下位机软件:
|
||||
|
||||
```shell
|
||||
[root@epc-9600 ~]# wr mv /tmp/target /root
|
||||
[root@epc-9600 ~]# wr chmod 755 /root/target
|
||||
[root@epc-9600 ~]# sync
|
||||
```
|
||||
0
doc/hardware_description.md
Normal file
0
doc/hardware_description.md
Normal file
1
doc/version
Normal file
1
doc/version
Normal file
@ -0,0 +1 @@
|
||||
0.2
|
||||
297
hardware/Job1.OutJob
Normal file
297
hardware/Job1.OutJob
Normal file
File diff suppressed because one or more lines are too long
BIN
hardware/asm/PCB1.PCBDwf
Normal file
BIN
hardware/asm/PCB1.PCBDwf
Normal file
Binary file not shown.
1148
hardware/epc9600ioextend.PrjPcb
Normal file
1148
hardware/epc9600ioextend.PrjPcb
Normal file
File diff suppressed because it is too large
Load Diff
1
hardware/epc9600ioextend.PrjPcbStructure
Normal file
1
hardware/epc9600ioextend.PrjPcbStructure
Normal file
@ -0,0 +1 @@
|
||||
Record=TopLevelDocument|FileName=Sheet1.SchDoc|SheetNumber=1
|
||||
BIN
hardware/lib/mw.PcbLib
Normal file
BIN
hardware/lib/mw.PcbLib
Normal file
Binary file not shown.
BIN
hardware/lib/mw.SchLib
Normal file
BIN
hardware/lib/mw.SchLib
Normal file
Binary file not shown.
BIN
hardware/pcb/PCB1.PcbDoc
Normal file
BIN
hardware/pcb/PCB1.PcbDoc
Normal file
Binary file not shown.
BIN
hardware/sch/Sheet1.SchDoc
Normal file
BIN
hardware/sch/Sheet1.SchDoc
Normal file
Binary file not shown.
1
hardware/version
Normal file
1
hardware/version
Normal file
@ -0,0 +1 @@
|
||||
1.1
|
||||
1
protocol/version
Normal file
1
protocol/version
Normal file
@ -0,0 +1 @@
|
||||
1.0
|
||||
2
script/S90target
Normal file
2
script/S90target
Normal file
@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
/root/target &
|
||||
1
script/version
Normal file
1
script/version
Normal file
@ -0,0 +1 @@
|
||||
1.0
|
||||
6
source/.vscode/c_cpp_properties.json
vendored
6
source/.vscode/c_cpp_properties.json
vendored
@ -4,10 +4,10 @@
|
||||
"name": "ARM",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**",
|
||||
"/home/miaow/software/arm-2011.03/lib/gcc/arm-none-linux-gnueabi/4.5.2/include/**"
|
||||
"/home/miaow/software/gcc-arm-2011.03/lib/gcc/arm-none-linux-gnueabi/4.5.2/include/**"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/home/miaow/software/arm-2011.03/bin/arm-none-linux-gnueabi-gcc",
|
||||
"compilerPath": "/home/miaow/software/gcc-arm-2011.03/bin/arm-none-linux-gnueabi-gcc",
|
||||
"cStandard": "gnu99",
|
||||
"cppStandard": "gnu++17",
|
||||
"intelliSenseMode": "linux-gcc-arm",
|
||||
@ -15,7 +15,7 @@
|
||||
"browse": {
|
||||
"path": [
|
||||
"${workspaceFolder}",
|
||||
"/home/miaow/software/arm-2011.03/lib/gcc/arm-none-linux-gnueabi/4.5.2/include"
|
||||
"/home/miaow/software/gcc-arm-2011.03/lib/gcc/arm-none-linux-gnueabi/4.5.2/include"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
4
source/.vscode/settings.json
vendored
4
source/.vscode/settings.json
vendored
@ -16,7 +16,9 @@
|
||||
"queue.h": "c",
|
||||
"stdio.h": "c",
|
||||
"encoder.h": "c",
|
||||
"semaphore.h": "c"
|
||||
"semaphore.h": "c",
|
||||
"socket.h": "c",
|
||||
"host_computer.h": "c"
|
||||
},
|
||||
"makefile.launchConfigurations": [
|
||||
{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#makefile for file_ioctl
|
||||
CROSS_COMPILE ?= /home/miaow/software/arm-2011.03/bin/arm-none-linux-gnueabi-
|
||||
CROSS_COMPILE ?= /home/miaow/software/gcc-arm-2011.03/bin/arm-none-linux-gnueabi-
|
||||
TARGET := target
|
||||
BUILD_DIR := build
|
||||
|
||||
|
||||
@ -1,3 +1,14 @@
|
||||
/**
|
||||
* @file gpio_common.h
|
||||
* @brief Operate the GPIO port of Zhou Ligong linux industrial control board
|
||||
* @details is_file_exist(const char *file_path) determine whether the specified file exists
|
||||
* print_array(int *array, int count) used to print out the value of the queue buffer, easy to debug and use
|
||||
* @mainpage github.com/NanjingForestryUniversity
|
||||
* @author miaow
|
||||
* @email 3703781@qq.com
|
||||
* @version v0.9.0
|
||||
* @date 2021/12/25 merry christmas
|
||||
*/
|
||||
#ifndef __GPIO_COMMON_H
|
||||
#define __GPIO_COMMON_H
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
/**
|
||||
* @file host_computer.c
|
||||
* @brief Commnunicate with host computer. Protocal is described in hostcomputer通信协议.md
|
||||
* @brief Commnunicate with host computer. Protocal is described in 下位机和上位机通信协议.md
|
||||
* @author miaow (3703781@qq.com)
|
||||
* @version 1.0
|
||||
* @date 2022/01/16
|
||||
* @version 1.1
|
||||
* @date 2023/02/08
|
||||
*
|
||||
* @copyright Copyright (c) 2022 miaow
|
||||
*
|
||||
@ -11,6 +11,7 @@
|
||||
* <table>
|
||||
* <tr><th>Date <th>Version <th>Author <th>Description
|
||||
* <tr><td>2022/01/16 <td>1.0 <td>miaow <td>Write this file
|
||||
* <tr><td>2023/02/08 <td>1.1 <td>miaow <td>Add fifo empty detection
|
||||
* </table>
|
||||
*/
|
||||
#include <host_computer.h>
|
||||
@ -84,6 +85,16 @@ static int recvn(int fd, char *buf, int size)
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send string "error"
|
||||
* @param fd The file descriptor that receives error
|
||||
*/
|
||||
static void send_error(int fd)
|
||||
{
|
||||
write(fd, "error", 5);
|
||||
printf("error sent\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief To inspect the status of TCP connection
|
||||
* @param sock_fd The socket
|
||||
@ -105,7 +116,7 @@ static int is_connected(int sock_fd)
|
||||
void *loop_thread_func(void *param)
|
||||
{
|
||||
printf("loop thread in %s start\r\n", __FILE__);
|
||||
int need_exit = 0;
|
||||
int need_exit = 0, error_sent = 0;
|
||||
char pre;
|
||||
uint16_t n_bytes;
|
||||
char type[2];
|
||||
@ -143,39 +154,32 @@ void *loop_thread_func(void *param)
|
||||
|
||||
if (recvn(_global_structure.socket_fd, (char *)&pre, 1) > 1)
|
||||
{
|
||||
// close(_global_structure.socket_fd);
|
||||
printf("pre_len!=1\r\n");
|
||||
continue;
|
||||
}
|
||||
if (pre != 0xAA)
|
||||
{
|
||||
// close(_global_structure.socket_fd);
|
||||
// printf("%X ", (int)pre);
|
||||
fflush(stdout);
|
||||
continue;
|
||||
}
|
||||
if (recvn(_global_structure.socket_fd, (char *)&n_bytes, 2) != 2)
|
||||
{
|
||||
// close(_global_structure.socket_fd);
|
||||
printf("n_bytes_len!=2\r\n");
|
||||
continue;
|
||||
}
|
||||
n_bytes = ntohs(n_bytes);
|
||||
if (n_bytes > 4096 || n_bytes < 2)
|
||||
{
|
||||
// close(_global_structure.socket_fd);
|
||||
printf("n_bytes>4096 or n_bytes<2\r\n");
|
||||
continue;
|
||||
}
|
||||
if (recvn(_global_structure.socket_fd, (char *)type, 2) != 2)
|
||||
{
|
||||
// close(_global_structure.socket_fd);
|
||||
printf("type!=2\r\n");
|
||||
continue;
|
||||
}
|
||||
if (recvn(_global_structure.socket_fd, (char *)data, n_bytes - 2) != n_bytes - 2)
|
||||
{
|
||||
// close(_global_structure.socket_fd);
|
||||
printf("data_len!=n_bytes-2\r\n");
|
||||
continue;
|
||||
}
|
||||
@ -183,19 +187,16 @@ void *loop_thread_func(void *param)
|
||||
data[n_bytes - 2] = 0;
|
||||
if (recvn(_global_structure.socket_fd, (char *)check, 2) != 2)
|
||||
{
|
||||
// close(_global_structure.socket_fd);
|
||||
printf("check_len!=2\r\n");
|
||||
continue;
|
||||
}
|
||||
if (recvn(_global_structure.socket_fd, (char *)&pre, 1) != 1)
|
||||
{
|
||||
// close(_global_structure.socket_fd);
|
||||
printf("end_len!=1\r\n");
|
||||
continue;
|
||||
}
|
||||
if (pre != 0xBB)
|
||||
{
|
||||
// close(_global_structure.socket_fd);
|
||||
printf("end!=0xBB\r\n");
|
||||
continue;
|
||||
}
|
||||
@ -205,9 +206,9 @@ void *loop_thread_func(void *param)
|
||||
if (type[0] == 'd' && type[1] == 'a')
|
||||
{
|
||||
// printf("%dbytes of data put to data queue\r\n", (int)n_bytes - 2);
|
||||
if (n_bytes - 2 != 6 * HOST_COMPUTER_PICTURE_ROW_NUM)
|
||||
if (n_bytes - 2 != HOST_COMPUTER_PICTURE_BYTES)
|
||||
{
|
||||
printf("n_bytes-2!=%d\r\n", 6 * HOST_COMPUTER_PICTURE_ROW_NUM);
|
||||
printf("n_bytes-2!=%d\r\n", HOST_COMPUTER_PICTURE_BYTES);
|
||||
continue;
|
||||
}
|
||||
int data_index = 0;
|
||||
@ -220,17 +221,24 @@ void *loop_thread_func(void *param)
|
||||
for (int i = 0; i < HOST_COMPUTER_PICTURE_ROW_NUM; i++)
|
||||
{
|
||||
tmp_one_line_data = 0ul;
|
||||
for (int j = 0; j < 6; j++)
|
||||
for (int j = 0; j < HOST_COMPUTER_PICTURE_COLUMN_BYTES; j++)
|
||||
{
|
||||
tmp_one_line_data <<= 8;
|
||||
tmp_one_line_data |= data[data_index++];
|
||||
}
|
||||
queue_uint64_put(_global_structure.data_q, tmp_one_line_data);
|
||||
}
|
||||
// printf("queue_num=%d\r\n", _global_structure.data_q->nData);
|
||||
if (_global_structure.data_q->nData == HOST_COMPUTER_PICTURE_ROW_NUM && !error_sent)
|
||||
{
|
||||
error_sent = 1;
|
||||
send_error(_global_structure.socket_fd);
|
||||
}
|
||||
}
|
||||
else if (type[0] == 's' && type[1] == 't')
|
||||
{
|
||||
// printf("Start put to cmd queue, param:%d\r\n", (int)atoll(data));
|
||||
error_sent = 0;
|
||||
queue_uint64_put(_global_structure.cmd_q, (atoll(data) << 32) | HOSTCOMPUTER_CMD_START);
|
||||
}
|
||||
else if (type[0] == 's' && type[1] == 'p')
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
/**
|
||||
* @file host_computer.h
|
||||
* @brief Commnunicate with host computer. Protocal is described in hostcomputer通信协议.md
|
||||
* @brief Commnunicate with host computer. Protocal is described in 下位机和上位机通信协议.md
|
||||
* @author miaow (3703781@qq.com)
|
||||
* @version 1.0
|
||||
* @date 2022/01/16
|
||||
* @version 1.1
|
||||
* @date 2023/02/08
|
||||
*
|
||||
* @copyright Copyright (c) 2022 miaow
|
||||
*
|
||||
@ -11,6 +11,7 @@
|
||||
* <table>
|
||||
* <tr><th>Date <th>Version <th>Author <th>Description
|
||||
* <tr><td>2022/01/16 <td>1.0 <td>miaow <td>Write this file
|
||||
* <tr><td>2023/02/08 <td>1.1 <td>miaow <td>Add 3 macros for picture from host computer
|
||||
* </table>
|
||||
*/
|
||||
#ifndef __HOST_COMPUTER_H
|
||||
@ -23,6 +24,9 @@
|
||||
#define HOST_COMPUTER_IP "192.168.2.10"
|
||||
#define HOST_COMPUTER_PORT 13452
|
||||
#define HOST_COMPUTER_PICTURE_ROW_NUM 500
|
||||
#define HOST_COMPUTER_PICTURE_COLUMN_NUM 48
|
||||
#define HOST_COMPUTER_PICTURE_COLUMN_BYTES (HOST_COMPUTER_PICTURE_COLUMN_NUM / 8)
|
||||
#define HOST_COMPUTER_PICTURE_BYTES (HOST_COMPUTER_PICTURE_COLUMN_BYTES * HOST_COMPUTER_PICTURE_ROW_NUM)
|
||||
|
||||
/**
|
||||
* @brief The commonds, ref hostcomputer通信协议.md
|
||||
|
||||
126
source/main.c
126
source/main.c
@ -1,7 +1,25 @@
|
||||
/**
|
||||
* @file main.c
|
||||
* @brief Excuting commands, resample data, triggle camera, and send data to valve
|
||||
* @author miaow (3703781@qq.com)
|
||||
* @version 1.1
|
||||
* @date 2023/02/08
|
||||
*
|
||||
* @copyright Copyright (c) 2022 miaow
|
||||
*
|
||||
* @par Changelog:
|
||||
* <table>
|
||||
* <tr><th>Date <th>Version <th>Author <th>Description
|
||||
* <tr><td>2022/01/16 <td>1.0 <td>miaow <td>Write this file
|
||||
* <tr><td>2023/02/08 <td>1.1 <td>miaow <td>Add debug option for interval of camera triggle
|
||||
* </table>
|
||||
*/
|
||||
#include <valve.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/time.h>
|
||||
#include <math.h>
|
||||
#include <main.h>
|
||||
#include <queue_uint64.h>
|
||||
#include <camera_trigger.h>
|
||||
#include <encoder.h>
|
||||
@ -12,11 +30,8 @@
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NOT_INITIALIZED = 0,
|
||||
INITIALIZED = 1,
|
||||
RUNNING = 2,
|
||||
SLEEPING = 3,
|
||||
STOPPED = 4
|
||||
SLEEPING = 0,
|
||||
RUNNING = 1,
|
||||
} status_enum_t;
|
||||
|
||||
valvedata_t valvedata = {0};
|
||||
@ -25,11 +40,16 @@ queue_uint64_msg_t cmd_queue = {0};
|
||||
|
||||
static int count_valve = 1, count_camera = 0, count_valve_should_be = 2;
|
||||
static uint64_t count_continues = 0UL, count_valve_continues = 0UL, count_camera_continues = 0UL;
|
||||
static status_enum_t status = NOT_INITIALIZED;
|
||||
static int camera_trigger_pulse_count = 0;
|
||||
static int valve_should_trigger_pulse_count = 0;
|
||||
static int valve_trigger_pulse_count = 0;
|
||||
static int camera_to_valve_pulse_count = 0;
|
||||
static status_enum_t status = SLEEPING;
|
||||
static int camera_trigger_pulse_count = 500;
|
||||
static int valve_should_trigger_pulse_count = 1;
|
||||
static int valve_trigger_pulse_count = 10;
|
||||
static int camera_to_valve_pulse_count = 3015;
|
||||
#if defined(DEBUG_CAMERA_TRIG_PERIOD)
|
||||
static struct timeval tv;
|
||||
static uint64_t camera_period_interval_last_us = 0UL;
|
||||
static uint64_t camera_period_interval_us = 0UL;
|
||||
#endif
|
||||
|
||||
#define ROTATE_UINT64_RIGHT(x, n) ((x) >> (n)) | ((x) << ((64) - (n)))
|
||||
#define ROTATE_UINT64_LEFT(x, n) ((x) << (n)) | ((x) >> ((64) - (n)))
|
||||
@ -50,11 +70,15 @@ int main(int argc, char *argv[])
|
||||
// fflush(stdout);
|
||||
// valve_test3(100.0f);
|
||||
// valve_test2(200.0f, 0);
|
||||
// for (int i = 0; i < 999; i++)
|
||||
// {
|
||||
// valve_test(200.0f);
|
||||
// }
|
||||
// printf("OK\r\n");
|
||||
// valve_deinit();
|
||||
|
||||
hostcomputer_init(&data_queue, &cmd_queue);
|
||||
printf("\r\n>>>>>\r\nstatus==SLEEPING\r\n<<<<<\r\n\r\n");
|
||||
uint64_t cmd;
|
||||
int TRUE = 1;
|
||||
while (TRUE)
|
||||
@ -62,8 +86,8 @@ int main(int argc, char *argv[])
|
||||
if (queue_uint64_get(&cmd_queue, &cmd) == 0)
|
||||
{
|
||||
process_cmd(&cmd);
|
||||
usleep(100000);
|
||||
}
|
||||
usleep(100000);
|
||||
}
|
||||
hostcomputer_deinit();
|
||||
queue_uint64_deinit(&data_queue);
|
||||
@ -79,14 +103,16 @@ void process_cmd(uint64_t *cmd)
|
||||
{
|
||||
if (tmp_cmd == HOSTCOMPUTER_CMD_START)
|
||||
{
|
||||
queue_uint64_clear(&data_queue);
|
||||
valve_should_trigger_pulse_count = camera_trigger_pulse_count / HOST_COMPUTER_PICTURE_ROW_NUM;
|
||||
for (int i = 0; i < camera_to_valve_pulse_count * HOST_COMPUTER_PICTURE_ROW_NUM / camera_trigger_pulse_count; i++)
|
||||
queue_uint64_put(&data_queue, 0);
|
||||
queue_uint64_put(&data_queue, 0L);
|
||||
|
||||
valve_init();
|
||||
cameratrigger_init();
|
||||
encoder_init(on_encoder);
|
||||
printf("\r\n>>>>>\r\nstatus==RUNNING\r\ncamera_trigger_pulse_count=%d\r\nvalve_trigger_pulse_count=%d\r\ncamera_to_valve_pulse_count=%d\r\n<<<<<\r\n\r\n", camera_trigger_pulse_count, valve_trigger_pulse_count, camera_to_valve_pulse_count);
|
||||
status = RUNNING;
|
||||
printf("\r\n>>>>>\r\nstatus==RUNNING\r\n<<<<<\r\n\r\n");
|
||||
}
|
||||
else if (tmp_cmd == HOSTCOMPUTER_CMD_TEST)
|
||||
{
|
||||
@ -94,10 +120,7 @@ void process_cmd(uint64_t *cmd)
|
||||
valve_test(500.0f);
|
||||
valve_deinit();
|
||||
}
|
||||
}
|
||||
else if (status == NOT_INITIALIZED)
|
||||
{
|
||||
if (tmp_cmd == HOSTCOMPUTER_CMD_SETCAMERATRIGPULSECOUNT)
|
||||
else if (tmp_cmd == HOSTCOMPUTER_CMD_SETCAMERATRIGPULSECOUNT)
|
||||
{
|
||||
camera_trigger_pulse_count = tmp_data;
|
||||
}
|
||||
@ -109,38 +132,6 @@ void process_cmd(uint64_t *cmd)
|
||||
{
|
||||
camera_to_valve_pulse_count = tmp_data;
|
||||
}
|
||||
else if (tmp_cmd == HOSTCOMPUTER_CMD_TEST)
|
||||
{
|
||||
valve_init();
|
||||
valve_test(500.0f);
|
||||
valve_deinit();
|
||||
}
|
||||
if (camera_trigger_pulse_count != 0 && valve_trigger_pulse_count != 0 && camera_to_valve_pulse_count != 0)
|
||||
{
|
||||
status = INITIALIZED;
|
||||
printf("\r\n>>>>>\r\nstatus==INITIALIZED\r\ncamera_trigger_pulse_count=%d\r\nvalve_trigger_pulse_count=%d\r\ncamera_to_valve_pulse_count=%d\r\n<<<<<\r\n\r\n", camera_trigger_pulse_count, valve_trigger_pulse_count, camera_to_valve_pulse_count);
|
||||
}
|
||||
}
|
||||
else if (status == INITIALIZED)
|
||||
{
|
||||
if (tmp_cmd == HOSTCOMPUTER_CMD_START)
|
||||
{
|
||||
valve_should_trigger_pulse_count = camera_trigger_pulse_count / HOST_COMPUTER_PICTURE_ROW_NUM;
|
||||
printf("valve_should_trigger_pulse_count=%d", valve_should_trigger_pulse_count);
|
||||
for (int i = 0; i < camera_to_valve_pulse_count * HOST_COMPUTER_PICTURE_ROW_NUM / camera_trigger_pulse_count; i++)
|
||||
queue_uint64_put(&data_queue, 0);
|
||||
valve_init();
|
||||
cameratrigger_init();
|
||||
encoder_init(on_encoder);
|
||||
status = RUNNING;
|
||||
printf("\r\n>>>>>\r\nstatus==RUNNING\r\n<<<<<\r\n\r\n");
|
||||
}
|
||||
else if (tmp_cmd == HOSTCOMPUTER_CMD_TEST)
|
||||
{
|
||||
valve_init();
|
||||
valve_test(500.0f);
|
||||
valve_deinit();
|
||||
}
|
||||
}
|
||||
else if (status == RUNNING)
|
||||
{
|
||||
@ -150,8 +141,21 @@ void process_cmd(uint64_t *cmd)
|
||||
cameratrigger_deinit();
|
||||
valve_deinit();
|
||||
queue_uint64_clear(&data_queue);
|
||||
status = SLEEPING;
|
||||
#if defined(DEBUG_CAMERA_TRIG_PERIOD)
|
||||
printf("\r\n>>>>>\r\nstatus==SLEEPING\r\ncamera_period_us=%.2f\r\n<<<<<\r\n\r\n", (float)camera_period_interval_us / (float)(count_camera_continues - 1));
|
||||
camera_period_interval_us = 0UL;
|
||||
camera_period_interval_last_us = 0UL;
|
||||
#else
|
||||
printf("\r\n>>>>>\r\nstatus==SLEEPING\r\n<<<<<\r\n\r\n");
|
||||
#endif
|
||||
count_continues = 0UL;
|
||||
count_valve_continues = 0UL;
|
||||
count_camera_continues = 0UL;
|
||||
count_camera = 0;
|
||||
count_valve = 1;
|
||||
count_valve_should_be = 2;
|
||||
|
||||
status = SLEEPING;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -159,7 +163,8 @@ void process_cmd(uint64_t *cmd)
|
||||
void valve_test(float ms_for_each_channel)
|
||||
{
|
||||
uint64_t valve_data = 1ul;
|
||||
for (int i = 0; i < 48; i++)
|
||||
|
||||
for (int i = 0; i < HOST_COMPUTER_PICTURE_COLUMN_NUM; i++)
|
||||
{
|
||||
usleep((useconds_t)(ms_for_each_channel * 500.0f));
|
||||
valvedata.valvedata_1 = valve_data << i;
|
||||
@ -212,33 +217,34 @@ void on_encoder()
|
||||
{
|
||||
count_continues++;
|
||||
|
||||
// send resampled data to valve, the resample cycle is valve_trigger_pulse_count
|
||||
if (++count_valve == valve_trigger_pulse_count + 1)
|
||||
{
|
||||
count_valve = 1;
|
||||
count_valve_continues++;
|
||||
valve_sendmsg(&valvedata);
|
||||
|
||||
// printf("data:%llx send to valve, queue length is %d\r\n", valvedata.valvedata_1, data_queue.nData);
|
||||
// printf("%016llx ", valvedata.valvedata_1);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
// load valve data to valvedata structure
|
||||
if (++count_valve_should_be == valve_should_trigger_pulse_count + 2)
|
||||
{
|
||||
count_valve_should_be = 2;
|
||||
valvedata.valvedata_1 = 0;
|
||||
queue_uint64_get(&data_queue, &(valvedata.valvedata_1));
|
||||
// if (data_queue.nData == 0)
|
||||
// {
|
||||
// printf("sb\r\n");
|
||||
// }
|
||||
}
|
||||
|
||||
// triggle camera in a cycle of camera_trigger_pulse_count
|
||||
if (++count_camera == camera_trigger_pulse_count)
|
||||
{
|
||||
// printf("camera triggled\r\n");
|
||||
count_camera = 0;
|
||||
count_camera_continues++;
|
||||
#if defined(DEBUG_CAMERA_TRIG_PERIOD)
|
||||
gettimeofday(&tv, NULL);
|
||||
if (camera_period_interval_last_us != 0UL)
|
||||
camera_period_interval_us += ((uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec) - camera_period_interval_last_us;
|
||||
camera_period_interval_last_us = ((uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec);
|
||||
#endif
|
||||
|
||||
cameratrigger_trig();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,23 @@
|
||||
/**
|
||||
* @file main.h
|
||||
* @brief Excuting commands, resample data, triggle camera, and send data to valve
|
||||
* @author miaow (3703781@qq.com)
|
||||
* @version 1.1
|
||||
* @date 2023/02/08
|
||||
*
|
||||
* @copyright Copyright (c) 2022 miaow
|
||||
*
|
||||
* @par Changelog:
|
||||
* <table>
|
||||
* <tr><th>Date <th>Version <th>Author <th>Description
|
||||
* <tr><td>2022/01/16 <td>1.0 <td>miaow <td>Write this file
|
||||
* <tr><td>2023/02/08 <td>1.1 <td>miaow <td>Add debug option for interval of camera triggle
|
||||
* </table>
|
||||
*/
|
||||
#ifndef __MAIN_H
|
||||
#define __MAIN_H
|
||||
|
||||
// #define DEBUG_CAMERA_TRIG_PERIOD // uncomment this to print the interval of camera triggle in the unit of usecond
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,3 +1,13 @@
|
||||
/**
|
||||
* @file valve.h
|
||||
* @brief Operate the valveboard with Linux application
|
||||
* @details Call valve_init() paired with valve_deinit() as their names imply, valve_send() can be executed several times to operate up to 6 valveboards between valve_init() and valve_deinit()
|
||||
* @mainpage github.com/NanjingForestryUniversity
|
||||
* @author miaow
|
||||
* @email 3703781@qq.com
|
||||
* @version v0.9.0
|
||||
* @date 2021/12/25 merry christmas
|
||||
*/
|
||||
#ifndef __VALVE_INIT_H
|
||||
#define __VALVE_INIT_H
|
||||
#include <gpio_common.h>
|
||||
@ -24,7 +34,6 @@ typedef struct
|
||||
uint64_t valvedata_6;
|
||||
} valvedata_t;
|
||||
|
||||
|
||||
#define SCLK_FREQUENCE_KHZ 10000
|
||||
|
||||
int valve_init(void);
|
||||
|
||||
1
source/version
Normal file
1
source/version
Normal file
@ -0,0 +1 @@
|
||||
1.1
|
||||
Loading…
Reference in New Issue
Block a user