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

Discussion specific to projects ideas and support.
nikera88
Posts: 5
Joined: 22 Jun 2011, 18:11

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

Post by nikera88 »

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

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

thank you!
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

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

Post 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.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

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

Post 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.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
nikera88
Posts: 5
Joined: 22 Jun 2011, 18:11

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

Post 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!
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

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

Post 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?
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
nikera88
Posts: 5
Joined: 22 Jun 2011, 18:11

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

Post 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/
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

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

Post 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?
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
nikera88
Posts: 5
Joined: 22 Jun 2011, 18:11

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

Post by nikera88 »

without sounds... but okay write this program on NXC and I will try to make changes to work in RobotC
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

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

Post 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?
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

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

Post 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();
      }
    }
  }
}
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest