Beispiel #1
0
    static public void Reception_Message_Astar(Communication.Communication_Trame trame)
    {
        ASTAR_COMMUNICATION comm = new ASTAR_COMMUNICATION();

        //Commence par transformer la trame en un message utilisable
        ASTAR_COMMUNICATION.Nodes_Values data = comm.Trame_To_Data(trame);

        //Puis met à jour l'affichage
        try
        {
            //Un message contient 60 valeurs, donc le status de 120 noeuds, soit 2 lignes
            //1ère ligne
            for (int noeud = 0; noeud < Field_Size_Y / Node_Size; noeud++)
            {
                Nodes[data.line_id, noeud].Set_Status(data.nodes_values[noeud]);
            }

            //2ème ligne
            for (int noeud = 0; noeud < Field_Size_Y / Node_Size; noeud++)
            {
                Nodes[data.line_id + 1, noeud].Set_Status(data.nodes_values[noeud + Field_Size_Y / Node_Size]);
            }
        }
        catch
        {
        }
    }
Beispiel #2
0
 public void Send_Trame(Communication.Communication_Trame trame)
 {
     Communication.Communication_Message message = new Communication.Communication_Message();
     message.Heure = DateTime.Now;
     message.Trame = trame;
     Push_Message_Out(message);
 }
Beispiel #3
0
        public Com_Position_Robot_Data Trame_To_Data(Communication.Communication_Trame input_trame)
        {
            Com_Position_Robot_Data output = new Com_Position_Robot_Data();

            output = (Com_Position_Robot_Data)Communication.GetStructFromArray <Com_Position_Robot_Data>(input_trame.Data);
            return(output);
        }
Beispiel #4
0
        public Logger_Debug_Data Trame_To_Data(Communication.Communication_Trame input_trame)
        {
            Logger_Debug_Data output = new Logger_Debug_Data();

            output = (Logger_Debug_Data)Communication.GetStructFromArray <Logger_Debug_Data>(input_trame.Data);
            return(output);
        }
Beispiel #5
0
    public Action_Datas Trame_To_Data(Communication.Communication_Trame input_trame)
    {
        Action_Datas output = new Action_Datas();

        output = (Action_Datas)Communication.GetClassFromArray <Action_Datas>(input_trame.Data);
        return(output);
    }
Beispiel #6
0
    static public void Reception_Message_Astar_Vector(Communication.Communication_Trame trame, bool fixes)
    {
        ASTAR_VECTOR_COMMUNICATION comm = new ASTAR_VECTOR_COMMUNICATION();

        //Commence par transformer la trame en un message utilisable
        ASTAR_VECTOR_COMMUNICATION.Vectors_Values data = comm.Trame_To_Data(trame);

        //Puis met à jour l'affichage
        try
        {
            //Si un effacement est demandé
            if (data.Effacement == 1)
            {
                Clear_Vectors(data.Numero_Robot, fixes);
            }


            //Un message contient 8 vecteurs maximum
            foreach (ASTAR_VECTOR_COMMUNICATION.ASTAR_Vector vect in data.vectors)
            {
                Create_New_Vector(vect.Color, vect.Start, vect.End, data.Numero_Robot, fixes);
            }
        }
        catch
        {
        }
    }
    public void Send_trame(Communication.Communication_Trame trame)
    {
        Communication comm = new Communication();

        comm.Trame_Data = trame;
        Messages_to_send.Add(comm);
    }
Beispiel #8
0
    public void Envoi_Commande_AX12Power(bool power)
    {
        Communication.Communication_Trame trame = new Communication.Communication_Trame();

        byte[] arr = new byte[1];

        arr[0] = Convert.ToByte(power);

        trame.Data   = arr;
        trame.Length = 1;

        trame.Slave_Adresse  = Communication.Slave_Adresses.ALL_CARDS; //uniquement la carte 1 qui gère les déplacement
        trame.Instruction    = Communication.Com_Instruction.DEMANDE_AX_12_POWER;
        trame.XBEE_DEST_ADDR = Communication.Adress_Xbee.ALL_XBEE;

        GameObject.FindWithTag("Communication port").GetComponent <Message_Sender>().Send_Trame(trame);

        if (!power)
        {
            for (int i = 0; i < 10; i++)
            {
                GameObject.FindWithTag("Communication port").GetComponent <Message_Sender>().Send_Trame(trame);
            }
        }
    }
Beispiel #9
0
    IEnumerator Demande_Infos()
    {
        yield return(new WaitForSeconds(.1f));

        Communication.Communication_Trame trame = new Communication.Communication_Trame();

        trame.Length         = 0;
        trame.Instruction    = Communication.Com_Instruction.DEMANDE_INFO;
        trame.XBEE_DEST_ADDR = Communication.Adress_Xbee.ALL_XBEE;

        while (true)
        {
            yield return(new WaitForSeconds(.2f));

            foreach (Traffic_Display robot in this.Traffic_display)
            {
                yield return(new WaitForSeconds(.02f));

                if (robot.Demande_Infos_Toggle != null)
                {
                    if (robot.Demande_Infos_Toggle.GetComponent <Toggle>().isOn)
                    {
                        for (int index_carte = 0; index_carte < Common_settings.static_Nombre_Cartes_Max_Par_Robot; index_carte++)
                        {
                            trame.Slave_Adresse = (Communication.Slave_Adresses)(index_carte + 1);
                            GameObject.FindWithTag("Communication port").GetComponent <Message_Sender>().Send_Trame(trame);
                            yield return(new WaitForSeconds(.01f));
                        }
                    }
                }
            }
        }
    }
Beispiel #10
0
    /*
     * public List<Communication> Send_Logger(string str, Logger_Debug_Color color)
     * {
     *      //Création locale de le liste de messages à envoyer
     *      List<Communication> List_trame_echange = new List<Communication>();
     *
     *      //Création de la trame de base d'un message
     *      Communication trame_echange = new Communication();
     *      trame_echange.Set_Instruction(Communication.Com_Instruction.LOGGER_DEBUG);
     *
     *      trame_echange.Set_SlaveAdress(Communication.Slave_Adresses.ALL_CARDS);
     *
     *      //Création de la structure du message de Log à envoyer
     *      Logger_Debug_Data logger_Debug = new Logger_Debug_Data();
     *      logger_Debug.Color = color;
     *
     *      if (str.Length < Max_Char_per_Log)
     *      {
     *              //Une seule trame suffit
     *              logger_Debug.Nombre_Carateres = (byte)str.Length;
     *
     *              //Copie la string dans la structure du Logger
     *              str.CopyTo(0, logger_Debug.Text, 0, str.Length);
     *
     *              //Ajoute un 0 de fin de chaine de caractere
     *              if (str.Length < Max_Char_per_Log - 1)
     *              {
     *                      logger_Debug.Text[str.Length] = (char)0;
     *              }
     *
     *              //Copie la structure du Logger dans la trame à envoyer
     *              trame_echange.Set_Data(logger_Debug);
     *
     *              //Ajoute cette trame à la liste des trames à envoyer
     *              List_trame_echange.Add(trame_echange);
     *
     *              return List_trame_echange;
     *      }
     *      else
     *      {
     *              //Plusieurs trames serront necessaires
     *      }
     *      return List_trame_echange;
     * }*/

    public Log_Message Trame_To_Data(Communication.Communication_Trame input_trame)
    {
        Log_Message log = new Log_Message();

        log.data = (Logger_Debug_Data)Communication.GetClassFromArray <Logger_Debug_Data>(input_trame.Data);
        log.str  = Encoding.UTF8.GetString(input_trame.Data, 3, log.data.Nombre_Carateres);

        return(log);
    }
Beispiel #11
0
    public Com_Graphique_Datas Trame_To_Data(Communication.Communication_Trame input_trame)
    {
        Com_Graphique_Datas output = new Com_Graphique_Datas();

        output.Datas = new Com_Graphique_data[12];

        output = (Com_Graphique_Datas)Communication.GetStructFromArray <Com_Graphique_Datas>(input_trame.Data);
        return(output);
    }
Beispiel #12
0
    public void Send_PID()
    {
        reglage_pid pid = new reglage_pid();

        pid.id = ID;

        if (coef_P.text != "")
        {
            pid.P = float.Parse(coef_P.text, Common_settings.culture);
        }
        if (coef_I.text != "")
        {
            pid.I = float.Parse(coef_I.text, Common_settings.culture);
        }
        if (coef_D.text != "")
        {
            pid.D = float.Parse(coef_D.text, Common_settings.culture);
        }

        if (Max_Min.text != "")
        {
            pid.Min_Max = (byte)float.Parse(Max_Min.text, Common_settings.culture);
        }
        if (Cumul.text != "")
        {
            pid.Cumul = (short)float.Parse(Cumul.text, Common_settings.culture);
        }

        if (Sommation.isOn)
        {
            pid.Sommation = 1;
        }
        else
        {
            pid.Sommation = 0;
        }

        if (Enable.isOn)
        {
            pid.Enable = 1;
        }
        else
        {
            pid.Enable = 0;
        }

        Communication.Communication_Trame trame = new Communication.Communication_Trame();

        trame = Communication.GetTrameFromClass <reglage_pid>(pid);

        trame.Slave_Adresse  = Communication.Slave_Adresses.MultiFct_1; //uniquement la carte 1 qui gère les déplacement
        trame.Instruction    = Communication.Com_Instruction.PARAMETRES_PID;
        trame.XBEE_DEST_ADDR = Communication.Adress_Xbee.ALL_XBEE;

        GameObject.FindWithTag("Communication port").GetComponent <Message_Sender>().Send_Trame(trame);
    }
Beispiel #13
0
    public void Envoi_Vitesse(GameObject vitesse_panel)
    {
        TMP_InputField Vit_Avance;
        TMP_InputField Accel_Avance;
        TMP_InputField Decel_Avance;
        TMP_InputField Vit_Rotation;
        TMP_InputField Accel_Rotation;
        TMP_InputField Decel_Rotation;

        Vit_Avance     = FindChildByRecursion(vitesse_panel.transform, "Vit Avance").GetComponent <TMP_InputField>();
        Accel_Avance   = FindChildByRecursion(vitesse_panel.transform, "Accel Avance").GetComponent <TMP_InputField>();
        Decel_Avance   = FindChildByRecursion(vitesse_panel.transform, "Decel Avance").GetComponent <TMP_InputField>();
        Vit_Rotation   = FindChildByRecursion(vitesse_panel.transform, "Vit Rotation").GetComponent <TMP_InputField>();
        Accel_Rotation = FindChildByRecursion(vitesse_panel.transform, "Accel Rotation").GetComponent <TMP_InputField>();
        Decel_Rotation = FindChildByRecursion(vitesse_panel.transform, "Decel Rotation").GetComponent <TMP_InputField>();


        reglage_speed speed = new reglage_speed();


        if (Vit_Avance.text != "")
        {
            speed.Vitesse_Avance = (ushort)(float.Parse(Vit_Avance.text, Common_settings.culture) * 1000);
        }
        if (Accel_Avance.text != "")
        {
            speed.Accel_Avance = (ushort)(float.Parse(Accel_Avance.text, Common_settings.culture) * 1000);
        }
        if (Decel_Avance.text != "")
        {
            speed.Deccel_Avance = (ushort)(float.Parse(Decel_Avance.text, Common_settings.culture) * 1000);
        }

        if (Vit_Rotation.text != "")
        {
            speed.Vitesse_Rotation = (ushort)(float.Parse(Vit_Rotation.text, Common_settings.culture) * 1000);
        }
        if (Accel_Rotation.text != "")
        {
            speed.Accel_Rotation = (ushort)(float.Parse(Accel_Rotation.text, Common_settings.culture) * 1000);
        }
        if (Decel_Rotation.text != "")
        {
            speed.Deccel_Rotation = (ushort)(float.Parse(Decel_Rotation.text, Common_settings.culture) * 1000);
        }

        Communication.Communication_Trame trame = new Communication.Communication_Trame();

        trame = Communication.GetTrameFromClass <reglage_speed>(speed);

        trame.Slave_Adresse  = Communication.Slave_Adresses.MultiFct_1; //uniquement la carte 1 qui gère les déplacement
        trame.Instruction    = Communication.Com_Instruction.VITESSE_ROBOT;
        trame.XBEE_DEST_ADDR = Communication.Adress_Xbee.ALL_XBEE;

        GameObject.FindWithTag("Communication port").GetComponent <Message_Sender>().Send_Trame(trame);
    }
Beispiel #14
0
    public Com_Reponse_Info Trame_To_Data(Communication.Communication_Trame input_trame)
    {
        Com_Reponse_Info output = new Com_Reponse_Info();

        output.Position_Servos.Position   = new ushort[NB_SERVO];
        output.Position_AX12.Position     = new ushort[NB_AX_12];
        output.Position_AX12.Torque       = new short[NB_AX_12];
        output.Mesures_Analogiques.Mesure = new ushort[NB_MES_ANA];
        output.PositionRobot = new Com_Position_Robot_Data();

        output = (Com_Reponse_Info)Communication.GetClassFromArray <Com_Reponse_Info>(input_trame.Data);
        return(output);
    }
Beispiel #15
0
    public void Envoi_Servos(GameObject servo_panel)
    {
        st_Destination_Servos destination = new st_Destination_Servos();

        destination.servo = new servo_destination[Communication_Nombre_Servos_Max_Message];

        int index_message_output = 0;

        //Pour chaque servo selectionné
        for (int index_input = 0; index_input < Communication_Nombre_Servos_Max_Message; index_input++)
        {
            destination.servo[index_input] = new servo_destination();

            servo_destination_temp temp = FindChildByRecursion(servo_panel.transform, $"1 Servo destination ({index_input})").GetComponentInChildren <Commande_Servos>().Get_Servos_Values();

            if (temp.numero != 0)
            {
                destination.servo[index_message_output].ID          = (byte)temp.numero;
                destination.servo[index_message_output].Destination = (ushort)temp.destination;
                destination.servo[index_message_output].Torque      = (ushort)temp.torque;
                index_message_output++;
            }
            else
            {
            }
        }

        destination.Nombre_servos_to_move = (byte)index_message_output;

        //Lecture du temps de déplacement des servos
        if (FindChildByRecursion(servo_panel.transform, "Temps deplacement").GetComponentInChildren <TMP_InputField>().text != "")
        {
            destination.Time_to_move = ushort.Parse(FindChildByRecursion(servo_panel.transform, "Temps deplacement").GetComponentInChildren <TMP_InputField>().text);
        }
        else
        {
            destination.Time_to_move = 0;
        }


        Communication.Communication_Trame trame = new Communication.Communication_Trame();

        trame = Communication.GetTrameFromClass <st_Destination_Servos>(destination);

        trame.Slave_Adresse  = Communication.Slave_Adresses.ALL_CARDS; //Toutes les cartes
        trame.Instruction    = Communication.Com_Instruction.DESTINATION_SERVOS_AND_AX12;
        trame.XBEE_DEST_ADDR = Communication.Adress_Xbee.ALL_XBEE;

        GameObject.FindWithTag("Communication port").GetComponent <Message_Sender>().Send_Trame(trame);
    }
Beispiel #16
0
    public void Envoi_Commande_Simulation(bool simu)
    {
        Communication.Communication_Trame trame = new Communication.Communication_Trame();

        byte[] arr = new byte[1];

        arr[0] = Convert.ToByte(simu);

        trame.Data   = arr;
        trame.Length = 1;

        trame.Slave_Adresse  = Communication.Slave_Adresses.MultiFct_1; //uniquement la carte 1 qui gère les déplacement
        trame.Instruction    = Communication.Com_Instruction.DEMANDE_SIMULATION_MOTEURS;
        trame.XBEE_DEST_ADDR = Communication.Adress_Xbee.ALL_XBEE;

        GameObject.FindWithTag("Communication port").GetComponent <Message_Sender>().Send_Trame(trame);
    }
Beispiel #17
0
    public void Envoi_Position_Adversaire(Vector3 _position)
    {
        Communication.Communication_Trame trame = new Communication.Communication_Trame();

        Infos_Carte.Com_Position_Robot_Data position = new Infos_Carte.Com_Position_Robot_Data();
        position.Position_X = (short)(_position.x * 10);
        position.Position_Y = (short)(_position.y * 10);

        Communication com = new Communication();

        trame = Communication.GetTrameFromStruct <Infos_Carte.Com_Position_Robot_Data>(position);

        trame.Slave_Adresse  = Communication.Slave_Adresses.IA_BOARD; //uniquement la carte IA qui gère l'évitement
        trame.Instruction    = Communication.Com_Instruction.POSITION_AUTRE_ROBOT;
        trame.XBEE_DEST_ADDR = Communication.Adress_Xbee.ALL_XBEE;

        GameObject.FindWithTag("Communication port").GetComponent <Message_Sender>().Send_Trame(trame);
    }
Beispiel #18
0
    public static Communication_Trame GetTrameFromStruct <T>(T data) where T : struct
    {
        int size = Marshal.SizeOf(data);

        byte[] arr = new byte[size];

        IntPtr ptr = Marshal.AllocHGlobal(size);

        Marshal.StructureToPtr(data, ptr, true);
        Marshal.Copy(ptr, arr, 0, size);
        Marshal.FreeHGlobal(ptr);

        Communication.Communication_Trame trame = new Communication.Communication_Trame();

        trame.Data   = arr;
        trame.Length = (byte)size;

        return(trame);
    }
Beispiel #19
0
    public void Envoi_Reglages_Odometrie(GameObject input)
    {
        TMP_InputField Coef_Distance;
        TMP_InputField Coef_Rotation;
        TMP_InputField Correction_Diametre_roues;

        //When pre-setting

        Coef_Distance             = FindChildByRecursion(input.transform, "Coef D").GetComponent <TMP_InputField>();
        Coef_Rotation             = FindChildByRecursion(input.transform, "Coef Rot").GetComponent <TMP_InputField>();
        Correction_Diametre_roues = FindChildByRecursion(input.transform, "Correction Diametre").GetComponent <TMP_InputField>();

        TMP_Dropdown Asserv;

        Asserv = FindChildByRecursion(input.transform, "Type Asserv").GetComponent <TMP_Dropdown>();

        bool Simulation = FindChildByRecursion(input.transform, "Simulation").GetComponent <Toggle>().enabled;


        Odometrie.Reglages_Odometrie reglages = new Odometrie.Reglages_Odometrie();

        reglages.Coef_D              = float.Parse(Coef_Distance.text, Common_settings.culture);
        reglages.Coef_Rot            = float.Parse(Coef_Rotation.text, Common_settings.culture);
        reglages.Correction_Diametre = float.Parse(Correction_Diametre_roues.text, Common_settings.culture);

        reglages.simulation = (byte)(Simulation ? 1 : 0);

        reglages.asserv = (Odometrie.Type_Asservissements)Asserv.value;



        Communication.Communication_Trame trame = new Communication.Communication_Trame();

        trame = Communication.GetTrameFromClass <Odometrie.Reglages_Odometrie>(reglages);

        trame.Slave_Adresse  = Communication.Slave_Adresses.MultiFct_1; //uniquement la carte 1 qui gère les déplacement
        trame.Instruction    = Communication.Com_Instruction.PARAMETRES_ODOMETRIE;
        trame.XBEE_DEST_ADDR = Communication.Adress_Xbee.ALL_XBEE;

        GameObject.FindWithTag("Communication port").GetComponent <Message_Sender>().Send_Trame(trame);
    }
Beispiel #20
0
    public Nodes_Values Trame_To_Data(Communication.Communication_Trame input_trame)
    {
        Nodes_Values_array output_temp = new Nodes_Values_array();

        output_temp.nodes_values = new byte[NB_Noeuds_par_mess / 2];

        output_temp = (Nodes_Values_array)Communication.GetClassFromArray <Nodes_Values_array>(input_trame.Data);

        Nodes_Values output = new Nodes_Values();

        output.line_id      = output_temp.Line_ID;
        output.nodes_values = new ASTAR.Astar_Node_Status[NB_Noeuds_par_mess];

        for (int index = 0; index < NB_Noeuds_par_mess / 2; index++)
        {
            output.nodes_values[index * 2]     = (ASTAR.Astar_Node_Status)((output_temp.nodes_values[index] & 0b00001111));
            output.nodes_values[index * 2 + 1] = (ASTAR.Astar_Node_Status)((output_temp.nodes_values[index] & 0b11110000) >> 4);
        }

        return(output);
    }
Beispiel #21
0
    public void Envoi_Deplacement(GameObject deplacement_panel)
    {
        TMP_InputField Destination_X;
        TMP_InputField Destination_Y;
        TMP_InputField Destination_Distance;
        TMP_InputField Destination_Theta;
        TMP_InputField Vitesse_Roue_Gauche;
        TMP_InputField Vitesse_Roue_Droite;

        Destination_X        = FindChildByRecursion(deplacement_panel.transform, "X").GetComponent <TMP_InputField>();
        Destination_Y        = FindChildByRecursion(deplacement_panel.transform, "Y").GetComponent <TMP_InputField>();
        Destination_Distance = FindChildByRecursion(deplacement_panel.transform, "Distance").GetComponent <TMP_InputField>();
        Destination_Theta    = FindChildByRecursion(deplacement_panel.transform, "Theta").GetComponent <TMP_InputField>();
        Vitesse_Roue_Gauche  = FindChildByRecursion(deplacement_panel.transform, "Vitesse Roue Gauche").GetComponent <TMP_InputField>();
        Vitesse_Roue_Droite  = FindChildByRecursion(deplacement_panel.transform, "Vitesse Roue Droite").GetComponent <TMP_InputField>();


        st_COORDONNEES       coord = new st_COORDONNEES();
        st_DESTINATION_ROBOT dest  = new st_DESTINATION_ROBOT();


        if (Destination_X.text != "")
        {
            coord.X = short.Parse(Destination_X.text, Common_settings.culture);
        }
        if (Destination_Y.text != "")
        {
            coord.Y = short.Parse(Destination_Y.text, Common_settings.culture);
        }
        if (Destination_Distance.text != "")
        {
            coord.Distance = short.Parse(Destination_Distance.text, Common_settings.culture);
        }

        if (Destination_Theta.text != "")
        {
            float temp_ang = float.Parse(Destination_Theta.text, Common_settings.culture);
            temp_ang   *= Mathf.Deg2Rad;
            temp_ang   *= 100;
            coord.Angle = (short)temp_ang;
        }


        if (Vitesse_Roue_Gauche.text != "")
        {
            coord.Vitesse_Roue_Gauche = short.Parse(Vitesse_Roue_Gauche.text, Common_settings.culture);
        }
        if (Vitesse_Roue_Droite.text != "")
        {
            coord.Vitesse_Roue_Droite = short.Parse(Vitesse_Roue_Droite.text, Common_settings.culture);
        }

        coord.Type_Deplacement = (enum_TYPE_MOVE_)FindChildByRecursion(deplacement_panel.transform, "type deplacement").GetComponent <TMP_Dropdown>().value;
        coord.Type_Arret       = (enum_TYPE_ARRET_)FindChildByRecursion(deplacement_panel.transform, "Freinage").GetComponent <TMP_Dropdown>().value;

        st_Parametre_Deplacement parametres = new st_Parametre_Deplacement();

        parametres.Distance_Detection_Fin_Trajectoire = 3 * 100;
        parametres.Angle_Avant_Debut_Avance           = (byte)(0.1F * 100);
        parametres.Angle_Detection_Fin_Trajectoire    = (byte)(0.05F * 100);

        coord.ptrParameters = parametres;

        dest.coord = coord;

        if (FindChildByRecursion(deplacement_panel.transform, "Effacement").GetComponent <TMP_Dropdown>().value == 0)
        {
            dest.Replace = false;
        }
        else
        {
            dest.Replace = true;
        }

        Communication.Communication_Trame trame = new Communication.Communication_Trame();

        trame = Communication.GetTrameFromClass <st_DESTINATION_ROBOT>(dest);

        trame.Slave_Adresse  = Communication.Slave_Adresses.MultiFct_1; //uniquement la carte 1 qui gère les déplacement
        trame.Instruction    = Communication.Com_Instruction.DESTINATION_ROBOT;
        trame.XBEE_DEST_ADDR = Communication.Adress_Xbee.ALL_XBEE;

        GameObject.FindWithTag("Communication port").GetComponent <Message_Sender>().Send_Trame(trame);
    }
Beispiel #22
0
    public Vectors_Values Trame_To_Data(Communication.Communication_Trame input_trame)
    {
        Vectors_Values_array output_temp = new Vectors_Values_array();

        output_temp.vectors_values = new byte[NB_Vector_par_mess * 8];

        output_temp = (Vectors_Values_array)Communication.GetClassFromArray <Vectors_Values_array>(input_trame.Data);

        Vectors_Values output = new Vectors_Values();

        output.Effacement  = (byte)(output_temp.Effacement & 0b00000001);
        output.Nb_vecteurs = (byte)(output_temp.Nb_vecteurs);

        output.Numero_Robot = (Infos_Carte.Com_Position_Robot_Identification)((output_temp.Effacement & 0b00000010) >> 1);

        output.vectors = new ASTAR_Vector[output.Nb_vecteurs];


        for (byte vecteur_index = 0; vecteur_index < output.Nb_vecteurs; vecteur_index++)
        {
            byte[] data = new byte[10];
            for (int i = 0; i < 10; i++)
            {
                data[i] = output_temp.vectors_values[i + 10 * vecteur_index];
            }

            output.vectors[vecteur_index] = new ASTAR_Vector();
            //Pour chaque vecteur reçu

            //1 octet = Couleur
            output.vectors[vecteur_index].Color = (Astar_Vector_Color)data[0];

            //1 octet perdu d'alignement

            //4 octets pour Start X et Start Y
            //Start X
            int value = data[3];
            value  = value << 8;
            value += data[2];

            output.vectors[vecteur_index].Start.x = (float)(value);

            //start Y
            value  = data[5];
            value  = value << 8;
            value += data[4];
            output.vectors[vecteur_index].Start.y = (float)(value);


            //4 octets pour End X et End Y
            //End X
            value  = data[7];
            value  = value << 8;
            value += data[6];

            output.vectors[vecteur_index].End.x = (float)(value);

            //End Y
            value  = data[9];
            value  = value << 8;
            value += data[8];
            output.vectors[vecteur_index].End.y = (float)(value);
        }

        return(output);
    }
Beispiel #23
0
    /*************************************************/

    #endregion



    public void Envoi_Ordre_Deplacement()
    {
        st_COORDONNEES       coord = new st_COORDONNEES();
        st_DESTINATION_ROBOT dest  = new st_DESTINATION_ROBOT();

        if (destination_x.text != "")
        {
            coord.X = (short)Convert.ToSingle(destination_x.text.Replace('.', ','));
        }
        if (destination_y.text != "")
        {
            coord.Y = (short)Convert.ToSingle(destination_y.text.Replace('.', ','));
        }
        if (angle.text != "")
        {
            coord.Angle = (short)Convert.ToSingle(angle.text.Replace('.', ','));
        }
        coord.Angle *= 100;
        if (distance.text != "")
        {
            coord.Distance = (short)Convert.ToSingle(distance.text.Replace('.', ','));
        }

        coord.Type_Deplacement = (enum_TYPE_MOVE_)Type_deplacement.value;
        coord.Type_Arret       = (enum_TYPE_ARRET_)Freinage.value;

        st_Parametre_Deplacement parametres = new st_Parametre_Deplacement();

        parametres.Distance_Detection_Fin_Trajectoire = 3 * 100;
        parametres.Angle_Avant_Debut_Avance           = (byte)(0.1F * 100);
        parametres.Angle_Detection_Fin_Trajectoire    = (byte)(0.05F * 100);

        coord.ptrParameters = parametres;

        dest.coord = coord;

        if (Effacement.value == 0)
        {
            dest.Replace = false;
        }
        else
        {
            dest.Replace = true;
        }

        Communication.Communication_Trame trame = new Communication.Communication_Trame();

        trame.Slave_Adresse  = Communication.Slave_Adresses.ALL_CARDS;
        trame.Instruction    = Communication.Com_Instruction.DESTINATION_ROBOT;
        trame.XBEE_DEST_ADDR = Communication.Adress_Xbee.ALL_XBEE;

        int size = Marshal.SizeOf(dest);

        byte[] arr = new byte[size];

        IntPtr ptr = Marshal.AllocHGlobal(size);

        Marshal.StructureToPtr(dest, ptr, true);
        Marshal.Copy(ptr, arr, 0, size);
        Marshal.FreeHGlobal(ptr);
        trame.Data   = arr;
        trame.Length = (byte)size;

        Communication_port.GetComponent <Communication_Send_Instructions>().Send_Instruction(trame);
    }
 public void Send_Instruction(Communication.Communication_Trame trame)
 {
     this.GetComponent <Communication_TX_RX_Trames>().Send_trame(trame);
 }
Beispiel #25
0
    public void Send_PID()
    {
        reglage_pid pid = new reglage_pid();

        pid.id = ID;

        if (coef_P.text != "")
        {
            pid.P = Convert.ToSingle(coef_P.text.Replace('.', ','));
        }
        if (coef_I.text != "")
        {
            pid.I = Convert.ToSingle(coef_I.text.Replace('.', ','));
        }
        if (coef_D.text != "")
        {
            pid.D = Convert.ToSingle(coef_D.text.Replace('.', ','));
        }

        if (Max_Min.text != "")
        {
            pid.Min_Max = (byte)Convert.ToSingle(Max_Min.text.Replace('.', ','));
        }
        if (Cumul.text != "")
        {
            pid.Cumul = (short)Convert.ToSingle(Cumul.text.Replace('.', ','));
        }

        if (Sommation.isOn)
        {
            pid.Sommation = 1;
        }
        else
        {
            pid.Sommation = 0;
        }

        if (Enable.isOn)
        {
            pid.Enable = 1;
        }
        else
        {
            pid.Enable = 0;
        }

        Communication.Communication_Trame trame = new Communication.Communication_Trame();

        trame.Slave_Adresse  = Communication.Slave_Adresses.ALL_CARDS;
        trame.Instruction    = Communication.Com_Instruction.PARAMETRES_PID;
        trame.XBEE_DEST_ADDR = Communication.Adress_Xbee.ALL_XBEE;

        int size = Marshal.SizeOf(pid);

        byte[] arr = new byte[size];

        IntPtr ptr = Marshal.AllocHGlobal(size);

        Marshal.StructureToPtr(pid, ptr, true);
        Marshal.Copy(ptr, arr, 0, size);
        Marshal.FreeHGlobal(ptr);
        trame.Data   = arr;
        trame.Length = (byte)size;

        Communication_port.GetComponent <Communication_Send_Instructions>().Send_Instruction(trame);
    }