Ejemplo n.º 1
0
# connection
id = usimpy.UsimCreateApiConnection("127.0.0.1", 17771, 5000, 10000)

# start simulation
ret = usimpy.UsimStartSim(id, 10000)
print (ret)

## control
control = usimpy.UsimSpeedAdaptMode()
control.expected_speed = 0.8 # m/s
control.steering_angle = 0.0 # angle
control.handbrake_on = False
## action
action = usimpy.UsimVehicleState()
## collision
collision = usimpy.UsimCollision()
## image
image = usimpy.UsimCameraResponse()

count = 0
time1 = 0
time2 = 0
root_dir = './dataset/'
img_dir = root_dir + 'imgs/'
mkdir(img_dir)

while(1):
    # control vehicle via speed & steer
    ret = usimpy.UsimSetVehicleControlsBySA(id, control)
    # get vehicle post & action
    ret = usimpy.UsimGetVehicleState(id, action)
Ejemplo n.º 2
0
    def __init__(self):
        ## Init node
        rospy.init_node("uisee_driver")
        # Shutdown function
        rospy.on_shutdown(self.shutdown)

        ## Get Parameters
        # joy axes and buttons index
        self.left_joy_lr = rospy.get_param("~left_joy_lr", 0)
        self.A = rospy.get_param("A", 2)
        self.B = rospy.get_param("B", 1)
        self.X = rospy.get_param("X", 3)
        self.Y = rospy.get_param("Y", 0)
        self.LT = rospy.get_param("LT", 6)
        self.RT = rospy.get_param("RT", 7)
        #self.LB = rospy.get_param("LB", 4)
        self.RB = rospy.get_param("RB", 5)

        # the amount of change of throttle and brake
        self.throttle_delta = rospy.get_param("~throttle_increment", 1.0)
        self.brake_delta = rospy.get_param("~brake_decrement", 1.0)

        # gear interval
        self.v1_min = rospy.get_param("~gear_v1_min", -10.0)
        self.v1_max = rospy.get_param("~gear_v1_max", 25.0)
        self.w1_scale = rospy.get_param("~gear_w1", 10)

        self.v2_min = rospy.get_param("~gear_v2_min", 30.0)
        self.v2_max = rospy.get_param("~gear_v2_max", 60.0)
        self.w2_scale = rospy.get_param("~gear_w2", 5)

        # for local computer, use 127.0.0.1
        target_ip = rospy.get_param("~target_ip", '192.168.1.109')

        # img
        self.data_path = rospy.get_param("~data_path", './dataset/img/')
        self.count = rospy.get_param("~img_count", 0)

        ## Init Variables
        self.steer = 0.0
        self.last_speed = 0.0

        self.throttle_pressed = False
        self.brake_pressed = False

        self.gear_v1_pressed = False
        self.gear_v2_pressed = False
        self.gear_w1_pressed = False
        self.gear_w2_pressed = False

        self.data_flag = False

        ## Uisee Simulator
        #connection
        self.id = usimpy.UsimCreateApiConnection(target_ip, 17771, 5000, 10000)
        ret = usimpy.UsimStartSim(self.id, 10000)
        print(ret)

        #control
        self.control = usimpy.UsimSpeedAdaptMode()
        #states
        self.states = usimpy.UsimVehicleState()
        #collision
        self.collision = usimpy.UsimCollision()
        #image
        self.image = usimpy.UsimCameraResponse()

        # Joy subscriber (global topic. Make sure the joy node has been run)
        self.joy_sub = rospy.Subscriber("joy",
                                        Joy,
                                        self.joy_callback,
                                        queue_size=10)

        # start a timer to publish control msg in 10hz
        self.timer_pub = rospy.Timer(rospy.Duration(0.1), self.cmd_publish)