Skip to content
This repository was archived by the owner on Sep 25, 2023. It is now read-only.

Commit 502a282

Browse files
authored
Merge pull request #9 from incomingflyingbrick/main
first commit
2 parents 78c09d3 + b4f7a00 commit 502a282

File tree

21 files changed

+729
-0
lines changed

21 files changed

+729
-0
lines changed
6 KB
Binary file not shown.

ROS智能物流 - 姜亚洲/1.jpg

220 KB
Loading

ROS智能物流 - 姜亚洲/2.jpg

238 KB
Loading

ROS智能物流 - 姜亚洲/3.jpg

185 KB
Loading
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## ROS 智能物流小车
2+
3+
本车可以用在物流行业,比如在无人监管的情形下自动运输
4+
它可以帮助人类完成运输任务,减少出错概率,使运输更安全
5+
我使用了google的tensorflow作为自动驾驶的模型训练工具
6+
7+
![](1.jpg)
8+
9+
![](2.jpg)
10+
11+
![](3.jpg)
12+
13+
14+
## 团队
15+
16+
姜亚洲 微信:spacedude888
17+
18+
## 谷歌技术
19+
20+
我使用了tensorflow来自动驾驶模型,用车载摄像头读取照片,然后输入到一个CNN网络里面,用油门和转向的值来做label
21+
22+
## 编译
23+
24+
可以使用python3编译代码,请装好open CV,tensorflow,cuda-10.2
25+
26+
训练代码请参考training/training.py
27+
28+
29+
Data collection 代码请看ai_racer/engine.py
30+
31+
32+
整体框架是基于ROS2开发,如果对ROS2比较熟悉可以尝试导入整个package

ROS智能物流 - 姜亚洲/ai_racer/__init__.py

Whitespace-only changes.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import rclpy
2+
from rclpy.node import Node
3+
import keyboard
4+
from std_msgs.msg import String
5+
6+
7+
class MinimalPublisher(Node):
8+
9+
def __init__(self):
10+
super().__init__('minimal_publisher')
11+
self.publisher_ = self.create_publisher(String, 'topic', 10)
12+
timer_period = 0.2 # seconds
13+
self.timer = self.create_timer(timer_period, self.timer_callback)
14+
self.i = 0
15+
16+
def timer_callback(self):
17+
msg = String()
18+
19+
if keyboard.is_pressed('w'):
20+
self.get_logger().info('w')
21+
msg.data = 'w'
22+
self.publisher_.publish(msg)
23+
24+
elif keyboard.is_pressed('s'):
25+
self.get_logger().info('s')
26+
msg.data = 's'
27+
self.publisher_.publish(msg)
28+
29+
elif keyboard.is_pressed('space'):
30+
self.get_logger().info('brake')
31+
msg.data = ' '
32+
self.publisher_.publish(msg)
33+
else:
34+
pass
35+
36+
37+
38+
39+
if keyboard.is_pressed('a'):
40+
self.get_logger().info('a')
41+
msg.data = 'a'
42+
self.publisher_.publish(msg)
43+
44+
elif keyboard.is_pressed('d'):
45+
self.get_logger().info('d')
46+
msg.data = 'd'
47+
self.publisher_.publish(msg)
48+
else:
49+
self.get_logger().info('going straight')
50+
msg.data = 'go_straight'
51+
self.publisher_.publish(msg)
52+
53+
if keyboard.is_pressed('k'):
54+
self.get_logger().info('k')
55+
msg.data = 'k'
56+
self.publisher_.publish(msg)
57+
58+
59+
60+
61+
def main(args=None):
62+
rclpy.init(args=args)
63+
64+
minimal_publisher = MinimalPublisher()
65+
66+
rclpy.spin(minimal_publisher)
67+
68+
# Destroy the node explicitly
69+
# (optional - otherwise it will be done automatically
70+
# when the garbage collector destroys the node object)
71+
minimal_publisher.destroy_node()
72+
rclpy.shutdown()
73+
74+
75+
if __name__ == '__main__':
76+
main()
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
2+
from multiprocessing.spawn import prepare
3+
import rclpy
4+
from rclpy.node import Node
5+
from adafruit_servokit import ServoKit
6+
from std_msgs.msg import String
7+
from time import *
8+
from sensor_msgs.msg import Joy
9+
import subprocess
10+
from jetcam.csi_camera import CSICamera
11+
import traitlets
12+
import uuid
13+
14+
from PIL import Image
15+
16+
17+
kit = ServoKit(channels=16)
18+
kit.servo[0].angle = 72
19+
20+
21+
22+
class MinimalSubscriber(Node):
23+
24+
def __init__(self):
25+
super().__init__('minimal_subscriber')
26+
self.isCollecting = True
27+
self.prepareDataCollection()
28+
self.camera = CSICamera(width=328, height=246,capture_fps=60)
29+
self.camera.running=True
30+
self.camera.observe(self.cameraCallback,names='value')
31+
self.turn_value = 0.0
32+
self.throttle_value = 0.0
33+
34+
self.subscription = self.create_subscription(
35+
Joy,
36+
'joy',
37+
self.joy_CallBack,
38+
10)
39+
40+
self.subscription
41+
42+
def cameraCallback(self,change):
43+
#self.get_logger().info(str(change['new']))
44+
if self.turn_value!=0.0 or self.throttle_value!=0.0:
45+
self.saveData(self.turn_value,self.throttle_value,change['new'])
46+
47+
def saveData(self,steering,throttle,image_data):
48+
if self.isCollecting:
49+
file_path = 'snapshots/' + str(uuid.uuid1()) +'_'+str(round(steering,5))+'_'+str(round(throttle,5))+ '_.png'
50+
im = Image.fromarray(image_data)
51+
im.save(file_path)
52+
self.get_logger().info('saved data:'+file_path)
53+
54+
def joy_CallBack(self,msg):
55+
self.get_logger().info('Button:'+str(msg.buttons))
56+
self.get_logger().info('Axes:'+str(msg.axes))
57+
self.turn_value = msg.axes[2]
58+
self.throttle_value = msg.axes[1]
59+
60+
if msg.buttons[0]==1:
61+
self.prepareEsc()
62+
#turn
63+
turn = msg.axes[2]*-1.0
64+
y=turn/(1.0/40.0)
65+
y=72+y
66+
kit.servo[0].angle = int(y)
67+
#throttle
68+
the = msg.axes[1]
69+
t= the/(1.0/7.0)
70+
if the==0.0 or the==-0.0:
71+
kit.servo[1].angle = 90
72+
else:
73+
if the > 0:
74+
kit.servo[1].angle = 90+t
75+
else:
76+
kit.servo[1].angle = 90+t-8
77+
78+
79+
def prepareEsc(self):
80+
self.get_logger().info("电调自检验开始")
81+
for i in range(50):
82+
kit.servo[1].angle = 90
83+
sleep(0.1)
84+
self.get_logger().info("电调自检验完成")
85+
86+
def prepareDataCollection(self):
87+
subprocess.call(['rm', '-r','-f', 'snapshots'])
88+
subprocess.call(['mkdir', '-p', 'snapshots'])
89+
90+
91+
92+
def main(args=None):
93+
rclpy.init(args=args)
94+
95+
minimal_subscriber = MinimalSubscriber()
96+
97+
rclpy.spin(minimal_subscriber)
98+
99+
# Destroy the node explicitly
100+
# (optional - otherwise it will be done automatically
101+
# when the garbage collector destroys the node object)
102+
minimal_subscriber.destroy_node()
103+
rclpy.shutdown()
104+
105+
106+
107+
108+
if __name__ == '__main__':
109+
main()
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "35820d08",
7+
"metadata": {},
8+
"outputs": [
9+
{
10+
"data": {
11+
"application/vnd.jupyter.widget-view+json": {
12+
"model_id": "2bae255686c74e8592cdb5d13afad554",
13+
"version_major": 2,
14+
"version_minor": 0
15+
},
16+
"text/plain": [
17+
"Image(value=b'', format='jpeg')"
18+
]
19+
},
20+
"metadata": {},
21+
"output_type": "display_data"
22+
},
23+
{
24+
"data": {
25+
"application/vnd.jupyter.widget-view+json": {
26+
"model_id": "32f3a43644eb4c419553fd6eae8c1f5b",
27+
"version_major": 2,
28+
"version_minor": 0
29+
},
30+
"text/plain": [
31+
"Controller()"
32+
]
33+
},
34+
"metadata": {},
35+
"output_type": "display_data"
36+
}
37+
],
38+
"source": [
39+
"import ipywidgets.widgets as widgets\n",
40+
"from time import *\n",
41+
"from adafruit_servokit import ServoKit\n",
42+
"import traitlets\n",
43+
"from jetcam.csi_camera import CSICamera\n",
44+
"import ipywidgets\n",
45+
"from IPython.display import display\n",
46+
"from jetcam.utils import bgr8_to_jpeg\n",
47+
"import uuid\n",
48+
"import subprocess\n",
49+
"from jetcam.csi_camera import CSICamera\n",
50+
"\n",
51+
"################################ clean folder ################################\n",
52+
"subprocess.call(['rm', '-r','-f', 'snapshots'])\n",
53+
"subprocess.call(['mkdir', '-p', 'snapshots'])\n",
54+
"################################ clean folder done ################################\n",
55+
"\n",
56+
"\n",
57+
"################################ setup camera ################################\n",
58+
"image_widget = ipywidgets.Image(format='jpeg')\n",
59+
"\n",
60+
"display(image_widget)\n",
61+
"\n",
62+
"\n",
63+
"def saveData(steering,throttle):\n",
64+
" file_path = 'snapshots/' + str(uuid.uuid1()) +'_'+str(round(throttle,2))+'_'+str(round(steering,2))+ '_.jpg'\n",
65+
" \n",
66+
" # write snapshot to file (we use image value instead of camera because it's already in JPEG format)\n",
67+
" with open(file_path, 'wb') as f:\n",
68+
" f.write(image_widget.value)\n",
69+
"\n",
70+
"\n",
71+
"def cameraCallback(change):\n",
72+
" image_widget.value = bgr8_to_jpeg(change['new'])\n",
73+
" if controller.axes[1].value!=0.0 or controller.axes[2].value!=0.0:\n",
74+
" saveData(controller.axes[2].value,controller.axes[1].value)\n",
75+
" \n",
76+
"\n",
77+
"camera = CSICamera(width=328, height=246,capture_fps=60)\n",
78+
"camera.running=True\n",
79+
"################################ setup camera done ################################\n",
80+
"\n",
81+
"\n",
82+
"################################ setup controller and servo ################################\n",
83+
"kit = ServoKit(channels=16)\n",
84+
"kit.servo[0].angle = 72\n",
85+
"controller = widgets.Controller(index=0) # replace with index of your controller\n",
86+
"display(controller)\n",
87+
"################################ setup controller and servo done ################################\n",
88+
"\n"
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": 2,
94+
"id": "2194934c",
95+
"metadata": {},
96+
"outputs": [],
97+
"source": [
98+
"camera.observe(cameraCallback,names='value')\n",
99+
"\n",
100+
"def prepareEsc(change):\n",
101+
" print(\"电调自检验开始\")\n",
102+
" if change['new']:\n",
103+
" print('press ')\n",
104+
" for i in range(50):\n",
105+
" kit.servo[1].angle = 90\n",
106+
" sleep(0.1)\n",
107+
" print(\"电调自检验完成\")\n",
108+
"\n",
109+
"\n",
110+
"def throttleControl(change):\n",
111+
" print('throttle changing')\n",
112+
" y=change['new']/(1.0/10.0)\n",
113+
" y=y*-1\n",
114+
" if y == -0.0:\n",
115+
" kit.servo[1].angle = 90\n",
116+
" else:\n",
117+
" kit.servo[1].angle = int(90+y)\n",
118+
" \n",
119+
"def turnControl(change):\n",
120+
" print('stering changing')\n",
121+
" y=change['new']/(1.0/25.0)\n",
122+
" y=72+y\n",
123+
" kit.servo[0].angle = int(y)\n",
124+
" \n",
125+
"def startLog(change):\n",
126+
" pass\n",
127+
"\n",
128+
"def stopLog(change):\n",
129+
" pass\n",
130+
" \n",
131+
"controller.buttons[0].observe(prepareEsc, names='value')\n",
132+
"controller.axes[1].observe(throttleControl,names='value')\n",
133+
"controller.axes[2].observe(turnControl,names='value')"
134+
]
135+
}
136+
],
137+
"metadata": {
138+
"kernelspec": {
139+
"display_name": "Python 3",
140+
"language": "python",
141+
"name": "python3"
142+
},
143+
"language_info": {
144+
"codemirror_mode": {
145+
"name": "ipython",
146+
"version": 3
147+
},
148+
"file_extension": ".py",
149+
"mimetype": "text/x-python",
150+
"name": "python",
151+
"nbconvert_exporter": "python",
152+
"pygments_lexer": "ipython3",
153+
"version": "3.6.9"
154+
}
155+
},
156+
"nbformat": 4,
157+
"nbformat_minor": 5
158+
}

0 commit comments

Comments
 (0)