def __init__(self, car="kari", mqtt_broker="mqtt.eclipse.org"):

        self.camera_sub = MQTTValueSub("donkey/%s/camera" % car, broker=mqtt_broker)
        self.state_sub = MQTTValueSub("donkey/%s/state" % car, broker=mqtt_broker)

        self.controller_pub = MQTTValuePub("donkey/%s/controls" % car, broker=mqtt_broker)
        self.jpgToImg = JpgToImgArr()

        self.img = np.zeros((40, 40))
        self.state = None
        self.speed = 0
Esempio n. 2
0
    def __init__(self, alg_type, sim, car_name=args.car_name):
        self.args = define_config()
        self.agent = Dreamer(self.args)
        self.sim = sim

        self.image = np.zeros((120, 160, 3))
        self.observation = torch.zeros(
            (1, 3, 64, 64))  # init observation, with batch dim
        self.belief = torch.zeros(1,
                                  self.args.belief_size,
                                  device=self.args.device)
        self.posterior_state = torch.zeros(1,
                                           self.args.state_size,
                                           device=self.args.device)
        self.action = torch.zeros(1,
                                  self.args.action_size,
                                  device=self.args.device)
        # self.act_history = torch.zeros(1, self.args.action_size*3, device=self.args.device)

        self.speed = 0

        self.step = 0
        self.episode = 0
        self.episode_reward = 0
        self.replay_buffer = []

        self.target_speed = 0
        self.steering = 0

        self.training = False
        self.step_start = 0

        self.buffers_sent = False

        self.replay_buffer_pub = MQTTValuePub(car_name + "buffer",
                                              broker="mqtt.eclipse.org")
        self.replay_buffer_sub = MQTTValueSub(car_name + "buffer",
                                              broker="mqtt.eclipse.org",
                                              def_value=(0, True))

        self.replay_buffer_received_pub = MQTTValuePub(
            car_name + "buffer_received", broker="mqtt.eclipse.org")
        self.replay_buffer_received_sub = MQTTValueSub(
            car_name + "buffer_received",
            broker="mqtt.eclipse.org",
            def_value=0)

        self.param_pub = MQTTValuePub(car_name + "param",
                                      broker="mqtt.eclipse.org")
        self.param_sub = MQTTValueSub(car_name + "param",
                                      broker="mqtt.eclipse.org")
Esempio n. 3
0
 def __init__(self, donkey_name, mqtt_broker, sensor_size=(120, 160, 3)):
     self.camera_sub = MQTTValueSub("donkey/%s/camera" % donkey_name,
                                    broker=mqtt_broker)
     self.controller_pub = MQTTValuePub("donkey/%s/controls" % donkey_name,
                                        broker=mqtt_broker)
     self.jpgToImg = JpgToImgArr()
     self.sensor_size = sensor_size
    def __init__(self,
                 car_name="Kari",
                 mqtt_broker="mqtt.eclipse.org",
                 realsense=False,
                 env_type="DonkeyCar"):

        self.camera_sub = MQTTValueSub("donkey/%s/camera" % car_name,
                                       broker=mqtt_broker)

        if realsense:
            self.state_sub = MQTTValueSub("donkey/%s/state" % car_name,
                                          broker=mqtt_broker)

        self.controller_pub = MQTTValuePub("donkey/%s/controls" % car_name,
                                           broker=mqtt_broker)

        self.jpgToImg = JpgToImgArr()

        self.img = np.zeros((40, 40))
        self.state = None
        self.speed = 0
        self.realsense = realsense
        self.sim = env_type != "DonkeyCar"
Esempio n. 5
0
import math
from docopt import docopt
import donkeycar as dk
import cv2

from donkeycar.parts.cv import CvImageView, ImgBGR2RGB, ImgRGB2BGR, ImageScale, ImgWriter, ArrowKeyboardControls
from donkeycar.parts.salient import SalientVis
from donkeycar.parts.network import MQTTValuePub, MQTTValueSub
from donkeycar.parts.transform import Lambda
from donkeycar.parts.image import JpgToImgArr

V = dk.vehicle.Vehicle()
args = docopt(__doc__)
print(args)

V.add(MQTTValueSub(name="donkey/%s/camera" % args["--name"], broker=args["--broker"]), outputs=["jpg"])
V.add(JpgToImgArr(), inputs=["jpg"], outputs=["img_arr"]) 
V.add(ImgBGR2RGB(), inputs=["img_arr"], outputs=["rgb"])
V.add(ImageScale(4.0), inputs=["rgb"], outputs=["lg_img"])
V.add(CvImageView(), inputs=["lg_img"])

V.add(ArrowKeyboardControls(), outputs=["control"])
V.add(MQTTValuePub(name="donkey/%s/controls" % args["--name"]), inputs=["control"])

record_path = args["--record"]
if record_path is not None:
    class ImageSaver:
        def __init__(self, path):
            self.index = 0
            self.path = path
        
Esempio n. 6
0
    threaded = True
    inputs = ['angle', 'throttle']

V.add(cam, inputs=inputs, outputs=['camera/arr'], threaded=threaded)

#V.add(cam, outputs=["camera/arr"], threaded=True)

img_to_jpg = ImgArrToJpg()
V.add(img_to_jpg, inputs=["camera/arr"], outputs=["camera/jpg"])

pub_cam = MQTTValuePub("donkey/%s/camera" % cfg.DONKEY_UNIQUE_NAME,
                       broker=cfg.MQTT_BROKER)
V.add(pub_cam, inputs=["camera/jpg"])

sub_controls = MQTTValueSub("donkey/%s/controls" % cfg.DONKEY_UNIQUE_NAME,
                            def_value=(0., 0.),
                            broker=cfg.MQTT_BROKER)
V.add(sub_controls, outputs=["angle", "throttle"])

# steering_controller = PCA9685(cfg.STEERING_CHANNEL, cfg.PCA9685_I2C_ADDR, busnum=cfg.PCA9685_I2C_BUSNUM)
# steering = PWMSteering(controller=steering_controller,
#                                 left_pulse=cfg.STEERING_LEFT_PWM,
#                                 right_pulse=cfg.STEERING_RIGHT_PWM)

# throttle_controller = PCA9685(cfg.THROTTLE_CHANNEL, cfg.PCA9685_I2C_ADDR, busnum=cfg.PCA9685_I2C_BUSNUM)
# throttle = PWMThrottle(controller=throttle_controller,
#                                 max_pulse=cfg.THROTTLE_FORWARD_PWM,
#                                 zero_pulse=cfg.THROTTLE_STOPPED_PWM,
#                                 min_pulse=cfg.THROTTLE_REVERSE_PWM)

# V.add(steering, inputs=['angle'])
Esempio n. 7
0
 def __init__(self, donkey_name, mqtt_broker):
     self.camera_sub = MQTTValueSub("donkey/%s/camera" % donkey_name,
                                    broker=mqtt_broker)
     self.controller_pub = MQTTValuePub("donkey/%s/controls" % donkey_name,
                                        broker=mqtt_broker)
     self.jpgToImg = JpgToImgArr()
Esempio n. 8
0
V = dk.Vehicle()

print("starting up", cfg.DONKEY_UNIQUE_NAME, "for remote management.")

cam = PiCamera(image_w=cfg.IMAGE_W,
               image_h=cfg.IMAGE_H,
               image_d=cfg.IMAGE_DEPTH)
V.add(cam, outputs=["camera/arr"], threaded=True)

img_to_jpg = ImgArrToJpg()
V.add(img_to_jpg, inputs=["camera/arr"], outputs=["camera/jpg"])

pub_cam = MQTTValuePub("donkey/%s/camera" % cfg.DONKEY_UNIQUE_NAME)
V.add(pub_cam, inputs=["camera/jpg"])

sub_controls = MQTTValueSub("donkey/%s/controls" % cfg.DONKEY_UNIQUE_NAME,
                            def_value=(0., 0.))
V.add(sub_controls, outputs=["angle", "throttle"])

steering_controller = ServoBlaster(cfg.STEERING_CHANNEL)

#PWM pulse values should be in the range of 100 to 200
assert (cfg.STEERING_LEFT_PWM <= 200)
assert (cfg.STEERING_RIGHT_PWM <= 200)
steering = PWMSteering(controller=steering_controller,
                       left_pulse=cfg.STEERING_LEFT_PWM,
                       right_pulse=cfg.STEERING_RIGHT_PWM)

from donkeycar.parts.actuator import Mini_HBridge_DC_Motor_PWM
motor = Mini_HBridge_DC_Motor_PWM(cfg.HBRIDGE_PIN_FWD, cfg.HBRIDGE_PIN_BWD)

V.add(steering, inputs=['angle'])
Esempio n. 9
0
    def __init__(self,
                 alg_type,
                 sim,
                 car_name=args.car_name,
                 encoder_update=args.encoder_update,
                 max_episode_steps=MAX_EPISODE_STEPS):

        if encoder_update == "pixel":
            print("Using Pixel encoder")
            PARAMS["sac"]["encoder_critic_loss"] = True
            PARAMS["sac"]["encoder_ae_loss"] = False

        if encoder_update == "ae":
            print("Using Autoencoder loss")
            PARAMS["sac"]["encoder_critic_loss"] = False
            PARAMS["sac"]["encoder_ae_loss"] = True

        if encoder_update == "aesac":
            print("Using autoencoder and critic loss")
            PARAMS["sac"]["encoder_critic_loss"] = True
            PARAMS["sac"]["encoder_ae_loss"] = True

        self.agent = AE_SAC(PARAMS)
        self.sim = sim

        self.image = np.zeros((120, 160, 3))
        self.command_history = np.zeros(3 * COMMAND_HISTORY_LENGTH)

        self.state = np.vstack([
            self.agent.process_im(self.image, IMAGE_SIZE, RGB)
            for x in range(FRAME_STACK)
        ])
        self.speed = 0

        self.step = 0
        self.episode = 0
        self.episode_reward = 0
        self.replay_buffer = []
        self.max_episode_steps = max_episode_steps

        self.target_speed = 0
        self.steering = 0

        self.training = False
        self.step_start = 0

        self.buffers_sent = False

        self.replay_buffer_pub = MQTTValuePub(car_name + "buffer",
                                              broker="mqtt.eclipse.org")
        self.replay_buffer_sub = MQTTValueSub(car_name + "buffer",
                                              broker="mqtt.eclipse.org",
                                              def_value=(0, True))

        self.replay_buffer_received_pub = MQTTValuePub(
            car_name + "buffer_received", broker="mqtt.eclipse.org")
        self.replay_buffer_received_sub = MQTTValueSub(
            car_name + "buffer_received",
            broker="mqtt.eclipse.org",
            def_value=0)

        self.param_pub = MQTTValuePub(car_name + "param",
                                      broker="mqtt.eclipse.org")
        self.param_sub = MQTTValueSub(car_name + "param",
                                      broker="mqtt.eclipse.org")