Commit cf2d4128 authored by Marco Buttu's avatar Marco Buttu
Browse files

A try to fix some not repeteable issues during setup.

Some times, from LLP to CCB, after the encoder power on,
a failure is notified but the setup is done properly.
parent bbcb0118
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ void SetupThread::onStart() {
    AUTO_TRACE("SetupThread::onStart()"); 

    m_positioning.clear();
    m_configuration->m_status = Management::MNG_WARNING;
    m_configuration->m_status = Management::MNG_OK;
}

void SetupThread::onStop() { AUTO_TRACE("SetupThread::onStop()"); }
@@ -51,6 +51,7 @@ void SetupThread::run()
    }

    vector<string> park_check; 
    vector<string> failure_check;

    // Park the components
    unsigned long counter = 0;
@@ -92,10 +93,19 @@ void SetupThread::run()
                            continue;
                        }
                        else if(status_bset.test(STATUS_FAILURE)) {
                            if(find(failure_check.begin(), failure_check.end(), comp_name) != failure_check.end()) {
                                string msg(comp_name + " in failure.");
                                ACS_SHORT_LOG((LM_ERROR, msg.c_str()));
                                if(find(park_check.begin(), park_check.end(), comp_name) == park_check.end())
                                    park_check.push_back(comp_name);
                            }
                            else {
                                // Try a setup, just once
                                if(!component_ref->isStarting()) {
                                    component_ref->setup(0);
                                }
                                failure_check.push_back(comp_name);
                            }
                            continue;
                        }
                        else if(component_ref->isInEmergencyStop()){
@@ -273,7 +283,7 @@ void SetupThread::run()
                                else if(component_ref->isInEmergencyStop()){
                                    string msg(comp_name + " in emergency stop.");
                                    ACS_SHORT_LOG((LM_ERROR, msg.c_str()));
                                    m_configuration->m_status = Management::MNG_WARNING;
                                    m_configuration->m_status = Management::MNG_FAILURE;
                                    m_configuration->m_isStarting = false;
                                    m_configuration->m_isConfigured = false;
                                    m_configuration->m_actualSetup = "unknown";
+2 −1
Original line number Diff line number Diff line
@@ -76,7 +76,8 @@ TrackingThread::TrackingThread(
                                    m_configuration->m_isElevationTracking = true;
                                    m_configuration->m_status = Management::MNG_OK;
                                }
                                else {
                                // Maybe now it is not starting, parked or parking, because it is ready...
                                else if(!component_ref->isReady()) {
                                    m_configuration->m_status = Management::MNG_FAILURE;
                                    ACS::ROdoubleSeq_var refActPos = component_ref->actPos();
                                    ACSErr::Completion_var completion;
+87 −0
Original line number Diff line number Diff line
from __future__ import with_statement
import random 
import math
import time
import os
from datetime import datetime

import unittest2 # https://pypi.python.org/pypi/unittest2
import Management
import MinorServo
import Antenna

from MinorServoErrors import MinorServoErrorsEx
from Acspy.Common.TimeHelper import getTimeStamp
from Acspy.Clients.SimpleClient import PySimpleClient
from Acspy.Util import ACSCorba


__author__ = "Marco Buttu <mbuttu@oa-cagliari.inaf.it>"

class CannotSetupTest(unittest2.TestCase):

    telescope = os.getenv('TARGETSYS')
    
    @classmethod
    def setUpClass(cls):
        cls.client = PySimpleClient()
        cls.boss = cls.client.getComponent('MINORSERVO/Boss')
        cls.pfp = cls.client.getComponent('MINORSERVO/PFP')
        
    @classmethod
    def tearDownClass(cls):
        cls.client.releaseComponent('MINORSERVO/Boss')
        cls.client.releaseComponent('MINORSERVO/PFP')
        cls.client.disconnect()

    def test_setup_after_manual_movement(self):
        """Verify the setup completes after a manual movement"""
        self.boss.setup('XKP')
        self.wait_until_ready()
        # XKP pos: PFP: RY(mm)=(-25.75); TX(mm)=(-841.15); TZ(mm)=(-45.9);
        target_position = [-25, -900, -47]
        self.pfp.setPosition(target_position, 0)
        self.wait_until(self.pfp.isTracking)
        position = self.pfp.getPositionFromHistory(0)
        # self.assertSequenceEqual(target_position, position)
        self.boss.setup('LLP')
        self.wait_until_ready()
        self.assertEqual(self.boss.getActualSetup(), 'LLP')

    def wait_until(self, is_true, timeout=240):
        time.sleep(0.5)
        t0 = datetime.now()
        while not is_true():
            if (datetime.now() - t0).seconds > timeout:
                assert False, 'Cannot wait_until %s' %is_true
            else:
                time.sleep(1)
        time.sleep(0.5)

    def wait_until_ready(self, timeout=240):
        time.sleep(0.5)
        t0 = datetime.now()
        while not self.boss.isReady():
            if (datetime.now() - t0).seconds > timeout:
                assert False, 'The minor servo boss is not ready'
            else:
                time.sleep(1)
        time.sleep(0.5)

    def wait_until_not_ready(self, timeout=240):
        time.sleep(0.5)
        t0 = datetime.now()
        while self.boss.isReady():
            if (datetime.now() - t0).seconds > timeout:
                assert False, 'The minor servo boss is not parked'
            else:
                time.sleep(1)
        time.sleep(0.5)


if __name__ == '__main__':
    if 'Configuration' in os.getenv('ACS_CDB'):
        unittest2.main(verbosity=2, failfast=True) # Real test using the antenna CDB
    else:
        from PyMinorServoTest import simunittest
        simunittest.run(CannotSetupTest)
+71 −0
Original line number Diff line number Diff line
# mscu-start
# acsStartContainer -cpp MinorServoContainer
# acsStartContainer -cpp MinorServoBossContainer
# acsStartContainer -py AntennaBossSimulatorContainer

from __future__ import with_statement

import threading
import time
import math
import datetime
import Antenna

from multiprocessing import Value
from random import randrange as rr
from Acspy.Clients.SimpleClient import PySimpleClient
from Acspy.Common.TimeHelper import getTimeStamp

antenna_client = PySimpleClient()

# Start a thread in order to set the AntennaBoss position
stop = Value('i', 0)
stop.value
antenna = antenna_client.getComponent('ANTENNA/Boss')
def set_position(antenna, stop):
    az0 = rr(-100, 50)
    el0 = rr(5, 30)
    while True:
        az = math.radians(az0 + 0.005)
        el = math.radians(el0 + 0.01)
        antenna.setOffsets(az, el, Antenna.ANT_HORIZONTAL)
        time.sleep(0.1)
        if stop.value:
            break

t = threading.Thread(target=set_position, args = (antenna, stop))
t.daemon = True
t.start()

# Get the MinorServo axes position
msclient = PySimpleClient()
boss = msclient.getComponent('MINORSERVO/Boss')
boss.setup('KKG')
while not boss.isReady():
    time.sleep(2)

starting_time = datetime.datetime.now()
total_time = 1800 # seconds
deltas = []
timestamps = []
while (datetime.datetime.now() - starting_time).seconds < total_time:
    # Random timevalue in the past 2 minutes
    target_time = getTimeStamp().value - rr(10**7, 200*10**7)
    t0 = datetime.datetime.now()
    axes = boss.getAxesPosition(target_time)
    delta = datetime.datetime.now() - t0
    sharp_delta = (delta.seconds + delta.microseconds)*1.0 / 10**6
    timestamps.append((t0 - starting_time).seconds)
    deltas.append(sharp_delta)
    time.sleep(1)

print 'Total test time: ', total_time
print 'max_time: %.4f' % max(deltas)
print 'min_time: %.4f' % min(deltas)
with open('outfile', 'w') as outfile:
    for timestamp, delta in zip(timestamps, deltas):
        outfile.write('%d %.4f\n' % (timestamp, delta))

# Stop the Antenna set_position thread
stop.value = True
t.join(5)