Esempio n. 1
0
        public string Action(string actionName, string actionParameters)
        {
            if (actionName == "StepDelay")
            {
                if (actionParameters == "Get")
                {
                    return(StepDelay.ToString());
                }
                else
                {
                    StepDelay = Convert.ToInt16(actionParameters);
                    return(StepDelay.ToString());
                }
            }

            else if (actionName == "MaxStep")
            {
                MaxStep = Convert.ToInt16(actionParameters);
                return(MaxStep.ToString());
            }
            else if (actionName == "MinStep")
            {
                if (actionParameters == "Get")
                {
                    return(MinStep.ToString());
                }
                else
                {
                    MinStep = Convert.ToInt16(actionParameters);
                    return(MinStep.ToString());
                }
            }
            else if (actionName == "Position")
            {
                focuserPosition = Convert.ToInt16(actionParameters);
                if (m_serial != null)
                {
                    m_serial.SetCurPos(focuserPosition);
                }
                return(Position.ToString());
            }
            else
            {
                return("?");
            }
            //throw new ASCOM.ActionNotImplementedException("Action " + actionName + " is not implemented by this driver");
        }
Esempio n. 2
0
                public override int GetHashCode()
                {
                    int hash = 1;

                    if (MaxStep != 0L)
                    {
                        hash ^= MaxStep.GetHashCode();
                    }
                    if (maxWallTime_ != null)
                    {
                        hash ^= MaxWallTime.GetHashCode();
                    }
                    if (MaxBlobSequenceLength != 0L)
                    {
                        hash ^= MaxBlobSequenceLength.GetHashCode();
                    }
                    if (_unknownFields != null)
                    {
                        hash ^= _unknownFields.GetHashCode();
                    }
                    return(hash);
                }
Esempio n. 3
0
        /// <summary>
        /// Save profile values
        /// </summary>
        public void SaveProfileSettings()
        {
            if (Temperature > TempMax)
            {
                Temperature = TempMax;
            }
            if (Temperature < TempMin)
            {
                Temperature = TempMin;
            }
            if (_position > MaxStep)
            {
                _position = MaxStep;
            }

            //ascom items
            Profile.WriteValue(sCsDriverId, "Absolute", Absolute.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "MaxIncrement", MaxIncrement.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "MaxStep", MaxStep.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "Position", _position.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "StepSize", stepSize.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "TempComp", tempComp.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "TempCompAvailable", TempCompAvailable.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "Temperature", Temperature.ToString(CultureInfo.InvariantCulture));
            //extended focuser items
            Profile.WriteValue(sCsDriverId, "CanHalt", CanHalt.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "CanStepSize", CanStepSize.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "Synchronous", Synchronous.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "TempMax", TempMax.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "TempMin", TempMin.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "TempPeriod", TempPeriod.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "TempProbe", TempProbe.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "TempSteps", TempSteps.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "SettleTime", settleTime.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "Logging", TL.Enabled.ToString(CultureInfo.InvariantCulture));
        }
Esempio n. 4
0
    /// <summary>
    /// Called when an action is received from either the player input or the neural network
    /// </summary>
    /// vectorAction[i] represents:
    /// Index 0: move vector z (+1 = right -1 = left)
    /// Index 1: yaw angle z (+1 = right -1 = left)
    /// Index 1: pitch angle z (+1 = right -1 = left)
    /// <param name="actionBuffers"> The actions to take </param>
    public override void OnActionReceived(ActionBuffers actionBuffers)
    {
        ActionSegment <int> act  = actionBuffers.DiscreteActions;
        var dirToGo              = Vector3.zero;
        var rotateDir            = Vector3.zero;
        var rotateMonitor        = 0f;
        var dirToGoForwardAction = act[0];
        var rotateDirAction      = act[1];
        var rotateMonitorAction  = act[2];

        if (dirToGoForwardAction == 1)
        {
            dirToGo = 1f * transform.forward;
        }
        else if (dirToGoForwardAction == 2)
        {
            dirToGo = -1f * transform.forward;
        }
        if (rotateDirAction == 1)
        {
            rotateDir = transform.up * -1f;
        }
        else if (rotateDirAction == 2)
        {
            rotateDir = transform.up * 1f;
        }
        if (rotateMonitorAction == 1)
        {
            rotateMonitor = -1f;
        }
        else if (rotateMonitorAction == 2)
        {
            rotateMonitor = 1f;
        }

        rigidbody.AddForce(dirToGo * moveForce, ForceMode.VelocityChange);
        transform.Rotate(rotateDir, Time.fixedDeltaTime * yawSpeed);

        monitorLocalAngle += rotateMonitor * pitchSpeed * Time.fixedDeltaTime;
        monitorLocalAngle  = Mathf.Clamp(monitorLocalAngle, MinPitchAngle, MaxPitchAngle);

        monitor.transform.localRotation = Quaternion.Euler(monitorLocalAngle, 0, 0);

        if (rigidbody.velocity.sqrMagnitude > 0.5f) // slow it down
        {
            rigidbody.velocity *= 0.7f;
        }

        Vector3 screenPos = agentCamera.WorldToScreenPoint(dockingStation.transform.position);

        steps++;
        stepsEpoch++;

        if (stepsEpoch == MaxStep - 1)
        {
            successfulDocking = false;
            dockingTime       = 0.02f * MaxStep;

            String first  = distanceFromDocker.ToString();
            String second = spawningAngle.ToString();
            String third  = MaxStep.ToString();
            String fourth = successfulDocking.ToString();
            String fifth  = dockingTime.ToString();
            Debug.Log("Docking not successful in epoch " + epoch);
            var newLine = string.Format("{0};{1};{2};{3};{4}", first, second, third, fourth, fifth);
            Debug.Log(newLine);
            csv.AppendLine(newLine);
        }

        if (steps >= 1)
        {
            //bool patternFound = Utils.isPatternVisible(agentCamera);
            bool patternFound = (screenPos.x > 0) & (screenPos.x < agentCamera.pixelWidth) & (screenPos.y > 0) & (screenPos.y < agentCamera.pixelHeight) & (screenPos.z > 0) & (screenPos.z < 10);
            //Debug.Log("Pattern found? " + patternFound);
            if (patternFound)
            {
                float reward_x = Mathf.Abs(screenPos.x - (agentCamera.pixelWidth / 2));  // [0 - agentCamera.pixelWidth/2]
                reward_x = -reward_x / (agentCamera.pixelWidth / 4) + 3;                 // [1-3]
                float reward_y = Mathf.Abs(screenPos.y - (agentCamera.pixelHeight / 2)); // [0 - agentCamera.pixelHeight/2]
                reward_y = -reward_y / (agentCamera.pixelHeight / 4) + 3;                // [1-3]
                //float reward_scale = screenPos.z<1.25f?3:0; // [0-3]
                float reward_scale   = Mathf.Clamp(3 - screenPos.z, 0, 3);
                float reward_pattern = ((reward_x + reward_y + reward_scale) * steps) / (MaxStep * 9f);
                //AddReward(reward_pattern);
                //Debug.Log("Reward for detecting the pattern of: " + reward_pattern + ", detected at coordinates: " + screenPos);
            }
            else
            {
                float reward_pattern = -((float)steps / (float)MaxStep);
                //AddReward(reward_pattern);
                //Debug.Log("Reward for not detecting the pattern of: " + reward_pattern);
            }
            steps = steps % 1;
        }
    }