Пример #1
0
    // Update is called once per frame
    void Update()
    {
        Vector2 v = rigidbody2D.velocity;

        if (v.magnitude > 0)
        {
            if (v.y > 0)
            {
                hasFallen = true;
            }
        }
        else if (hasFallen)
        {
            stTools.Remove(gameObject);
        }

        if (ready)
        {
            if (Input.GetButtonUp(launchKey))
            {
                ready = false;
                SetMotion motion = GetComponent <SetMotion>();
                motion.speed = multiplier * (float)stData.GetDictionaryValue("Game", "Thrust");
                motion.DoSetMotion();
                GetComponent <ControlsRotateDrive>().enabled = false;
                GetComponent <MouseFace>().enabled           = false;
                rigidbody2D.gravityScale = 1;
            }
        }
    }
Пример #2
0
        /**
         * Update method which gets called by PiCarConnection when sending image frames and car actions.
         */
        public void HandleStream(byte[] imageBytes, SetMotion action)
        {
            if (imageBytes == null)
            {
                return;
            }

            var  save_dir_path  = getPathName();
            var  session_prefix = getSessionName();
            bool save_to_disk   = getSaveEnabled();

            //Convert bytes to ImageSource type for GUI
            var imgSource = (ImageSource) new ImageSourceConverter().ConvertFrom(imageBytes);

            // Update the GUI
            try
            {
                synchronizationContext.Post(o => StreamImage.Source = (ImageSource)o, imgSource);
            }
            catch (Exception e)
            {
                LogField.AppendText($"{DateTime.Now}: Error updating the GUI with image received from car: {e}\n");
            }

            if (save_to_disk)
            {
                try
                {
                    var csv_path        = $"{save_dir_path}\\{session_prefix}.csv";
                    var image_file_name = $"{session_prefix}_{saved_frame_count.ToString("D5")}.jpg";

                    saved_frame_count += 1;
                    using (var fileStream = new FileStream($"{save_dir_path}\\train\\{image_file_name}", FileMode.Create))
                    {
                        //Console.WriteLine($"Writing image of length {imageBytes.Length}");
                        fileStream.Write(imageBytes, 0, imageBytes.Length);
                        fileStream.Flush();
                    }

                    using (var streamWriter = new StreamWriter(csv_path, true))
                    {
                        streamWriter.WriteLineAsync($"train/{image_file_name},{action.Throttle},{action.Direction}");
                    }
                }
                catch (IOException e)
                {
                    LogField.AppendText($"{DateTime.Now}:\tError writing stream data to disk: {e.Message}\n");
                }
            }
        }
Пример #3
0
 //Send a signal to the PiCar telling it how to move its wheels
 public void SetMotion(double throttle, double direction)
 {
     try
     {
         // Send a control signal to the PiCar
         var request = new SetMotion {
             Throttle = throttle, Direction = direction
         };
         remoteControlCall.RequestStream.WriteAsync(request);
     }
     catch (RpcException e)
     {
         Console.Write("RPC failed " + e);
         throw;
     }
 }