-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.py
69 lines (60 loc) · 2.36 KB
/
env.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import rospy
import math
import random
import numpy as np
from collections import deque
from std_msgs.msg import Float32MultiArray, Float32, Bool, String
from geometry_msgs.msg import Transform
class VrepEnvironment():
def __init__(self, speed, turn, rate):
#self.scan_sub = rospy.Subscriber('scanData', Float32MultiArray, self.scan_callback)
self.left_pub = rospy.Publisher('leftMotorSpeed', Float32, queue_size=1, latch=True)
self.right_pub = rospy.Publisher('rightMotorSpeed', Float32, queue_size=1, latch=True)
self.fifo = []
rospy.init_node('pioneer_controller')
self.v_forward = speed
self.v_turn = turn
self.rate = rospy.Rate(rate) # frequence of motor speed publisher
def step(self, action):
if action==0:
self.left_pub.publish(self.v_forward-self.v_turn)
self.right_pub.publish(self.v_forward+self.v_turn)
self.rate.sleep()
# self.left_pub.publish(0)
# self.right_pub.publish(0)
#self.rate.sleep()
elif action==1:
self.left_pub.publish(self.v_forward)
self.right_pub.publish(self.v_forward)
self.rate.sleep()
# self.left_pub.publish(0)
# self.right_pub.publish(0)
#self.rate.sleep()
elif action==2:
self.left_pub.publish(self.v_forward+self.v_turn)
self.right_pub.publish(self.v_forward-self.v_turn)
self.rate.sleep()
# self.left_pub.publish(0)
# self.right_pub.publish(0)
#self.rate.sleep()
elif action==3:
self.left_pub.publish(-self.v_forward)
self.right_pub.publish(-self.v_forward)
self.rate.sleep()
self.left_pub.publish(0)
self.right_pub.publish(0)
#self.rate.sleep()
elif action==4:
self.left_pub.publish(0)
self.right_pub.publish(0)
self.rate.sleep()
elif action==5:
print("do nothing")
transform = rospy.wait_for_message('transformData', Transform)
scan = rospy.wait_for_message('scanData',Float32MultiArray).data
return transform, scan
# def scan_callback(self, msg):
# # FIFO queue storing DVS data during one step
# self.fifo.append(msg.data)
# self.fifo.popleft()
# return