aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineSerialView.xaml
blob: 2393ab6e7e78ff869dbaade777f99fef7dfa4a84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<UserControl x:Class="Tango.MachineStudio.UI.Views.MachineSerialView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:autoComplete="clr-namespace:Tango.AutoComplete.Editors;assembly=Tango.AutoComplete"
             xmlns:autoCompleteMachine="clr-namespace:Tango.MachineStudio.Common.AutoComplete;assembly=Tango.MachineStudio.Common"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:vm="clr-namespace:Tango.MachineStudio.UI.ViewModels"
             xmlns:local="clr-namespace:Tango.MachineStudio.UI.Views"
             mc:Ignorable="d" Width="559" Height="266" Background="{StaticResource Dialog.Background}" d:DataContext="{d:DesignInstance Type=vm:MachineSerialViewVM, IsDesignTimeCreatable=False}" Foreground="{StaticResource MainWindow.Foreground}">

    <UserControl.Resources>
        <autoCompleteMachine:MachinesProvider x:Key="MachinesProvider" />
    </UserControl.Resources>

    <Grid>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="80"/>
                <RowDefinition Height="1*"/>
            </Grid.RowDefinitions>

            <Grid>
                <StackPanel Orientation="Horizontal" Margin="10">
                    <Image Source="{StaticResource MachineSmall}" Width="60" RenderOptions.BitmapScalingMode="Fant"></Image>
                    <TextBlock Text="Virtual Machine" VerticalAlignment="Center" Margin="10 0 0 0" FontSize="20"></TextBlock>
                </StackPanel>
            </Grid>

            <Grid Grid.Row="1" Margin="10 0 10 10">
                <Grid.RowDefinitions>
                    <RowDefinition Height="1*"/>
                    <RowDefinition Height="50"/>
                </Grid.RowDefinitions>

                <Grid>
                    <StackPanel Margin="0 10 0 0" >
                        <TextBlock TextWrapping="Wrap">
                            <Run>Connecting directly to a machine's embedded firmware requires the selection of an existing machine from the database in order for machine studio to function properly.</Run>
                            <LineBreak/>
                            <LineBreak/>
                            <Run>Please select a 'virtual machine' by entering the machine serial number</Run>
                        </TextBlock>

                        <StackPanel Orientation="Horizontal" Margin="0 20 0 0" Width="300" HorizontalAlignment="Left">
                            <materialDesign:PackIcon Kind="BarcodeScan" VerticalAlignment="Bottom" Width="24" Height="24" />
                            <autoComplete:AutoCompleteTextBox HorizontalContentAlignment="Stretch" Width="300" Margin="10 0 0 0" FontSize="16" Provider="{StaticResource MachinesProvider}" SelectedItem="{Binding SelectedMachine,Mode=TwoWay}" materialDesign:HintAssist.Hint="Serial Number / Name" DisplayMember="SerialNumber">
                                <autoComplete:AutoCompleteTextBox.ItemTemplate>
                                    <DataTemplate>
                                        <Border Padding="5">
                                            <DockPanel LastChildFill="False" Width="250">
                                                <StackPanel Orientation="Horizontal" DockPanel.Dock="Left">
                                                    <Image Source="/Images/machine-trans.png" Width="24" RenderOptions.BitmapScalingMode="Fant" />
                                                    <TextBlock Margin="10 0 0 0" FontWeight="SemiBold" Text="{Binding SerialNumber}" VerticalAlignment="Center"></TextBlock>
                                                </StackPanel>
                                                <TextBlock DockPanel.Dock="Right" HorizontalAlignment="Right" Text="{Binding Name}" Foreground="{StaticResource GrayBrush}" VerticalAlignment="Center"></TextBlock>
                                            </DockPanel>
                                        </Border>
                                    </DataTemplate>
                                </autoComplete:AutoCompleteTextBox.ItemTemplate>
                            </autoComplete:AutoCompleteTextBox>
                        </StackPanel>
                    </StackPanel>
                </Grid>

                <Grid Grid.Row="1">
                    <Button HorizontalAlignment="Right" Width="140" Command="{Binding OKCommand}">CONNECT</Button>
                </Grid>
            </Grid>
        </Grid>
    </Grid>
</UserControl>
: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/************************************************************************************************************************
 **************************************************************************************************************************/

#include <DataDef.h>
#include <Drivers/FPGA/Motors_Driver/PowerSTEP01.h>
#include "include.h"

#include "PMR/Hardware/UploadHardWareConfigurationRequest.pb-c.h"
#include "PMR/Hardware/HardWareConfiguration.pb-c.h"
#include "PMR/Hardware/HardwareMotor.pb-c.h"
#include "PMR/Hardware/HardwareDancer.pb-c.h"
#include "PMR/Hardware/HardwareWinder.pb-c.h"
#include "PMR/Hardware/HardwareBreakSensor.pb-c.h"
#include  "PMR/Diagnostics/EventType.pb-c.h"

#include "Modules/AlarmHandling/AlarmHandling.h"
#include "PMR/Printing/JobSpool.pb-c.h"
#include "PMR/common/MessageContainer.pb-c.h"

#include "Common/SWUpdate/FileSystem.h"
#include "drivers/Flash_Memory/fatfs/ff.h"
#include "drivers/SSI_Comm/Dancer/Dancer.h"
#include "drivers/Flash_ram/FlashProgram.h"

#include "drivers/Flash_ram/MCU_E2Prom.h"
#include "modules/ids/ids_ex.h"

#include "thread.h"
MotorDriverConfigStruc  MotorsCfg[NUM_OF_MOTORS]={0};
HardwarePidControl MotorsControl[MAX_THREAD_MOTORS_NUM] = {0};

double MotorSpeedSamples[MAX_THREAD_MOTORS_NUM][MAX_CONTROL_SAMPLES] = {0};
int MotorSpeedSamplePointer[MAX_THREAD_MOTORS_NUM] = {0};

int32_t MotorSamples[MAX_THREAD_MOTORS_NUM][MAX_CONTROL_SAMPLES] = {0};
int MotorSamplePointer[MAX_THREAD_MOTORS_NUM] = {0};
double NormalizedErrorCoEfficient[MAX_THREAD_MOTORS_NUM] = {0};
int DancerStopActivityLimit[MAX_THREAD_MOTORS_NUM] = {0};
HardwareDancer DancersCfg[MAX_SYSTEM_DANCERS] = {0};

#define BREAK_SENSOR_LIMIT 10

bool BreakSensorenabled;
int32_t BreakSensordebouncetimemilli = BREAK_SENSOR_LIMIT;

HardwarePidControlType ThreadMotorIdToControlId[MAX_THREAD_MOTORS_NUM] = {HARDWARE_PID_CONTROL_TYPE__MotorFeeder,HARDWARE_PID_CONTROL_TYPE__MotorDryer,HARDWARE_PID_CONTROL_TYPE__MotorPooler,HARDWARE_PID_CONTROL_TYPE__MotorWinder,0};

//********************************************************************************************************************
uint32_t MotorsConfigMessage(HardwareConfiguration * HWrequest)
{
    uint32_t status = PASSED;
    TimerMotors_t Motor_i,MotorId;
    HardwareMotor *request;
    if (HWrequest == NULL)
        return ERROR;
    AlarmHandlingSetAlarm (EVENT_TYPE__MACHINE_STATE_HW_CONFIG_FAILED,OFF);

    for (MotorId = 0; MotorId < HWrequest->n_motors ; MotorId++)
    {
        request = HWrequest->motors[MotorId];
        if (request == NULL)
            return ERROR;
        Motor_i = request->hardwaremotortype;
        MotorsCfg[Motor_i].configword = request->configword;
        MotorsCfg[Motor_i].hardwaremotortype = request->hardwaremotortype;
        MotorsCfg[Motor_i].minfrequency = request->minfrequency;
        MotorsCfg[Motor_i].maxfrequency = request->maxfrequency;
        MotorsCfg[Motor_i].setmicrostep = request->setmicrostep;
        MotorsCfg[Motor_i].microstep = request->microstep;
        MotorsCfg[Motor_i].maxchangeslope = request->maxchangeslope;
        MotorsCfg[Motor_i].highlengthmicrosecond = request->highlengthmicrosecond;
        MotorsCfg[Motor_i].speedmaster = request->speedmaster;
        MotorsCfg[Motor_i].pulseperround = request->pulseperround;
        MotorsCfg[Motor_i].pulleyradius = request->pulleyradius;
        MotorsCfg[Motor_i].configword = request->configword;
        if(MotorDriverResponse[Motor_i].DriverType == CombinrdMotDriver)
        {
            MotorsCfg[Motor_i].directionthreadwize = request->directionthreadwize ^ 1;//PowerSTEP01
        }
        else
        {
            MotorsCfg[Motor_i].directionthreadwize = request->directionthreadwize;//L6470 + L6472
        }
        MotorsCfg[Motor_i].kvalhold = request->kvalhold;
        MotorsCfg[Motor_i].kvalrun = request->kvalrun;
        MotorsCfg[Motor_i].kvalacc = request->kvalacc;
        MotorsCfg[Motor_i].kvaldec = request->kvaldec;
        MotorsCfg[Motor_i].overcurrentthreshold = request->overcurrentthreshold;
        MotorsCfg[Motor_i].stallthreshold = request->stallthreshold;
        MotorsCfg[Motor_i].thermalcompensationfactor = request->thermalcompensationfactor;
        MotorsCfg[Motor_i].lowspeedoptimization = request->lowspeedoptimization;
        MotorsCfg[Motor_i].stslp = request->stslp;
        MotorsCfg[Motor_i].intspd = request->intspd;
        MotorsCfg[Motor_i].fnslpacc = request->fnslpacc;
        MotorsCfg[Motor_i].fnslpdec = request->fnslpdec;
        MotorsCfg[Motor_i].fsspd = request->fsspd;

        MotorsCfg[Motor_i].gatecfg1 = request->gatecfg1;
        MotorsCfg[Motor_i].gatecfg2 = request->gatecfg2;
        MotorsCfg[Motor_i].tvalhold = request->tvalhold;
        MotorsCfg[Motor_i].tvalrun  = request->tvalrun ;
        MotorsCfg[Motor_i].tvalacc  = request->tvalacc ;
        MotorsCfg[Motor_i].tvaldec  = request->tvaldec ;
        MotorsCfg[Motor_i].tfast    = request->tfast   ;
        MotorsCfg[Motor_i].tonmin   = request->tonmin  ;
        MotorsCfg[Motor_i].toffmin  = request->toffmin ;
        MotorsCfg[Motor_i].has_p01configword  = (bool)(request->has_p01configword) ;//needed for backward compatibility
        MotorsCfg[Motor_i].p01configword  = request->p01configword ;

            status = MotorConfig( Motor_i,  &MotorsCfg[Motor_i]);
            if ((Motor_i >= HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_1)&&(Motor_i <= HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_8))
            {
                IDS_Dispenser_Init(Motor_i-HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_1);
            }
    }
        return status;

}
uint32_t MotorPidRequestMessage(HardwarePidControl* request)
{
    int Motor_i,i;
    int temp;
    for (i=0;i<MAX_THREAD_MOTORS_NUM;i++)
    {
        if (ThreadMotorIdToControlId[i] == request->hardwarepidcontroltype)
        {
            Motor_i = i;
            break;
        }
    }
    memcpy (&MotorsControl[Motor_i],request,sizeof(HardwarePidControl));
    if (MotorsControl[Motor_i].pvinputfilterfactormode > MAX_CONTROL_SAMPLES)
        MotorsControl[Motor_i].pvinputfilterfactormode = MAX_CONTROL_SAMPLES;
#ifdef TEST_LONGER_PID_THREAD
    MotorsControl[Motor_i].pvinputfilterfactormode = 10; //test longer control
#endif
    for (i = 0;i < (int)MotorsControl[Motor_i].pvinputfilterfactormode; i++)
    {
        MotorSamples[Motor_i][i] = 0;  //reset the samples value for control beginning
        MotorSpeedSamples[Motor_i][i] = 0;
    }
    NormalizedErrorCoEfficient[Motor_i] = (2*PI*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].armlength);
    temp = 1<<(DancersCfg[ThreadMotorIdToDancerId[Motor_i]].resolutionbits);
    temp=(NORMAL_COEF_DIVIDER*(temp-1)*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].maximalmovementmm);
    NormalizedErrorCoEfficient[Motor_i] = NormalizedErrorCoEfficient[Motor_i] / temp;
//    uint32_t MotorSamples[MAX_THREAD_MOTORS_NUM][MAX_CONTROL_SAMPLES];
    temp = 1<<(DancersCfg[ThreadMotorIdToDancerId[Motor_i]].resolutionbits);
    temp = (temp*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].maximalmovementmm);//*3/2);
    if (Motor_i == WINDER_MOTOR)
    {
        temp = temp*3/2;
    }
    DancerStopActivityLimit[Motor_i] = temp/(2*PI*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].armlength);
#ifdef FOUR_WINDERS
    if (Motor_i == WINDER_MOTOR)
    {
        int j,winderMotorId;
        for (j=0;j<3;j++)
        {
            winderMotorId = j+WINDER_2_MOTOR;
            memcpy (&MotorsControl[winderMotorId],request,sizeof(HardwarePidControl));
            if (MotorsControl[winderMotorId].pvinputfilterfactormode > MAX_CONTROL_SAMPLES)
                MotorsControl[winderMotorId].pvinputfilterfactormode = MAX_CONTROL_SAMPLES;
        #ifdef TEST_LONGER_PID_THREAD
            MotorsControl[Motor_i].pvinputfilterfactormode = 10; //test longer control
        #endif
            for (i = 0;i < (int)MotorsControl[winderMotorId].pvinputfilterfactormode; i++)
            {
                MotorSamples[winderMotorId][i] = 0;  //reset the samples value for control beginning
                MotorSpeedSamples[winderMotorId][i] = 0;
            }
            NormalizedErrorCoEfficient[winderMotorId] = (2*PI*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].armlength);
            temp = 1<<(DancersCfg[ThreadMotorIdToDancerId[Motor_i]].resolutionbits);
            temp=(NORMAL_COEF_DIVIDER*(temp-1)*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].maximalmovementmm);
            NormalizedErrorCoEfficient[winderMotorId] = NormalizedErrorCoEfficient[winderMotorId] / temp;
        //    uint32_t MotorSamples[MAX_THREAD_MOTORS_NUM][MAX_CONTROL_SAMPLES];
            temp = 1<<(DancersCfg[ThreadMotorIdToDancerId[Motor_i]].resolutionbits);
            temp = (temp*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].maximalmovementmm);//*3/2);
            if (Motor_i == WINDER_MOTOR)
            {
                temp = temp*3/2;
            }
            DancerStopActivityLimit[winderMotorId] = temp/(2*PI*DancersCfg[ThreadMotorIdToDancerId[Motor_i]].armlength);
        }
    }
#endif
    return OK;
}
char DancerConfigPath[50] = "0://SysInfo//DancCfg.cfg";

uint32_t StoreDancerConfigMessage()
{
    uint32_t status = OK;
  //  FRESULT Fresult = FR_OK;
    //HardwareConfiguration DancerConfig;
    HardwareDancer Dancers[MAX_SYSTEM_DANCERS];
  //  uint8_t* response_buffer;
  //  size_t response_size = 0;
    int Dancer_i;

    //hardware_configuration__init(&DancerConfig);
    //DancerConfig.dancers = (HardwareDancer**)my_malloc(sizeof(HardwareDancer*)*MAX_SYSTEM_DANCERS);
    for (Dancer_i = 0; Dancer_i < MAX_SYSTEM_DANCERS; Dancer_i++)
    {
        hardware_dancer__init(&Dancers[Dancer_i]);
        //DancerConfig.dancers[Dancer_i] = &Dancers[Dancer_i];
        Dancers[Dancer_i].has_zeropoint = true;
        Dancers[Dancer_i].hardwaredancertype = Dancer_i;
        Dancers[Dancer_i].has_hardwaredancertype = true;
        Dancers[Dancer_i].zeropoint=Control_Read_Dancer_Position(Dancer_i,0);
        //DancerConfig.n_dancers++;
        DancersCfg[Dancer_i].zeropoint = Dancers[Dancer_i].zeropoint;
        DancersCfg[Dancer_i].zeropoint = Control_Read_Dancer_Position(Dancer_i,0);
    }

    status |= MCU_E2PromProgram(EEPROM_STORAGE_DANCER_0,DancersCfg[0].zeropoint);
    status |= MCU_E2PromProgram(EEPROM_STORAGE_DANCER_1,DancersCfg[1].zeropoint);
    status |= MCU_E2PromProgram(EEPROM_STORAGE_DANCER_2,DancersCfg[2].zeropoint);
    Report("~~~~~~Store eeprom 0",__FILE__,DancersCfg[0].zeropoint,(int)DancersCfg[1].zeropoint,RpWarning,(int)DancersCfg[2].zeropoint,0);
#ifdef FOUR_WINDERS
    status |= MCU_E2PromProgram(EEPROM_STORAGE_DANCER_3,DancersCfg[HARDWARE_DANCER_3].zeropoint);
    status |= MCU_E2PromProgram(EEPROM_STORAGE_DANCER_4,DancersCfg[HARDWARE_DANCER_4].zeropoint);
    Report("~~~~~~Store eeprom 1",__FILE__,__LINE__,(int)DancersCfg[HARDWARE_DANCER_3].zeropoint,RpWarning,(int)DancersCfg[HARDWARE_DANCER_4].zeropoint,0);
#endif
    /*
    response_buffer = my_malloc(hardware_configuration__get_packed_size(&DancerConfig));
    if (response_buffer)
    {
        response_size = hardware_configuration__pack(&DancerConfig, response_buffer);
    }
    Fresult = FileWrite(response_buffer,response_size,DancerConfigPath,BIOS_WAIT_FOREVER);
    EraseFlashSection(DANCERS_MAP_IN_FLASH,1024);
    for (Dancer_i = 0; Dancer_i < MAX_SYSTEM_DANCERS; Dancer_i++)
    {
        ReadAppAndProgram(DANCERS_MAP_IN_FLASH, sizeof(Dancers), Dancers);
    }


    my_free(response_buffer);
*/
    return status;
}
uint32_t LoadDancerConfigMessage()
{
    uint32_t status = OK;

    MCU_E2PromRead(EEPROM_STORAGE_DANCER_0,&DancersCfg[0].zeropoint);
    MCU_E2PromRead(EEPROM_STORAGE_DANCER_1,&DancersCfg[1].zeropoint);
    MCU_E2PromRead(EEPROM_STORAGE_DANCER_2,&DancersCfg[2].zeropoint);
#ifdef FOUR_WINDERS
    MCU_E2PromRead(EEPROM_STORAGE_DANCER_3,&DancersCfg[3].zeropoint);
    MCU_E2PromRead(EEPROM_STORAGE_DANCER_4,&DancersCfg[4].zeropoint);
#endif

    status |= Report("Dancer 0 Store data eeprom ",__FILE__,__LINE__,0,RpWarning,(int)DancersCfg[0].zeropoint,0);
    status |= Report("Dancer 1 Store data eeprom ",__FILE__,__LINE__,1,RpWarning,(int)DancersCfg[1].zeropoint,0);
    status |= Report("Dancer 2 Store data eeprom ",__FILE__,__LINE__,2,RpWarning,(int)DancersCfg[2].zeropoint,0);
#ifdef FOUR_WINDERS
    status |= Report("Dancer 3 Store data eeprom ",__FILE__,__LINE__,3,RpWarning,(int)DancersCfg[3].zeropoint,0);
    status |= Report("Dancer 4 Store data eeprom ",__FILE__,__LINE__,4,RpWarning,(int)DancersCfg[4].zeropoint,0);
#endif

    return status;

}

uint32_t DancerConfigMessage(HardwareDancer * request)
{
    uint32_t status = PASSED;
    int Dancer_i;

    Dancer_i = request->hardwaredancertype;
    if (Dancer_i<MAX_SYSTEM_DANCERS )
    {
        memcpy (&DancersCfg[Dancer_i],request,sizeof(HardwareDancer));
        return status;
    }
    else
        return Dancer_i;

}
uint32_t ThreadConfigBreakSensor(void *request)
{
    HardwareBreakSensor  *SensorCfg = (HardwareBreakSensor*)request;
    if (SensorCfg)
    {
        BreakSensorenabled = SensorCfg->enabled;
        if (SensorCfg->debouncetimemilli)
        {
            BreakSensordebouncetimemilli = SensorCfg->debouncetimemilli;
        }
        return OK;
    }
    return ERROR;
}
uint32_t thread_init(void)
{
    //memset (MotorsCfg,0,sizeof(MotorsCfg));
    //memset (&InternalWinderCfg,0,sizeof(InternalWinderConfigStruc));

    return OK;
}
void ThreadSetBreakSensorLimit(int limit)
{
    if (limit)
        BreakSensordebouncetimemilli = limit;
}