示例#1
0
# 長さの単位はcm
isLoop = True

centerLine = 30
thresWidth = 15
facingAngleThres = 15
betweenSensors = 20

timeStamp = []
timeStamp.append(time.time())

print("carmachi")
# steering setting
car = NvidiaRacecar()
car.steering_gain = 1.0
car.steering_offset = 0.0

rightMax = 1.0
leftMax = -1.0

steerParam = 1.0  # steerParam * facingAngle で facingAngle[rad]曲がる

# throttle setting
car.throttle_gain = 0.5

speedHigh = 10
speedLow = 0.5

# *Distance are the acquired distance to the wall from each sensor
rightFrontDistance = []
rightRearDistance = []
示例#2
0
    model_trt = TRTModule()
    model_trt.load_state_dict(torch.load(MODEL_PATH_TRT))
else:
    model = AutopilotModel(pretrained=False)
    model.load_from_path(MODEL_PATH)
    model.eval()

    x = torch.ones((1, FRAME_CHANNELS, FRAME_SIZE, FRAME_SIZE)).cuda()
    model_trt = torch2trt(model, [x], fp16_mode=True)
    torch.save(model_trt.state_dict(), MODEL_PATH_TRT)

try:
    # Car
    car = NvidiaRacecar()
    car.throttle_gain = THROTTLE_GAIN
    car.steering_offset = STEERING_OFFSET

    # Camera
    camera = CSICamera(width=CAMERA_WIDTH, height=CAMERA_HEIGHT)

    # Control Loop
    while True:
        if SHOW_LOGS:
            start_time = time.time()

        camera_frame = camera.read()
        cropped_frame = center_crop_square(camera_frame)
        resized_frame = cv2.resize(cropped_frame, (FRAME_SIZE, FRAME_SIZE))
        preprocessed_frame = preprocess_image(resized_frame)
        output = model_trt(preprocessed_frame).detach().clamp(
            -1.0, 1.0).cpu().numpy().flatten()
#!/usr/bin/env python3

import rospy
from jetracer.nvidia_racecar import NvidiaRacecar
from std_msgs.msg import Float32

#Initialize car variable and tune settings
car = NvidiaRacecar()
car.steering_gain = 0.65
car.steering_offset = -0.16
car.throttle_gain = 1
car.steering = 0.0
car.throttle = 0.0

#Throttle
def callback_throttle(throt):
    car.throttle = throt.data
    rospy.loginfo("Throttle: %s", str(throt.data))

#Steering
def callback_steering(steer):
    car.steering = steer.data
    rospy.loginfo("Steering: %s", str(steer.data))

#Setup node and topics subscription
def racecar():
    rospy.init_node('racecar', anonymous=True)
    rospy.Subscriber("throttle", Float32, callback_throttle)
    rospy.Subscriber("steering", Float32, callback_steering)

    rospy.spin()