Page 1 of 2

Can you show me this program from NXT-G to RobotC ?

Posted: 22 Jun 2011, 18:13
by nikera88
Can you show me this program from NXT-G to RobotC ?

http://www.laurensvalk.com/images/downl ... 527&ex=rbt

thank you!

Re: Can you show me this program from NXT-G to RobotC ?

Posted: 22 Jun 2011, 18:34
by mattallen37
You want that NXT-G program converted into ROBOTC?

Here is now I would go about doing it:
  • - Determine the logic used.
    - Create a loop and if statements to represent the loop and switches in the NXT-G program.
    - Build ROBOTC chunks of code to represent the NXT-G blocks.
    - Test to confirm it is working.
    - Optimize the program by cutting out unnecessary lines of code.
I don't program in ROBOTC, so I can't personally offer ROBOTC detail specifics.

Re: Can you show me this program from NXT-G to RobotC ?

Posted: 22 Jun 2011, 18:44
by mattallen37
I'm not gonna convert all the blocks into text code, but here is the logic (in NXC, not ROBOTC):

Code: Select all

task main(){
  SetSensorLight(S4);
  SetSensorType(S4, SENSOR_TYPE_LIGHT_ACTIVE);
  while(true){
    Wait(300);
    if(SENSOR_4<34){
    
    }
    else{
      if(SENSOR_4>48){
      
      }
      else{
      
      }
    }
  }
}
That should be the same logic layout, you just need to build it in ROBOTC.

Re: Can you show me this program from NXT-G to RobotC ?

Posted: 22 Jun 2011, 19:26
by nikera88
oh I saw the source code but I cant control the motors with the light sensor... ;o/ Im new in this LEGO "World" and I must be done whit this project after 2 days... ;o/ I beg you to show me the whole source code... this is very important

thanks!

Re: Can you show me this program from NXT-G to RobotC ?

Posted: 22 Jun 2011, 19:36
by mattallen37
I told you that was only the logic (and it's only the main structure for that matter), and in NXC (not ROBOTC). What I showed you is not source-code for the NXT-G program; it's my own hand-coded NXC program that makes up the logic used in the NXT-G program.

Why such a time-frame?

Like I said before, I don't program in ROBOTC. I can't magically convert an NXT-G program into ROBOTC, or any other language.

Why do you need the program in ROBOTC? What is the program for? Do you know that the NXT-G program works fine the way it is?

Re: Can you show me this program from NXT-G to RobotC ?

Posted: 22 Jun 2011, 19:45
by nikera88
this is simple color sorter

here is the project:
http://www.laurensvalk.com/nxt-1_0-only ... orter-8527

it must be on RobotC because my professor want this ;o/

Re: Can you show me this program from NXT-G to RobotC ?

Posted: 22 Jun 2011, 20:02
by mattallen37
Does it need to be ROBOTC? Can it be NXC? Do you need a literal interpretation of it? Is a functionally equivalent version fine? Does it need to make sounds?

If this is for a school project, shouldn't you do the work?

Re: Can you show me this program from NXT-G to RobotC ?

Posted: 22 Jun 2011, 20:12
by nikera88
without sounds... but okay write this program on NXC and I will try to make changes to work in RobotC

Re: Can you show me this program from NXT-G to RobotC ?

Posted: 22 Jun 2011, 20:18
by mattallen37
Well, I can try to make a working program in NXC. However, if you can't even begin to convert this yourself, I don't know how you will convert the NXC program into ROBOTC.

Can you please answer the other questions from my last post?

Re: Can you show me this program from NXT-G to RobotC ?

Posted: 22 Jun 2011, 21:07
by mattallen37
Well, here is an untested NXC program that I came up with.

Code: Select all

bool PosRegComplete(byte port, int tolerance, long position){
  if (MotorTachoCount (port)>=(position-tolerance)&&MotorTachoCount (port)<=(position+tolerance))
}

void Push(){
  PosRegSetAngle (OUT_B, -85);
  until(PosRegComplete(OUT_B, 5, -85));
  PosRegSetAngle (OUT_B, 0);
  until(PosRegComplete(OUT_B, 5, 0));
}

task main(){
  PosRegEnable (OUT_A);
  PosRegSetMax (OUT_A, 0, 0);
  PosRegEnable (OUT_B);
  PosRegSetMax (OUT_B, 0, 0);
  SetSensorLight(S4);
  SetSensorType(S4, SENSOR_TYPE_LIGHT_ACTIVE);
  while(true){
    Wait(300);
    if(SENSOR_4<34){                //Black
      PosRegSetAngle (OUT_A, 50);
      until(PosRegComplete(OUT_A, 5, 50));
      Push();
    }
    else{
      if(SENSOR_4>48){              //White
        PosRegSetAngle (OUT_A, -50);
        until(PosRegComplete(OUT_A, 5, -50));
        Push();
      }
      else{                         //Gray
        PosRegSetAngle (OUT_A, 0);
        until(PosRegComplete(OUT_A, 5, 0));
        Push();
      }
    }
  }
}