/*******************************************************************************/
/*        Description file for the carousel in standalone mode                 */
/*                                                                             */
/*******************************************************************************/


/*******************************************************************************/
/* The file carousel__simulation.groovy is generated with the script :         */
/* generateCarouselDescription.sh                                              */
/* from the files carousel__simulation_head and socket__simulation__model      */
/* DO NOT MODIFY carousel__simulation.groovy : the changes will be lost after  */
/* the next generation.                                                        */
/*******************************************************************************/

package carouselSimulation

import org.lsst.ccs.subsystems.fcs.*
import org.lsst.ccs.subsystems.fcs.singlefiltertest.*
import org.lsst.ccs.subsystems.fcs.common.*
import org.lsst.ccs.subsystems.fcs.drivers.*
import org.lsst.ccs.subsystems.fcs.simulation.*
import org.lsst.ccs.subsystems.fcs.testbench.*
import org.lsst.ccs.framework.Configurable
import org.lsst.ccs.startup.CCSBuilder ;


import static org.lsst.gruth.jutils.MapArgs.*
import static org.lsst.gruth.nodes.NodeUtils.loopList

//for each socket we define a position on the carousel : positionOnCarouselSocket
//and the position of the socket when it is at STANDBY position.
def positionOnCarouselSocket1 = 0
def positionOnCarouselSocket2 = 72
def positionOnCarouselSocket3 = 144
def positionOnCarouselSocket4 = 216
def positionOnCarouselSocket5 = 288
def standbyPositionSocket1 = 0
def standbyPositionSocket2 = 288
def standbyPositionSocket3 = 216
def standbyPositionSocket4 = 144
def standbyPositionSocket5 = 72


//Carousel Can Open Devices (CAN-CBX-AI814)
def adcName = "ai814"

//Carousel clamps controllers name
def clampXminusControllerName = "clampXminusController" //controller to unlock clamp on the side Xminus
def clampXplusControllerName =  "clampXplusController" //controller to unlock clamp on the side Xplus


CCSBuilder builder = ["carousel-standalone"]

builder.
        "Main Module" ( CarouselMainModule,
                argMap(a("name", "main"),
                        anInt("tickMillis", 3000),
                        ref("bridge"),
                        ref("filterManager"),
                        ))
                 


            //begin description of Main submodules
            {       
                //-------------------------
                // BEGIN Bridge description
                // Bridge
                bridge (SimuBridgeForCarousel,
                        argMap(aString("name", "bridge"),
                            anInt("tickMillis", 1000),
                            ref("tcpProxy"),
                            ref("clampXminusController"),
                            ref("clampXplusController"),
                            ref("carouselController"),
                            ref("clampsSensorsReaderDevice"),                            
                            ref("ai420_1"),
                            ref("ai420_2"),
                            ))
                        {//begin description of bridge's children 
                            
                            // tcp Proxy
                            tcpProxy (SimuCanOpenProxy,
                                argMap(aString("name", "tcpProxy"),
                                    anInt("tickMillis", 1000),
                                    anInt("portNumber", 54321,[static:true, 
                                            constraints:1024..99000]),
                                    aString("myClientName","TestBench",[static:true]),
                                    anInt("hardwareBootTimeout",2500, 
                                            [description:"A timeout for the harwdare booting process",
                                            constraints:1000..10000])))
                            
                            clampXminusController (SimuCarouselClampController,
                                    argMap( a("name", clampXminusControllerName),
                                    anInt("tickMillis",3000),
                                    aString("nodeID","1a"),
                                    aString("serialNB","79003317"),
                                    aMap("paramsForCurrent", [MotorType:11, PositionSensorType:3,PolePairNumber:8,
                                            ContinuousCurrentLimit:2360,OutputCurrentLimit:4720,
                                            ThermalTimeConstantWinding:160,
                                            MaxSpeedInCurrentMode:25]),
                                    aMap("paramsForProfilePosition", [MotionProfileType:0]),
                                    aMap("paramsForHoming",[HomeOffset:0]),
                                    ))  

                            clampXplusController (SimuCarouselClampController,
                                    argMap( a("name", clampXplusControllerName),
                                    anInt("tickMillis",3000),
                                    aString("nodeID","1b"),
                                    aString("serialNB","79003313"),
                                    aMap("paramsForCurrent", [MotorType:11, PositionSensorType:3,PolePairNumber:8,
                                            ContinuousCurrentLimit:2360,OutputCurrentLimit:4720,
                                            ThermalTimeConstantWinding:160,
                                            MaxSpeedInCurrentMode:25]),
                                    aMap("paramsForProfilePosition", [MotionProfileType:0]),
                                    aMap("paramsForHoming",[HomeOffset:0]),
                                    ))
                                
                            carouselController (SimuCarouselController,
                                argMap( aString("name", "carouselController"),
                                anInt("tickMillis",3000),
                                aString("nodeID","1c", [static:true, 
                                        description:"can open node ID in HEXADECIMAL for EPOS24/50 for rotation carousel motor"]),
                                aString("serialNB","7900xxxxx", [static:true, 
                                        description:"EPOS24/50 serial number for the rotation carousel motor controller"]),
                                aMap("paramsForCurrent", 
                                    [ContinuousCurrentLimit:3440,
                                    OutputCurrentLimit:6880,
                                    MaxSpeedInCurrentMode:2000,
                                    MotorType:10,PolePairNumber:1,
                                    PositionSensorType:1]),
                                aMap("paramsForProfilePosition", 
                                    [MinPositionLimit:-300,
                                    MaxPositionLimit:550000,
                                    MotionProfileType:0]),
                                aMap("paramsForHoming",[HomeOffset:0]),
                                ))
                            
                            // can open devices to read clamps sensors
                            clampsSensorsReaderDevice (SimuADCDevice,
                                    argMap(aString("name", "clampsSensorsReaderDevice"),
                                        anInt("tickMillis", 3000),
                                        aString("nodeID","1d"),
                                        aString("serialNB","44110125008180")))
                            
                            // can open devices to read brakes sensors and temperatures
                            ai420_1 (SimuADCDevice,
                                    argMap(aString("name", "ai420_1"),
                                        anInt("tickMillis", 3000),
                                        aString("nodeID","1e"),
                                        aString("serialNB","c7yyyyyy")))

                            // can open devices to read brakes sensors and temperatures
                            ai420_2 (SimuADCDevice, 
                                    argMap(aString("name", "ai420_2"),
                                        anInt("tickMillis", 1000),
                                        aString("nodeID","1f"),
                                        aString("serialNB","c7zzzzzz")))    
                            
                        } //end of carousel's bridge hardware


                //-------------------------
                // BEGIN Filter description
                
                filterManager(FilterManager,
                    argMap( a("name", "filterManager"),
                        ref ("filterU"),
                        ref ("filterG"),
                        ref ("filterR"),
                        ref ("filterI"),
                        ref ("filterZ"),
                        ref ("filterY"),
                        ref ("dummyFilter")
                    ))
                {//begin description of filter manager's children

                    "filterU" (Filter, 
                            argMap(aString("name", "filterU"),
                            anInt("filterID", 1),
                            aDbl("weight", "45.320")))
                    "filterG" (Filter,
                            argMap(aString("name", "filterG"),
                            anInt("filterID", 2),
                            aDbl("weight", "53.215")))
                    "filterR" (Filter,
                            argMap(aString("name", "filterR"),
                            anInt("filterID", 3),
                            aDbl("weight", "62")))
                    "filterI" (Filter,
                            argMap(aString("name", "filterI"),
                            anInt("filterID", 4),
                            aDbl("weight", "47.1")))
                    "filterZ" (Filter,
                            argMap(aString("name", "filterZ"),
                            anInt("filterID", 5),
                            aDbl("weight", "45")))
                    "filterY" (Filter,
                            argMap(aString("name", "filterY"),
                            anInt("filterID", 6),
                            aDbl("weight", "44")))
                    "dummyFilter" (Filter,
                            argMap(aString("name", "dummyFilter"),
                            anInt("filterID", 10),
                            aDbl("weight", "44.5")))
                    
                }//begin description of filter manager's children

    // END Filter description
    // ------------------------
    
    //----------------------------
    // BEGIN Carousel description
    carousel (CarouselModule,
        argMap( a("name", "carousel"),
            anInt("tickMillis",5000),
            ref ("socket1"),
            ref ("socket2"),
            ref ("socket3"),
            ref ("socket4"),
            ref ("socket5"),
        ))
    
    {//begin description of carousel's children
        
        
