CODESYS 瀹炴垬锛氳挋鐗瑰崱缃楁柟娉曡绠楀渾鍛ㄧ巼 螤-CODESYS璧勬簮涓嬭浇鍖-閰峰痉缃 - CoDeSys杞欢鏁欑▼涓嬭浇,CoDeSys宸ユ帶璧勮闂ㄦ埛
HSC6490-cn涓浗鍒堕狅紝涓浗鑺瘇
鏌ョ湅: 192|鍥炲: 0

CODESYS 瀹炴垬锛氳挋鐗瑰崱缃楁柟娉曡绠楀渾鍛ㄧ巼 螤

[澶嶅埗閾炬帴]
  • TA鐨勬瘡鏃ュ績鎯
    寮蹇
    2017-11-20 22:07
  • 绛惧埌澶╂暟: 2 澶

    [LV.1]鍒濇潵涔嶅埌

    鍙戣〃浜 2025-3-14 08:42:05 | 鏄剧ず鍏ㄩ儴妤煎眰 |闃呰妯″紡

    寮曡█

    鍦ㄥ伐涓氳嚜鍔ㄥ寲涓紝鎺屾彙CODESYS鐨勭粨鏋勫寲鏂囨湰锛圫T锛夎瑷鏄彁楂樼紪绋嬭兘鍔涚殑鍏抽敭銆傛湰鏂囧皢浠嬬粛濡備綍浣跨敤 CODESYS 缂栧啓涓涓▼搴忥紝閫氳繃钂欑壒鍗$綏鏂规硶杩戜技璁$畻鍦嗗懆鐜囷紙蟺锛夈傚府鍔╃敤鎴峰湪瀹炶返涓涔犲拰鐞嗚ВST璇█鐨勫熀鏈蹇靛拰搴旂敤鏂规硶銆
    1绋嬪簭璁捐鎬濊矾
    鍒╃敤闅忔満鐐瑰湪鍗曚綅姝f柟褰腑鐨勫垎甯冿紝浼扮畻鍥涘垎涔嬩竴鍦嗙殑闈㈢Н锛屼互姝よ绠椣銆
    2绋嬪簭浠g爜

    [AppleScript] 绾枃鏈煡鐪 澶嶅埗浠g爜
    FUNCTION_BLOCK FB_CalculatePi
    VAR_INPUT
        NumPoints : DINT := 10000; // 鎬绘ā鎷熺偣鏁
    END_VAR
    VAR_OUTPUT
        PiEstimate : REAL; // 鍦嗗懆鐜囦及璁″
    END_VAR
    VAR
        PointsInsideCircle : DINT; // 鍦嗗唴鐐硅鏁
        i : DINT; // 寰幆璁℃暟鍣
        x, y : REAL; // 闅忔満鐐圭殑x, y鍧愭爣
        Seed : DINT := 12345; // 闅忔満鏁扮瀛
    END_VAR
    
    // 绾挎у悓浣欑敓鎴愬櫒
    FUNCTION LCG : REAL
    VAR
        A : DINT := 1664525;
        C : DINT := 1013904223;
        M : DINT := 2147483647;
    END_VAR
    Seed := (A * Seed + C) MOD M;
    LCG := REAL(Seed) / REAL(M);
    
    (*
    鐗堟湰璁板綍锛
    鐗堟湰          鏃ユ湡           浣滆
     V1         2024-5-3       宸ユ帶鑰佺帇
     V2         2024-10-10     宸ユ帶鑰佺帇
    *)
    
    
    FOR i := 1 TO NumPoints DO
        // 鐢熸垚闅忔満鐐
        x := LCG();
        y := LCG();
        
        // 妫鏌ョ偣鏄惁鍦ㄥ渾鍐
        IF (x * x + y * y) <= 1.0 THEN
            PointsInsideCircle := PointsInsideCircle + 1;
        END_IF
    END_FOR
    
    // 璁$畻蟺鐨勪及璁″
    PiEstimate := 4.0 * REAL(PointsInsideCircle) / REAL(NumPoints);
    PointsInsideCircle := 0;

    3浠g爜杩愯
    鍙 100000 鐐癸紝杩愯缁撴灉涓 3.14232銆傚鍔犵偣鏁板彲浠ヤ娇缁撴灉鏇村姞绮剧‘銆
    640?wx_fmt=png&from=appmsg.jpg

    640?wx_fmt=png&from=appmsg.jpg
    4浠g爜瑙i噴
    鍙橀噺瀹氫箟锛
    • NumPoints锛氱敤浜庢ā鎷熺殑鎬荤偣鏁般
    • PiEstimate锛氳绠楀緱鍒扮殑鍦嗗懆鐜囦及璁″笺
    • PointsInsideCircle锛氳惤鍦ㄥ渾鍐呯殑鐐圭殑鏁伴噺銆
    • x銆亂锛氱敓鎴愮殑浼殢鏈虹偣鐨勫潗鏍囥
    • Seed锛氱敤浜庣敓鎴愪吉闅忔満鏁扮殑绉嶅瓙銆

    鏍稿績閫昏緫锛
    • 浣跨敤绾挎у悓浣欑敓鎴愬櫒鐢熸垚浼殢鏈烘暟銆
    • 妯℃嫙闅忔満鐐癸紝缁熻钀藉湪鍗曚綅鍦嗗唴鐨勭偣鏁般
    • 璁$畻蟺鐨勪及璁″硷細蟺 鈮 4 脳 (鍦嗗唴鐐规暟 / 鎬荤偣鏁)銆

    5搴旂敤鍦烘櫙
    閫傜敤浜庢暟鍊艰绠楀拰闅忔満妯℃嫙鐨勬暀瀛﹀満鍚堬紝甯姪鐞嗚В鍦嗗懆鐜囪绠楄繃绋嬨
    6寮婧愮増鏈鏄
    璇ョ▼搴忛伒寰紑婧愬師鍒欙紝浠讳綍浜洪兘鍙互浣跨敤銆佷慨鏀瑰拰鍒嗗彂姝や唬鐮併傚湪浣跨敤鍓嶅簲杩涜鍏呭垎鐨勬祴璇曪紝淇敼浠g爜鏃讹紝璇风鎸佸垎浜簿绁烇紝灏嗘偍鐨勬敼杩涘拰鎴愭灉杩涜鍒嗕韩锛屼互渚挎洿澶氫汉鍙楃泭銆

    鎬荤粨

    閫氳繃鏈缁冧範锛屾偍涓嶄粎鐔熸倝浜咰ODESYS ST璇█鐨勫熀鏈娉曪紝杩樻帉鎻′簡濡備綍浣跨敤钂欑壒鍗$綏鏂规硶杩涜鏁板艰绠椼傝繖鏍风殑瀹炶返鍙互鏈夋晥鎻愬崌缂栫▼鎶宸э紝涓鸿В鍐虫洿澶嶆潅鐨勮嚜鍔ㄥ寲闂濂犲畾鍩虹銆

    +10
    涓嶈禐涓涓紵
    鎵撹祻榧撳姳涓涓嬶紒
    鍥炲

    浣跨敤閬撳叿 涓炬姤

    鎮ㄩ渶瑕佺櫥褰曞悗鎵嶅彲浠ュ洖甯 鐧诲綍 | 绔嬪嵆娉ㄥ唽 鏂版氮寰崥鐧婚檰

    鏈増绉垎瑙勫垯

    椤堕儴qrcode搴曢儴
    鍏虫敞閰峰痉缃戣闃呭彿锛岃幏鍙栨洿澶氳祫璁紒

    QQ|灏忛粦灞|鎵嬫満鐗|Archiver|閰峰痉璁哄潧 ( 鑻廔CP澶16065247鍙-1 )|缃戠珯鍦板浘

    GMT+8, 2025-4-5 06:08 , Processed in 0.144335 second(s), 61 queries .

    閰峰痉缃

    © 2001-2013 Hicodesys. 鎶鏈敮鎸 by 閰峰痉缃

    蹇熷洖澶 杩斿洖椤堕儴 杩斿洖鍒楄〃