欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

WPF開發(fā)之實(shí)現(xiàn)一種三軸機(jī)械手控件

 更新時(shí)間:2023年01月31日 09:53:13   作者:一團(tuán)靜火  
這篇文章主要為大家詳細(xì)介紹了如何利用WPF實(shí)現(xiàn)簡(jiǎn)單一種三軸機(jī)械手控件,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)或工作有一定幫助,感興趣的小伙伴可以了解一下

一 引入

考慮實(shí)現(xiàn)一種三軸機(jī)器人控件。

三軸機(jī)器人用來(lái)將某種工件從一個(gè)位置運(yùn)送到另一個(gè)位置。

其X軸為手臂軸,可以正向和反向運(yùn)動(dòng),它處于末端,直接接觸工件;

其T軸為旋轉(zhuǎn)軸,可以對(duì)手臂進(jìn)行旋轉(zhuǎn);

其Z軸為升降軸,可以對(duì)手臂和旋轉(zhuǎn)部分進(jìn)行升降。

二 RobotControl

定義出機(jī)器人的軸動(dòng)作枚舉,軸的動(dòng)作分為回原點(diǎn),正向運(yùn)動(dòng),反向運(yùn)動(dòng)。

public enum WaferRobotZAction
{
    Z_Origin,
    Z_CW,
    Z_CCW
}

public enum WaferRobotXAction
{
    X_Origin,
    X_CW,
    X_CCW
}

public enum WaferRobotTAction
{
    T_Origin,
    T_CW,
    T_CCW
}

聲明一個(gè)WaferRobotControl的自定義控件,它繼承自Control類。

定義一個(gè)Wafer屬性來(lái)表示W(wǎng)aferRobot上的工件。

定義表示X軸動(dòng)作、T軸動(dòng)作和Z軸動(dòng)作的依賴屬性,它可以被實(shí)際的業(yè)務(wù)數(shù)據(jù)源綁定。

當(dāng)實(shí)際的業(yè)務(wù)數(shù)據(jù)發(fā)生改變時(shí),軸動(dòng)作屬性相應(yīng)改變,并VisualStateManager來(lái)轉(zhuǎn)換控件的狀態(tài),以觸發(fā)樣式模板中的動(dòng)畫。

public class WaferRobotControl : Control
{
    static WaferRobotControl()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(WaferRobotControl), new FrameworkPropertyMetadata(typeof(WaferRobotControl)));
    }

    public static readonly DependencyProperty WaferProperty = DependencyProperty.Register("Wafer", typeof(int), typeof(WaferRobotControl));
    public int Wafer { get => (int)GetValue(WaferProperty); set => SetValue(WaferProperty, value); }

    public static readonly DependencyProperty RobotZActionProperty = DependencyProperty.Register(
       "RobotZAction",
       typeof(WaferRobotZAction),
       typeof(WaferRobotControl),
       new PropertyMetadata(WaferRobotZAction.Z_Origin, RobotZActionPropertyChangedCallback));

    public WaferRobotZAction RobotZAction
    {
        get => (WaferRobotZAction)GetValue(RobotZActionProperty);
        set => SetValue(RobotZActionProperty, value);
    }

    private static void RobotZActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var control = d as WaferRobotControl;
        var oldAct = (WaferRobotZAction)e.OldValue;
        var newAct = (WaferRobotZAction)e.NewValue;
        switch (newAct)
        {
            case WaferRobotZAction.Z_Origin:
                VisualStateManager.GoToState(control, newAct.ToString(), true);
                break;
            case WaferRobotZAction.Z_CW:
                if (newAct != oldAct)
                {
                    VisualStateManager.GoToState(control, newAct.ToString(), true);
                }
                break;
            case WaferRobotZAction.Z_CCW:
                if (newAct != oldAct)
                {
                    VisualStateManager.GoToState(control, newAct.ToString(), true);
                }
                break;
            default:
                break;
        }
    }

    public static readonly DependencyProperty RobotXActionProperty = DependencyProperty.Register(
        "RobotXAction",
        typeof(WaferRobotXAction),
        typeof(WaferRobotControl),
        new PropertyMetadata(WaferRobotXAction.X_Origin, RobotXActionPropertyChangedCallback));
    public WaferRobotXAction RobotXAction
    {
        get => (WaferRobotXAction)GetValue(RobotXActionProperty);
        set => SetValue(RobotXActionProperty, value);
    }

    private static void RobotXActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var control = d as WaferRobotControl;
        var oldAct = (WaferRobotXAction)e.OldValue;
        var newAct = (WaferRobotXAction)e.NewValue;
        switch (newAct)
        {
            case WaferRobotXAction.X_Origin:
                VisualStateManager.GoToState(control, newAct.ToString(), true);
                break;
            case WaferRobotXAction.X_CW:
                if (newAct != oldAct)
                {
                    VisualStateManager.GoToState(control, newAct.ToString(), true);
                }
                break;
            case WaferRobotXAction.X_CCW:
                if (newAct != oldAct)
                {
                    VisualStateManager.GoToState(control, newAct.ToString(), true);
                }
                break;
            default:
                break;
        }
    }

    public static readonly DependencyProperty RobotTActionProperty = DependencyProperty.Register(
        "RobotTAction",
        typeof(WaferRobotTAction),
        typeof(WaferRobotControl),
        new PropertyMetadata(WaferRobotTAction.T_Origin, RobotTActionPropertyChangedCallback));

    public WaferRobotTAction RobotTAction
    {
        get => (WaferRobotTAction)GetValue(RobotTActionProperty);
        set => SetValue(RobotTActionProperty, value);
    }

    private static void RobotTActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var control = d as WaferRobotControl;
        var oldAct = (WaferRobotTAction)e.OldValue;
        var newAct = (WaferRobotTAction)e.NewValue;
        switch (newAct)
        {
            case WaferRobotTAction.T_Origin:
                VisualStateManager.GoToState(control, newAct.ToString(), true);
                break;
            case WaferRobotTAction.T_CW:
                if (newAct != oldAct)
                {
                    VisualStateManager.GoToState(control, newAct.ToString(), true);
                }
                break;
            case WaferRobotTAction.T_CCW:
                if (newAct != oldAct)
                {
                    VisualStateManager.GoToState(control, newAct.ToString(), true);
                }
                break;
            default:
                break;
        }
    }

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
        VisualStateManager.GoToState(this, WaferRobotZAction.Z_Origin.ToString(), true);
        VisualStateManager.GoToState(this, WaferRobotXAction.X_Origin.ToString(), true);
        VisualStateManager.GoToState(this, WaferRobotTAction.T_Origin.ToString(), true);
    }
}

三 Style

控件模板的實(shí)現(xiàn)思路。

將機(jī)器人的樣式分為三部分,不動(dòng)的底座部分,Z軸部分,包含T軸和X軸的手臂部分。

VisualStateGroup中定義出軸動(dòng)作的VisualState,編寫轉(zhuǎn)換動(dòng)畫。

<SolidColorBrush x:Key="robotBorderBrush" Color="#030303" />
<Style TargetType="{x:Type local:WaferRobotControl}" >
    <Setter Property="Cursor" Value="Hand" />
    <Setter Property="Width" Value="200"/>
    <Setter Property="Height" Value="300"/>
    <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:WaferRobotControl}">
                    <Viewbox x:Name="viewbox" Stretch="Fill">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup Name="RobotActions">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition To="Z_CW">
                                        <Storyboard FillBehavior="HoldEnd">
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotZAct" Storyboard.TargetProperty="Y">
                                                <LinearDoubleKeyFrame Value="-90" KeyTime="0:0:1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotUpDownAct" Storyboard.TargetProperty="Y">
                                                <LinearDoubleKeyFrame Value="-90" KeyTime="0:0:1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualTransition>
                                    <VisualTransition To="Z_CCW">
                                        <Storyboard FillBehavior="HoldEnd">
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotZAct" Storyboard.TargetProperty="Y">
                                                <LinearDoubleKeyFrame Value="0" KeyTime="0:0:1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotUpDownAct" Storyboard.TargetProperty="Y">
                                                <LinearDoubleKeyFrame Value="0" KeyTime="0:0:1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualTransition>
                                </VisualStateGroup.Transitions>
                                <VisualState Name="Z_Origin">
                                    <Storyboard FillBehavior="HoldEnd">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotZAct" Storyboard.TargetProperty="Y" >
                                            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotUpDownAct" Storyboard.TargetProperty="Y" >
                                            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState Name="Z_CW">
                                    <Storyboard  FillBehavior="HoldEnd">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotZAct" Storyboard.TargetProperty="Y" Duration="0" >
                                            <LinearDoubleKeyFrame Value="-90" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotUpDownAct" Storyboard.TargetProperty="Y" >
                                            <LinearDoubleKeyFrame Value="-90" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState Name="Z_CCW">
                                    <Storyboard FillBehavior="HoldEnd">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotZAct" Storyboard.TargetProperty="Y" >
                                            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotUpDownAct" Storyboard.TargetProperty="Y" >
                                            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>

                            <VisualStateGroup Name="RobotXActions">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition To="X_CW">
                                        <Storyboard FillBehavior="HoldEnd" SpeedRatio="6">
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="armXT1RotateAct" Storyboard.TargetProperty="Angle">
                                                <LinearDoubleKeyFrame Value="90" KeyTime="0:0:0"/>
                                                <LinearDoubleKeyFrame Value="0" KeyTime="0:0:9"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="armXT2ArmRotateAct" Storyboard.TargetProperty="Angle">
                                                <LinearDoubleKeyFrame Value="-90" KeyTime="0:0:0"/>
                                                <LinearDoubleKeyFrame Value="0" KeyTime="0:0:9"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="armXT2Act" Storyboard.TargetProperty="X">
                                                <LinearDoubleKeyFrame Value="0" KeyTime="0:0:9"/>
                                                <LinearDoubleKeyFrame Value="2.126" KeyTime="0:0:8"/>
                                                <LinearDoubleKeyFrame Value="8.443" KeyTime="0:0:7"/>
                                                <LinearDoubleKeyFrame Value="18.756" KeyTime="0:0:6"/>
                                                <LinearDoubleKeyFrame Value="32.753" KeyTime="0:0:5"/>
                                                <LinearDoubleKeyFrame Value="50.009" KeyTime="0:0:4"/>
                                                <LinearDoubleKeyFrame Value="70" KeyTime="0:0:3"/>
                                                <LinearDoubleKeyFrame Value="92.117" KeyTime="0:0:2"/>
                                                <LinearDoubleKeyFrame Value="115.689" KeyTime="0:0:1"/>
                                                <LinearDoubleKeyFrame Value="140" KeyTime="0:0:0"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualTransition>
                                    <VisualTransition To="X_CCW">
                                        <Storyboard FillBehavior="HoldEnd" SpeedRatio="6">
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="armXT1RotateAct" Storyboard.TargetProperty="Angle">
                                                <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
                                                <LinearDoubleKeyFrame Value="90" KeyTime="0:0:9"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="armXT2ArmRotateAct" Storyboard.TargetProperty="Angle">
                                                <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
                                                <LinearDoubleKeyFrame Value="-90" KeyTime="0:0:9"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="armXT2Act" Storyboard.TargetProperty="X">
                                                <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
                                                <LinearDoubleKeyFrame Value="2.126" KeyTime="0:0:1"/>
                                                <LinearDoubleKeyFrame Value="8.443" KeyTime="0:0:2"/>
                                                <LinearDoubleKeyFrame Value="18.756" KeyTime="0:0:3"/>
                                                <LinearDoubleKeyFrame Value="32.753" KeyTime="0:0:4"/>
                                                <LinearDoubleKeyFrame Value="50.009" KeyTime="0:0:5"/>
                                                <LinearDoubleKeyFrame Value="70" KeyTime="0:0:6"/>
                                                <LinearDoubleKeyFrame Value="92.117" KeyTime="0:0:7"/>
                                                <LinearDoubleKeyFrame Value="115.689" KeyTime="0:0:8"/>
                                                <LinearDoubleKeyFrame Value="140" KeyTime="0:0:9"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualTransition>
                                </VisualStateGroup.Transitions>

                                <VisualState Name="X_Origin">
                                    <Storyboard FillBehavior="HoldEnd">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="armXT1RotateAct" Storyboard.TargetProperty="Angle">
                                            <LinearDoubleKeyFrame Value="90" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="armXT2ArmRotateAct" Storyboard.TargetProperty="Angle">
                                            <LinearDoubleKeyFrame Value="-90" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="armXT2Act" Storyboard.TargetProperty="X">
                                            <LinearDoubleKeyFrame Value="140" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>

                                <VisualState Name="X_CW">
                                    <Storyboard FillBehavior="HoldEnd">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="armXT1RotateAct" Storyboard.TargetProperty="Angle">
                                            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="armXT2ArmRotateAct" Storyboard.TargetProperty="Angle">
                                            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="armXT2Act" Storyboard.TargetProperty="X">
                                            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState Name="X_CCW">
                                    <Storyboard FillBehavior="HoldEnd">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="armXT1RotateAct" Storyboard.TargetProperty="Angle">
                                            <LinearDoubleKeyFrame Value="90" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="armXT2ArmRotateAct" Storyboard.TargetProperty="Angle">
                                            <LinearDoubleKeyFrame Value="-90" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="armXT2Act" Storyboard.TargetProperty="X">
                                            <LinearDoubleKeyFrame Value="140" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>

                            <VisualStateGroup Name="RobotTActions">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition To="T_Origin">
                                        <Storyboard FillBehavior="HoldEnd">
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotRotateAct" Storyboard.TargetProperty="Angle">
                                                <LinearDoubleKeyFrame Value="90" KeyTime="0:0:1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualTransition>
                                    <VisualTransition To="T_CW">
                                        <Storyboard FillBehavior="HoldEnd">
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotRotateAct" Storyboard.TargetProperty="Angle">
                                                <LinearDoubleKeyFrame Value="180" KeyTime="0:0:1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualTransition>
                                    <VisualTransition To="T_CCW">
                                        <Storyboard FillBehavior="HoldEnd">
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotRotateAct" Storyboard.TargetProperty="Angle">
                                                <LinearDoubleKeyFrame Value="0" KeyTime="0:0:1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualTransition>
                                </VisualStateGroup.Transitions>

                                <VisualState Name="T_Origin">
                                    <Storyboard FillBehavior="HoldEnd">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotRotateAct" Storyboard.TargetProperty="Angle">
                                            <LinearDoubleKeyFrame Value="90" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState Name="T_CCW">
                                    <Storyboard FillBehavior="HoldEnd">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotRotateAct" Storyboard.TargetProperty="Angle">
                                            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState Name="T_CW">
                                    <Storyboard FillBehavior="HoldEnd">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotRotateAct" Storyboard.TargetProperty="Angle">
                                            <LinearDoubleKeyFrame Value="180" KeyTime="0:0:0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Canvas Width="200" Height="300" >
                            <Canvas x:Name="robotZ" Width="40" Height="120" Canvas.Top="170" Canvas.Left="80" >
                                <Canvas.RenderTransform>
                                    <TransformGroup>
                                        <TranslateTransform x:Name="robotZAct"></TranslateTransform>
                                    </TransformGroup>
                                </Canvas.RenderTransform>
                                <Path Stroke="#030303" StrokeStartLineCap="Round" StrokeEndLineCap="Round">
                                    <Path.Fill>
                                        <LinearGradientBrush  EndPoint="1,0.5" StartPoint="0,0.5">
                                            <GradientStop Color="#6B696A" Offset="0" />
                                            <GradientStop Color="#6B696A" Offset="1" />
                                            <GradientStop Color="#A1A7BE" Offset="0.5" />
                                        </LinearGradientBrush>
                                    </Path.Fill>
                                    <Path.Data>
                                        <PathGeometry>
                                            <PathFigure StartPoint="0 20" IsClosed="True">
                                                <LineSegment Point="0 2"/>
                                                <LineSegment Point="2 2"/>
                                                <LineSegment Point="5 5"/>
                                                <LineSegment Point="35 5" />
                                                <LineSegment Point="38 2"/>
                                                <LineSegment Point="40 2"/>
                                                <LineSegment Point="40 20" />
                                                <LineSegment Point="0 20" />
                                            </PathFigure>

                                            <PathFigure StartPoint="4 20" >
                                                <LineSegment Point="4 24"/>
                                                <LineSegment Point="36 24" />
                                                <LineSegment Point="36 20"/>
                                            </PathFigure>

                                            <PathFigure StartPoint="4 24" >
                                                <LineSegment Point="2 24"/>
                                                <LineSegment Point="2 28"/>
                                                <LineSegment Point="4 28"/>
                                                <LineSegment Point="36 28" />
                                                <LineSegment Point="38 28" />
                                                <LineSegment Point="38 24"/>
                                                <LineSegment Point="36 24"/>
                                            </PathFigure>
                                        </PathGeometry>
                                    </Path.Data>
                                </Path>
                                <Path Stroke="#030303"  StrokeStartLineCap="Round" StrokeEndLineCap="Round">
                                    <Path.Fill>
                                        <LinearGradientBrush  EndPoint="1,0.5" StartPoint="0,0.5">
                                            <GradientStop Color="#6B696A" Offset="0" />
                                            <GradientStop Color="#6B696A" Offset="1" />
                                            <GradientStop Color="#A1A7BE" Offset="0.5" />
                                        </LinearGradientBrush>
                                    </Path.Fill>
                                    <Path.Data>
                                        <PathGeometry>
                                            <PathFigure StartPoint="2 28.5" >
                                                <LineSegment Point="2 120"/>
                                                <LineSegment Point="38 120"/>
                                                <LineSegment Point="38 28.5"/>
                                            </PathFigure>
                                        </PathGeometry>
                                    </Path.Data>
                                </Path>
                            </Canvas>

                            <Canvas x:Name="dizuo" Width="80" Height="100" Canvas.Top="200" Canvas.Left="60">
                                <Path  Stroke="#030303" Fill="#A1A7BE" >
                                    <Path.Data>
                                        <PathGeometry>
                                            <PathFigure StartPoint="0 0" IsClosed="True">
                                                <LineSegment Point="20 0"/>
                                                <LineSegment Point="20 92"/>
                                                <LineSegment Point="0 92"/>
                                            </PathFigure>
                                            <PathFigure StartPoint="0 92" IsClosed="True">
                                                <LineSegment Point="12 92"/>
                                                <LineSegment Point="12 100"/>
                                                <LineSegment Point="0 100"/>
                                            </PathFigure>
                                        </PathGeometry>
                                    </Path.Data>
                                </Path>
                                <Path  Stroke="#030303" Fill="#7A7E90"  Canvas.Left="20">
                                    <Path.Data>
                                        <PathGeometry>
                                            <PathFigure StartPoint="0 0" IsClosed="True">
                                                <LineSegment Point="40 0"/>
                                                <LineSegment Point="40 92"/>
                                                <LineSegment Point="0 92"/>
                                            </PathFigure>
                                            <PathFigure StartPoint="0 92" IsClosed="True">
                                                <LineSegment Point="-8 92"/>
                                                <LineSegment Point="-8 100"/>
                                                <LineSegment Point="48 100"/>
                                                <LineSegment Point="48 92"/>
                                            </PathFigure>
                                        </PathGeometry>
                                    </Path.Data>
                                </Path>
                                <Path  Stroke="#030303" Fill="#585368" Canvas.Left="60">
                                    <Path.Data>
                                        <PathGeometry>
                                            <PathFigure StartPoint="0 0" IsClosed="True">
                                                <LineSegment Point="20 0"/>
                                                <LineSegment Point="20 92"/>
                                                <LineSegment Point="0 92"/>
                                            </PathFigure>
                                            <PathFigure StartPoint="8 92" IsClosed="True">
                                                <LineSegment Point="20 92"/>
                                                <LineSegment Point="20 100"/>
                                                <LineSegment Point="8 100"/>
                                            </PathFigure>
                                        </PathGeometry>
                                    </Path.Data>
                                </Path>
                            </Canvas>

                            <Canvas x:Name="robot" Width="100" Height="150" RenderTransformOrigin="1 1" >
                                <Canvas.RenderTransform>
                                    <TransformGroup>
                                        <RotateTransform  x:Name="robotRotateAct"/>
                                        <TranslateTransform  x:Name="robotUpDownAct"></TranslateTransform>
                                    </TransformGroup>
                                </Canvas.RenderTransform>
                                <Canvas x:Name="armXT1" Width="200" Height="100"  Canvas.Top="100" RenderTransformOrigin="0.5 0.5">
                                    <Canvas.RenderTransform>
                                        <RotateTransform  x:Name="armXT1RotateAct"/>
                                    </Canvas.RenderTransform>

                                    <Canvas x:Name="armXT1Arm" Width="70" Height="30"  Canvas.Left="30" Canvas.Top="35" RenderTransformOrigin="1 0.5">
                                        <Path  Stroke="{StaticResource robotBorderBrush}" Fill="#FF7F50" StrokeThickness="1" StrokeEndLineCap="Round" >
                                            <Path.Data>
                                                <PathGeometry>
                                                    <PathFigure StartPoint="0 5" IsClosed="True">
                                                        <LineSegment Point="51 0"/>
                                                        <LineSegment Point="51 30" IsStroked="False"/>
                                                        <LineSegment Point="0 25"/>
                                                        <LineSegment Point="0 5" IsStroked="False"/>
                                                    </PathFigure>
                                                </PathGeometry>
                                            </Path.Data>
                                        </Path>
                                        <Path Stroke="{StaticResource robotBorderBrush}" StrokeThickness="1" Canvas.Left="0" 
                                                StrokeEndLineCap="Round" StrokeStartLineCap="Round" Fill="#FF7F50"
                                                Data="M 0,5 A 10,10 0 0 0 0,25">
                                        </Path>
                                    </Canvas>

                                    <Canvas x:Name="armXT1Center"  Width="40" Height="40" Canvas.Left="80" Canvas.Top="30" >
                                        <Path  Stroke="{StaticResource robotBorderBrush}"  Fill="#FF7F50" StrokeThickness="1" StrokeEndLineCap="Round"  >
                                            <Path.Data>
                                                <PathGeometry>
                                                    <PathFigure StartPoint="0 6" IsClosed="True">
                                                        <LineSegment Point="6 0"/>
                                                        <LineSegment Point="34 0"/>
                                                        <LineSegment Point="40 6"/>
                                                        <LineSegment Point="40 34"/>
                                                        <LineSegment Point="34 40"/>
                                                        <LineSegment Point="6 40"/>
                                                        <LineSegment Point="0 34"/>
                                                    </PathFigure>
                                                </PathGeometry>
                                            </Path.Data>
                                        </Path>
                                    </Canvas>
                                </Canvas>

                                <Canvas x:Name="armXT2" Width="120" Height="40" Canvas.Left="-90" Canvas.Top="130">
                                    <Canvas.RenderTransform>
                                        <TransformGroup>
                                            <TranslateTransform x:Name="armXT2Act"></TranslateTransform>
                                        </TransformGroup>
                                    </Canvas.RenderTransform>
                                    <Canvas x:Name="armXT2Arm" Width="70" Height="20"  Canvas.Left="50" Canvas.Top="10" RenderTransformOrigin="0 0.5" Background="#6495ED">
                                        <Canvas.RenderTransform>
                                            <RotateTransform x:Name="armXT2ArmRotateAct"/>
                                        </Canvas.RenderTransform>
                                        <Path Stroke="{StaticResource robotBorderBrush}" StrokeThickness="1" Canvas.Left="70" 
                                        StrokeEndLineCap="Round" StrokeStartLineCap="Round" Fill="#6495ED"
                                        Data="M 0,0 A 10,10 0 0 1 0,20">
                                        </Path>
                                        <Path Stroke="{StaticResource robotBorderBrush}" StrokeThickness="1" Canvas.Left="0" 
                                        StrokeEndLineCap="Round" StrokeStartLineCap="Round" Fill="#6495ED"
                                        Data="M 0,0 A 10,10 0 0 0 0,20">
                                        </Path>

                                        <Path  Stroke="{StaticResource robotBorderBrush}" Fill="#6495ED" StrokeThickness="1" StrokeEndLineCap="Round" >
                                            <Path.Data>
                                                <PathGeometry>
                                                    <PathFigure StartPoint="70 0" >
                                                        <LineSegment Point="0 0" />
                                                        <LineSegment Point="0 20" IsStroked="False"/>
                                                        <LineSegment Point="70 20"/>
                                                        <LineSegment Point="70 0" IsStroked="False"/>
                                                    </PathFigure>
                                                </PathGeometry>
                                            </Path.Data>
                                        </Path>
                                        <Ellipse Width="12" Height="12" Stroke="#030303" StrokeThickness="2"  Fill="Transparent" 
                                             Canvas.Top="4" Canvas.Left="62"/>
                                    </Canvas>

                                    <Canvas x:Name="armGripper" Height="40" Width="50"  Canvas.Left="0" Canvas.Top="0">
                                        <Path  Stroke="{StaticResource robotBorderBrush}"  StrokeThickness="2" StrokeEndLineCap="Round" >
                                            <Path.Data>
                                                <PathGeometry>
                                                    <PathFigure StartPoint="30 14" >
                                                        <LineSegment Point="10 14" />
                                                        <LineSegment Point="4 8" />
                                                        <LineSegment Point="-6 8" />
                                                    </PathFigure>

                                                    <PathFigure StartPoint="30 26" >
                                                        <LineSegment Point="10 26" />
                                                        <LineSegment Point="4 32" />
                                                        <LineSegment Point="-6 32" />
                                                    </PathFigure>
                                                </PathGeometry>
                                            </Path.Data>
                                        </Path>
                                        <Path  Stroke="{StaticResource robotBorderBrush}" Fill="#7A7E90"  StrokeThickness="1" StrokeEndLineCap="Round" >
                                            <Path.Data>
                                                <PathGeometry>
                                                    <PathFigure StartPoint="40 0" >
                                                        <LineSegment Point="60 0" />
                                                        <LineSegment Point="60 40" />
                                                        <LineSegment Point="40 40" />
                                                        <LineSegment Point="30 30" />
                                                        <LineSegment Point="30 10" />
                                                        <LineSegment Point="40 0" />
                                                    </PathFigure>
                                                </PathGeometry>
                                            </Path.Data>
                                        </Path>
                                        <Path  Stroke="{StaticResource robotBorderBrush}" Fill="#7A7E90" StrokeThickness="1" StrokeEndLineCap="Round" >
                                            <Path.Data>
                                                <PathGeometry>
                                                    <PathFigure StartPoint="30 10" >
                                                        <LineSegment Point="20 10" />
                                                        <LineSegment Point="20 30" />
                                                        <LineSegment Point="30 30" />
                                                        <LineSegment Point="30 10" IsStroked="False"/>
                                                    </PathFigure>
                                                </PathGeometry>
                                            </Path.Data>
                                        </Path>

                                        <Ellipse Width="12" Height="12" Stroke="#030303" StrokeThickness="2"  Fill="Transparent" 
                                             Canvas.Top="14" Canvas.Left="44"/>
                                        <Ellipse x:Name="wafer" Width="40" Height="40" StrokeThickness="1" Stroke="Black"  Canvas.Left="-24"
                                                 Visibility="{Binding Wafer,Converter={StaticResource WaferIntToVisibilityConverter},
                                                    RelativeSource={RelativeSource TemplatedParent}}"
                                                 Fill="{Binding Wafer,Converter={StaticResource WaferIntToColorConverter},
                                                     RelativeSource={RelativeSource TemplatedParent}}"/>
                                    </Canvas>
                                </Canvas>
                            </Canvas>
                        </Canvas>
                    </Viewbox>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
</Style>

四 效果演示

界面代碼如下:

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:wpfapp1="clr-namespace:WpfApp1"
        mc:Ignorable="d" Background="WhiteSmoke"
        Title="MainWindow" Height="800" Width="1200">
    <Canvas>
        <wpfapp1:WaferRobotControl Canvas.Left="472" Canvas.Top="171" x:Name="robot"/>
        <Button Content="Z CW" Canvas.Left="757" Canvas.Top="338" Width="60" Height="30" Click="ZCWButton_Click"   />
        <Button Content="Z CCW" Canvas.Left="757" Canvas.Top="388" Width="60" Height="30" Click="ZCCWButton_Click"/>
        <Button Content="X CW" Canvas.Left="838" Canvas.Top="338" Width="60" Height="30" Click="XCWButton_Click"/>
        <Button Content="X CCW" Canvas.Left="838" Canvas.Top="389" Width="60" Height="30" Click="XCCWButton_Click"/>
        <Button Content="T CW" Canvas.Left="919" Canvas.Top="338" Width="60" Height="30" Click="TCWButton_Click"/>
        <Button Content="T CCW" Canvas.Left="919" Canvas.Top="389" Width="60" Height="30" Click="TCCWButton_Click"/>
        <Button Content="Auto" Canvas.Left="757" Canvas.Top="439" Width="60" Height="30" Click="AutoButton_Click"/>
    </Canvas>
</Window>

后臺(tái)代碼如下:

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void ZCWButton_Click(object sender, RoutedEventArgs e)
        {
            robot.RobotZAction = WaferRobotZAction.Z_CW;
        }

        private void ZCCWButton_Click(object sender, RoutedEventArgs e)
        {
            robot.RobotZAction = WaferRobotZAction.Z_CCW;
        }

        private void XCWButton_Click(object sender, RoutedEventArgs e)
        {
            robot.RobotXAction = WaferRobotXAction.X_CW;
        }

        private void XCCWButton_Click(object sender, RoutedEventArgs e)
        {
            robot.RobotXAction = WaferRobotXAction.X_CCW;
        }

        private void TCWButton_Click(object sender, RoutedEventArgs e)
        {
            robot.RobotTAction = WaferRobotTAction.T_CW;
        }

        private void TCCWButton_Click(object sender, RoutedEventArgs e)
        {
            robot.RobotTAction = WaferRobotTAction.T_CCW;
        }

        private void AutoButton_Click(object sender, RoutedEventArgs e)
        {
            Task.Run(async () =>
            {
                Application.Current.Dispatcher?.Invoke
                (
                   () => { this.robot.RobotTAction = WaferRobotTAction.T_CCW; }
                );
                await Task.Delay(1000);

                Application.Current.Dispatcher?.Invoke
                (
                   () => { this.robot.RobotXAction = WaferRobotXAction.X_CW; }
                );
                await Task.Delay(2000);

                Application.Current.Dispatcher?.Invoke(
                    () => { this.robot.Wafer = 1; }
                    );
                await Task.Delay(200);

                Application.Current.Dispatcher?.Invoke(
                   () => { this.robot.RobotXAction = WaferRobotXAction.X_CCW; }
                   );
                await Task.Delay(2000);

                Application.Current.Dispatcher?.Invoke(
                 () => { this.robot.RobotZAction = WaferRobotZAction.Z_CW; }
                 );
                await Task.Delay(1000);

                Application.Current.Dispatcher?.Invoke
                (
                   () => { this.robot.RobotTAction = WaferRobotTAction.T_CW; }
                );
                await Task.Delay(1000);

                Application.Current.Dispatcher?.Invoke
                (
                 () => { this.robot.RobotXAction = WaferRobotXAction.X_CW; }
                );
                await Task.Delay(2000);

                Application.Current.Dispatcher?.Invoke(
                    () => { this.robot.Wafer = 0; }
                    );
                await Task.Delay(200);

                Application.Current.Dispatcher?.Invoke(
                 () => { this.robot.RobotXAction = WaferRobotXAction.X_CCW; }
                 );
                await Task.Delay(2000);
                Application.Current.Dispatcher?.Invoke
                (
                  () => { this.robot.RobotTAction = WaferRobotTAction.T_Origin; }
                );
                await Task.Delay(1000);
                Application.Current.Dispatcher?.Invoke
                (
                  () => { this.robot.RobotZAction = WaferRobotZAction.Z_CCW; }
                );
                await Task.Delay(1000);
            });
        }
    }

以上就是WPF開發(fā)之實(shí)現(xiàn)一種三軸機(jī)械手控件的詳細(xì)內(nèi)容,更多關(guān)于WPF三軸機(jī)械手控件的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • C#學(xué)習(xí)筆記整理_淺談Math類的方法

    C#學(xué)習(xí)筆記整理_淺談Math類的方法

    下面小編就為大家?guī)?lái)一篇C#學(xué)習(xí)筆記整理_淺談Math類的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-09-09
  • C#實(shí)現(xiàn)窗體中動(dòng)態(tài)按鈕的設(shè)計(jì)方法

    C#實(shí)現(xiàn)窗體中動(dòng)態(tài)按鈕的設(shè)計(jì)方法

    在窗體界面中,通常以按鈕來(lái)代替菜單欄的功能,這種形式雖然給用戶一種直觀、界面風(fēng)格各異的感覺,但通常按鈕都是以靜止的形式顯示,所以本文給大家介紹了C#實(shí)現(xiàn)窗體中動(dòng)態(tài)按鈕的設(shè)計(jì)方法,感興趣的朋友可以參考下
    2024-04-04
  • C#通過(guò)第三方組件生成二維碼(QR Code)和條形碼(Bar Code)

    C#通過(guò)第三方組件生成二維碼(QR Code)和條形碼(Bar Code)

    用C#如何生成二維碼,我們可以通過(guò)現(xiàn)有的第三方dll直接來(lái)實(shí)現(xiàn),下面列出幾種不同的生成方法
    2016-12-12
  • 配置C#的系統(tǒng)環(huán)境變量的方法

    配置C#的系統(tǒng)環(huán)境變量的方法

    配置C#的系統(tǒng)環(huán)境變量的方法...
    2007-03-03
  • c# 實(shí)現(xiàn)RSA非對(duì)稱加密算法

    c# 實(shí)現(xiàn)RSA非對(duì)稱加密算法

    RSA解決了對(duì)稱加密的一個(gè)不足,比如AES算法加密和解密時(shí)使用的是同一個(gè)秘鑰,因此這個(gè)秘鑰不能公開,因此對(duì)于需要公開秘鑰的場(chǎng)合,我們需要在加密和解密過(guò)程中使用不同的秘鑰,加密使用的公鑰可以公開,解密使用的私鑰要保密,這就是非對(duì)稱加密的好處。 
    2021-06-06
  • C# 數(shù)據(jù)庫(kù)鏈接字符串加密解密工具代碼詳解

    C# 數(shù)據(jù)庫(kù)鏈接字符串加密解密工具代碼詳解

    本文通過(guò)代碼給大家介紹C# 數(shù)據(jù)庫(kù)鏈接字符串加密解密工具的相關(guān)知識(shí),實(shí)現(xiàn)思路大概是使用兩個(gè)數(shù)對(duì)連接字符串進(jìn)行加密,再用這兩個(gè)數(shù)進(jìn)行解密,具體詳細(xì)代碼,大家參考下本文
    2018-05-05
  • C#開發(fā)WinForm之DataGridView開發(fā)詳解

    C#開發(fā)WinForm之DataGridView開發(fā)詳解

    這篇文章主要介紹了C#開發(fā)WinForm之DataGridView開發(fā)詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • C#配置文件設(shè)置及應(yīng)用詳解

    C#配置文件設(shè)置及應(yīng)用詳解

    在軟件開發(fā)過(guò)程中,配置文件是常用的一個(gè)功能,用于在程序運(yùn)行時(shí)調(diào)整應(yīng)用程序的行為,C# 提供了多種方式來(lái)創(chuàng)建和使用配置文件,本文將詳細(xì)介紹 C# 配置文件的創(chuàng)建、修改、讀取和寫入,以及跨平臺(tái)配置文件的應(yīng)用,需要的朋友可以參考下
    2024-06-06
  • C#實(shí)現(xiàn)圖像銳化的方法

    C#實(shí)現(xiàn)圖像銳化的方法

    這篇文章主要介紹了C#實(shí)現(xiàn)圖像銳化的方法,涉及C#操作圖像的相關(guān)技巧,需要的朋友可以參考下
    2015-04-04
  • c#實(shí)現(xiàn)ini文件讀寫類分享

    c#實(shí)現(xiàn)ini文件讀寫類分享

    c#實(shí)現(xiàn)ini文件讀寫類分享,大家參考使用吧
    2013-12-12

最新評(píng)論