/// <summary> /// 作業を開始します /// </summary> public void WorkStart(double target_x, double target_y, SettingsObj obj) { // 作業をクリア DobotDll.SetQueuedCmdClear(); // コマンド開始 DobotDll.SetQueuedCmdStartExec(); OnWorkEvent?.Invoke(this, "作業開始"); // 現在位置を取得 var pose = GetCurrentPose(); OnWorkEvent(this, $"現在位置を取得:"); OnWorkEvent?.Invoke(this, $"X:{pose.x}, Y:{pose.y}, Z:{pose.z}, R:{pose.rHead}"); // 対象の上部まで移動(Z座標は適当) var cmdIndex = ptp((byte)2, (float)target_x, (float)target_y, (float)0.0, pose.rHead); OnWorkEvent?.Invoke(this, "対象の上部まで移動:"); OnWorkEvent?.Invoke(this, $"X:{(float)target_x}, Y:{(float)target_y}, Z:{(float)0.0}, R:{pose.rHead}"); // 対象物のZ座標計算 var object_z = obj.PedestalZ + obj.ObjectHeight; OnWorkEvent?.Invoke(this, "対象物のZ座標:"); OnWorkEvent?.Invoke(this, $"Z:{object_z}"); // 対象の位置まで下がる cmdIndex = ptp((byte)2, (float)target_x, (float)target_y, (float)object_z, pose.rHead); OnWorkEvent?.Invoke(this, "対象物までアームを降ろす:"); OnWorkEvent?.Invoke(this, $"X:{(float)target_x}, Y:{(float)target_y}, Z:{(float)object_z}, R:{pose.rHead}"); // 下がったらサクションカップONしてつかむ DobotDll.SetEndEffectorSuctionCup(true, true, true, ref cmdIndex); OnWorkEvent?.Invoke(this, "サクションカップでつかむ"); // いったん上に持ち上げる cmdIndex = ptp((byte)2, (float)target_x, (float)target_y, (float)0.0, pose.rHead); OnWorkEvent?.Invoke(this, $"持ち上げる:"); OnWorkEvent?.Invoke(this, $"X:{(float)target_x}, Y:{(float)target_y}, Z:{(float)0.0}, R:{pose.rHead}"); // 持っていく場所に移動 cmdIndex = ptp((byte)2, (float)obj.PlacePoseXCoordinate, (float)obj.PlacePoseYCoordinate, (float)obj.PlacePoseZCoordinate, pose.rHead); OnWorkEvent?.Invoke(this, $"持っていく場所に移動:"); OnWorkEvent?.Invoke(this, $"X:{(float)obj.PlacePoseXCoordinate}, Y:{(float)obj.PlacePoseYCoordinate}, Z:{(float)obj.PlacePoseZCoordinate}, R:{pose.rHead}"); // 下がったらサクションカップOFFして放す DobotDll.SetEndEffectorSuctionCup(false, false, false, ref cmdIndex); OnWorkEvent?.Invoke(this, "サクションカップOFFして放す"); // 上がって終わり cmdIndex = ptp((byte)2, (float)obj.PlacePoseXCoordinate, (float)obj.PlacePoseYCoordinate, (float)0.0, pose.rHead); OnWorkEvent?.Invoke(this, "アームを上にあげる"); // コマンド終了 DobotDll.SetQueuedCmdStopExec(); OnWorkEvent?.Invoke(this, "作業終了"); }
/// <summary> /// Make a copy, used when changing stettings, so that changes can be applied or discarded /// </summary> /// <returns></returns> public SettingsObj copy() { SettingsObj settings = new SettingsObj(); settings.saveNum = this.saveNum; // will have to update this for each variable added. settings.volume = this.volume; settings.resolutionX = this.resolutionX; settings.resolutionY = this.resolutionY; settings.vsync = this.vsync; settings.fullscreen = this.fullscreen; return(settings); }
public void UpdateEnvironment() { var settingsObj = new SettingsObj() { ConnectionString = builder.ConnectionString, CentralServerUrl = ptbRemoteSrvURL.Text, SendInterval = int.Parse(ptbSendInterval.Text), KeepHistoryDays = SettingsTable.Get <int>(Strings.VScan_KeepHistoryDays, 1), }; SettingsTable.Set(Strings.Transferring_SettingsObject, settingsObj); DBConfigValue.Save(Strings.Transferring_SettingsObject, settingsObj); SettingsTable.Default.Save(); }
/// <summary> /// 画面遷移 /// </summary> /// <param name="t"></param> public void Navigate(Type t, SettingsObj obj) { // Typeがnullなら終了 if (t == null) { Close(); return; } this.Controls.Clear(); var uc = obj != null? Activator.CreateInstance(t, new Object[] { obj }) as UserControl : Activator.CreateInstance(t) as UserControl; this.Controls.Add(uc); }
protected override void ThreadFunction() { bool fireSuccess = true; try { Auth = DBConfigValue.ReadSf <UserAuth>(Strings.Transferring_AuthObject, UserAuth.Default); if (Auth == null || !Auth.IsValid) { throw new ApplicationException("No authentication provided"); } Settings = DBConfigValue.ReadSf <SettingsObj>(Strings.Transferring_SettingsObject, SettingsObj.Default); if (m_CleanDbCheckRun.Day != DateTime.Now.Day) { CleanDataBase(); m_CleanDbCheckRun = DateTime.Now; } using (var client = new DataServiceClient()) { QuerySiteCodes(client); SendFiles(client, true); if (DateTime.Now.Hour.IsBetween(Program.START_EXPORTMESSAGES_HOUR, Program.END_EXPORTMESSAGES_HOUR)) { SendMessages(client); } } } catch { fireSuccess = false; throw; } finally { if (fireSuccess && Success != null) { Success(this, EventArgs.Empty); } } }
/// <summary> /// /// </summary> /// <param name="num"></param> public void loadSlot(int num) { GameManager.saveGame = SaveObj.LoadGame(num); if (GameManager.saveGame == null) // complain if save file doesn't exist/error // give file-doesn't exist notification here { Debug.Log("Error: Can't find save file \"" + num + "\""); return; } GameManager.settings.saveNum = num; // set the last-save-used to this num, and save that change SettingsObj.saveSettings(GameManager.settings); if (GameManager.saveGame.levelNumber >= 0 && GameManager.saveGame.levelNumber < levelSelector.levelButtons.Length) // load straight to the last visited level if it exists { LevelSelector.changeLevelHelper(GameManager.saveGame.levelNumber); GameManager.changeState(GameManager.gameplay, this); } else { onClick(levelSelector); // else, go to level selector } }
/// <summary> /// Called by confirmMenu when returning. /// If gets success value, will delete the slot at number, else will do nothing /// </summary> /// <param name="retVal"></param> /// <param name="retString"></param> public override void _RespondToConfirm(int retVal, string retString) // if get success va { switch (retVal) { case 0: // accept delete if (number == GameManager.settings.saveNum) { GameManager.settings.saveNum = 0; SettingsObj.saveSettings(GameManager.settings); GameManager.saveGame = null; } SaveObj.DeleteGame(number); //refresh(); onClick(previous); break; default: // canceled, do nothing //refresh(); break; } }
/// <summary> /// Saves the given settings object to the standard location /// </summary> /// <param name="settings"></param> public static void saveSettings(SettingsObj settings) { if (settings == null) // can't save the object if there is no object { throw new System.ArgumentException("Parameter \"settings\" cannot be null"); } Stream stream = null; try { // crashing due to file access issues is a bitch, so don't crash System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); //Debug.Log("Saving to File: \"" + Application.persistentDataPath + "\\Settings.txt\""); stream = new FileStream(Application.persistentDataPath + "\\Settings.txt", FileMode.Create, FileAccess.Write); formatter.Serialize(stream, settings); stream.Close(); } catch (System.Exception e) { Debug.Log(e.Message); // notify me about any exceptions. if (stream != null) // make sure the stream is closed if an exception was generated. { stream.Close(); } } return; }
public void TestWriteJson() { //Arrange var rw = new OlcSideScrollingConsoleGame.Core.ReadWrite(); string Path = "\\Resources\\Settings"; string FileName = "\\settings"; string FileExtension = ".json"; // highscore var HSO = new HighScoreObj() { //Id = 1, Handle = "AAA", //Hours = 0, //Minutes = 5, //Seconds = 2, //Time = "00:05:02:123" }; var HSOList = new List <HighScoreObj>(); HSOList.Add(HSO); var testObj = new SettingsObj() { //misc = "Unit test", //AttributeIndex = new int[3] { 1, 2, 4 } //HighScoreList = HSOList }; //Act var success = rw.WriteJson <SettingsObj>(Path, FileName, FileExtension, testObj); //Assert Assert.IsTrue(success); }
public void discardChanges() { tempSettings = GameManager.settings.copy(); refresh(); }
/// <summary> /// 処理実行 /// </summary> public ImageProcessValue Execute(SettingsObj obj) { try { // webカメラキャプチャ var camera = new OpenCvSharp.VideoCapture(0) { //// 解像度の指定 FrameWidth = 1920, FrameHeight = 1080 }; using (camera) { // カメラ内部パラメータ格納用 Mat mtx = new Mat(); Mat dist = new Mat(); // ymlファイルを読み来み計算パラメータを取得 using (var fs = new FileStorage(obj.CalibratinFilePath, FileStorage.Mode.Read)) { mtx = fs["mtx"].ReadMat(); dist = fs["dist"].ReadMat(); } var src = new Mat(); // 撮影画像の読み取り camera.Read(src); if (src.Empty()) { return(null); } Mat calib = new Mat(); // 歪み補正 Cv2.Undistort(src, calib, mtx, dist); // 画像処理 var tmp = new Mat(); // OpenCVのカラーの並びに変換 Cv2.CvtColor(calib, tmp, OpenCvSharp.ColorConversionCodes.RGB2BGR); // BGR画像をHSV画像に変換 var hsv = new Mat(); Cv2.CvtColor(tmp, hsv, OpenCvSharp.ColorConversionCodes.BGR2HSV); // inRange関数で範囲指定2値化 -> マスク画像として使う var msk = new Mat(); Cv2.InRange(hsv, new Scalar(obj.HueMin, obj.SaturationMin, obj.ValueMin), new Scalar(obj.HueMax, obj.SaturationMax, obj.ValueMax), msk); // bitwise_andで元画像にマスクをかける -> マスクされた部分の色だけ残る var msk_src = new Mat(); Cv2.BitwiseAnd(hsv, hsv, msk_src, msk); var show_msk = new Mat(); // 元の色に戻す Cv2.CvtColor(msk_src, show_msk, ColorConversionCodes.HSV2BGR); // グレースケール変換 var gray = new Mat(); Cv2.CvtColor(show_msk, gray, ColorConversionCodes.BGR2GRAY); // 2値化 var th = new Mat(); Cv2.Threshold(gray, th, 130, 255, ThresholdTypes.Otsu); // ブロブとラベリング var label = new Mat(); var stats = new Mat(); var centroids = new Mat(); ConnectedComponents cc = Cv2.ConnectedComponentsEx(th); if (cc.LabelCount <= 1) { return(null); } // draw labels //cc.RenderBlobs(show_msk); // draw bonding boxes except background foreach (var blob in cc.Blobs.Skip(1)) { show_msk.Rectangle(blob.Rect, Scalar.Red); } // filter maximum blob var maxBlob = cc.GetLargestBlob(); var filtered = new Mat(); cc.FilterByBlob(show_msk, filtered, maxBlob); // 矩形探索 // マスク画像から矩形探索 Point[][] contours; HierarchyIndex[] hierarchy; Cv2.FindContours(th, out contours, out hierarchy, RetrievalModes.List, ContourApproximationModes.ApproxNone); // 見つからなかったら何もしない if (contours.Length == 0) { return(null); } // 回転を考慮した外接矩形 foreach (var cont in contours) { var rect = Cv2.MinAreaRect(cont); var box = Cv2.BoxPoints(rect).Select(x => (Point)x); } Cv2.DrawContours(show_msk, contours, -1, Scalar.Yellow, 3); //Cv2.ImShow("show_msk", show_msk); // 画像、画像上の位置発火 var val = new ImageProcessValue(); val.CameraImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(show_msk); val.Blob = maxBlob; // メモリリーク対策でDispose呼ぶ mtx.Dispose(); dist.Dispose(); calib.Dispose(); tmp.Dispose(); hsv.Dispose(); msk.Dispose(); msk_src.Dispose(); show_msk.Dispose(); gray.Dispose(); th.Dispose(); label.Dispose(); stats.Dispose(); centroids.Dispose(); filtered.Dispose(); return(val); } } catch (Exception e) { throw e; } }
public void Awake() { #region finding objects/setting refferences if ((instance == null) || (instance == this)) // singleton pattern { instance = this; } else { Debug.Log("Duplicate GameManager destroyed"); DestroyImmediate(this.gameObject); } IState[] objList = (IState[])Resources.FindObjectsOfTypeAll(typeof(IState)); // find all IState objects // should be easily tweakable to work when switching between scenes foreach (IState state in objList) { if (istates[(int)state._stateType] == null) // add one of each type to list of istates, delete any duplicates { istates[(int)state._stateType] = state; // the type enum is used to put each istate in a unique nd predictable slot state.gameObject.SetActive(false); } else { Debug.Log("Destroyed duplicate of IState " + state._stateType); DestroyImmediate(state.gameObject); } } for (int i = 0; i < istates.Length; i++) // check that one of each type exists { if (istates[i] == null) { Debug.Log("Error: IState object of type \"" + (IStateType)i + "\" not found"); } else { istates[i].initialize(); // initialize each that exists } } ConfirmMenu[] conList = (ConfirmMenu[])Resources.FindObjectsOfTypeAll(typeof(ConfirmMenu)); if (conList.Length > 0) { confirmMenu = conList[0]; // only use one copy of the ConfirmMenu object confirmMenu.gameObject.SetActive(false); } else { Debug.Log("Error: No ConfirmMenu object is exists"); } for (int i = 1; i < conList.Length; i++) { DestroyImmediate(conList[i].gameObject); // destroy extras } #endregion //settup spritebook & index spriteBook = _spriteBook; // move info from non-static variables to static variables errorSprite = _errorSprite; for (int s = 0; s < spriteBook.Length; s++) // get the index and name of every sprite, so you can look them up by name { if (spriteBook[s] != null) { string lowercase = spriteBook[s].name.ToLowerInvariant(); //Debug.Log(string.Format("Trying to add sprite {0} to sprite index", lowercase)); if (!spriteIndex.ContainsKey(lowercase)) // don't add any duplicate names { spriteIndex.Add(lowercase, s); } else { throw new System.Exception("Error: sprite with name" + spriteBook[s].name + " present in spritebook more than once"); } } } // load settings stuff, and apply them. if (SettingsObj.settingsExists()) //load the settings if the file exists { settings = SettingsObj.loadSettings(); } else // else create new file { Debug.Log("Creating new settings file"); settings = new SettingsObj(); SettingsObj.saveSettings(settings); } applySettings(settings); // apply the saved settings // consider changing so that it keeps resolution settings from start-up menu // load from save if possible, or load default save. if (settings.saveNum >= 1 && settings.saveNum <= 3) // if saveNum = 1, 2, or 3, savefile should exist, else one won't { saveGame = SaveObj.LoadGame(settings.saveNum); if (saveGame == null) { Debug.Log("Indicated save does not exist, load an existing save or create a new one."); settings.saveNum = 0; SettingsObj.saveSettings(settings); } } gameplay = (Gameplay)istates[(int)GameManager.IStateType.gameplay]; // get gameplay IState from istate[Enum.gameplay] slot of array if (istates[(int)GameManager.IStateType.gameMenu] != null) // set current state to gamemenu, or complain if gameMenu istate doesn't exist { currentstate = istates[(int)GameManager.IStateType.gameMenu]; currentstate.StartState(null); istates[(int)GameManager.IStateType.gameMenu].gameObject.SetActive(true); } //InputManager.instance.LoadKeybinds(); // load keybindings eventSystem = (EventSystem)FindObjectOfType(typeof(EventSystem)); }
/// <summary> /// 引数つきコンストラクタ /// </summary> /// <param name="obj"></param> public DobotExecute(SettingsObj obj) : this() { _obj = obj; }