找回密码
 马上注册

QQ登录

只需一步,快速开始

查看: 5644|回复: 0

RoboArm NXC程序

[复制链接]
发表于 2012-6-30 01:04:55 | 显示全部楼层 |阅读模式
本人新手,学习了一段时间的NXC,一直只是阅读别人的程序,初次尝试将9695+9797中RoboArm程序改写成NXC如下,还请各位看看有没有不妥之处。
  1. sub Arm_Grab()
  2. {
  3.    //A电机反转,抓取物体
  4.   OnFwd(OUT_A,75);
  5.   Wait(500);
  6.   //停止A电机
  7.   Off(OUT_A);
  8. }

  9. sub Arm_Release()
  10. {
  11.    //A电机正转,放下物体
  12.   OnFwd(OUT_A,-75);
  13.   Wait(500);
  14.   //停止A电机
  15.   Off(OUT_A);
  16. }

  17. //原结构中增加了一个接在3号端口的触碰传感器来控制抓手的打开及闭合
  18. task Arm_Act()
  19. {
  20.      int Status=0;  //打开状态
  21.      while(true)
  22.      {
  23.                 //压下触碰传感器
  24.           while(SENSOR_3==1)
  25.           {
  26.                 if  (Status==0)
  27.                 {
  28.                       Arm_Grab();
  29.                       Status=1;
  30.                 }
  31.                 else
  32.                 {
  33.                       Arm_Release();
  34.                       Status=0;
  35.                 }
  36.           }
  37.      }
  38. }

  39. task Arm_Move()
  40. {
  41.      while(true)
  42.      {
  43.           ClearScreen();
  44.           TextOut(30,29,"Rotate");
  45.           TextOut(4,0,"Left");
  46.           TextOut(68,0,"Right");
  47.           while(!ButtonPressed(BTNCENTER))
  48.           {
  49.                if (ButtonPressed(BTNLEFT))
  50.                {
  51.                    OnFwd(OUT_C,+75);
  52.                }
  53.                else
  54.                {
  55.                    if (ButtonPressed(BTNRIGHT))
  56.                    {
  57.                        OnFwd(OUT_C,-75);
  58.                    }
  59.                    else
  60.                        Off(OUT_C);
  61.                }

  62.           }
  63.           ClearScreen();
  64.           TextOut(36,26,"Lift");
  65.           TextOut(4,0,"Down");
  66.           TextOut(85,0,"Up");
  67.           while(!ButtonPressed(BTNCENTER))
  68.           {
  69.                if (ButtonPressed(BTNLEFT))
  70.                {
  71.                    OnFwd(OUT_B,-75);
  72.                }
  73.                else
  74.                {
  75.                    if (ButtonPressed(BTNRIGHT))
  76.                    {
  77.                          OnFwd(OUT_B,+75);
  78.                    }
  79.                    else
  80.                         Off(OUT_B);
  81.                }
  82.            }
  83.      }
  84. }

  85. task main()
  86. {
  87.    SetSensorTouch(S3);
  88.    Precedes(Arm_Act,Arm_Move);
  89. }
复制代码
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|中文乐高 ( 桂ICP备13001575号-7 )

GMT+8, 2024-4-28 04:08 , Processed in 0.104074 second(s), 22 queries .

Powered by Discuz! X3.5

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表