View unanswered posts | View active topics It is currently Thu Apr 24, 2014 10:55 pm






Reply to topic  [ 39 posts ]  Go to page Previous  1, 2, 3  Next
2D array... I need help! (kinda urgent...). 
Author Message
Rookie

Joined: Sun May 12, 2013 3:17 pm
Posts: 21
Post Re: 2D array... I need help! (kinda urgent...).
JohnWatson wrote:
We will need to see the full code (including what you are doing with the motors); remember, you will be encounter the 0 condition 18 times before it gets to the 1 condition, so whatever you have in the 'case:0' will repeat 18 times in a row. Please provide us with the full code (motor commands included) and we will continue to help debug these issues.

I tried your provided code (with debug commands instead of psuedocode) and receive the expected result:

Code:
task main()
{
   int i,j;
   int image[6][4] = {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,1,0}};

   clearDebugStream();
   //Turn on motor1 and move it
   
   for (i = 0; i < 6; i++)
   {
      for (j = 0; j < 4; j++)
      {

         switch (image[i][j])
         {
         case 1:
            writeDebugStreamLine("The value of %d,%d is 1", i, j);
         break;
      
         case 0:
            writeDebugStreamLine("The value of %d,%d is 0", i, j);
         break;
      
      default:
      break;
         }
         
      }
   }
}


Result:
Quote:
The value of 0,0 is 0
The value of 0,1 is 0
The value of 0,2 is 0
The value of 0,3 is 0
The value of 1,0 is 0
The value of 1,1 is 0
The value of 1,2 is 0
The value of 1,3 is 0
The value of 2,0 is 0
The value of 2,1 is 0
The value of 2,2 is 0
The value of 2,3 is 0
The value of 3,0 is 0
The value of 3,1 is 0
The value of 3,2 is 0
The value of 3,3 is 0
The value of 4,0 is 0
The value of 4,1 is 0
The value of 4,2 is 0
The value of 4,3 is 0
The value of 5,0 is 0
The value of 5,1 is 0
The value of 5,2 is 1
The value of 5,3 is 0


Edit: On a side note, Xander's provided code works the exact same way (using if statements instead of a switch/case). In this instance, there is no 'superior' method of coding, but it is rather a matter of preference. Just wanted to throw that out there for reference.



Here:
Code:

task main()
{
  int i,j;
  int image[6][4] = {{0,0,1,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};


  clearDebugStream();

  motor[motorA] = -7;

  for (i = 0; i < 6; i++)
  {
    for (j = 0; j < 4; j++)
    {

     switch (image[i][j])
     {
      case 1:
             motor[motorA] = 0;
             nMotorEncoder[motorC] = 0;
             while (nMotorEncoder[motorC] > -360)
               {
                motor[motorC] = -50;
               }
             nMotorEncoder[motorC] = 0;
             while(nMotorEncoder[motorC] <360)
               {
              motor[motorC] = 50;
               }
              motor[motorC] = 0;
      break;

      case 0:
               while (SensorValue(thefirsttouchsensor) == 0)
              {
               motor[motorA] = -10;
              }
               motor[motorA] = 0;
               ClearTimer(T2);
               while (time10[T2] < 100)
                   {
                    motor[motorB] = 5;
                   }
                    motor[motorB] = 0;
      break;

    default:
    }

    }
  }
}



Thanks again


Thu May 23, 2013 3:38 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 537
Post Re: 2D array... I need help! (kinda urgent...).
It's probably getting stuck on the case:0 segment of code because of the low power levels being assigned to the motor. Generally, anything under +-15 will not make the robot move (do to friction, gearing, etc). Try kicking the motor values up to a higher magnitude (50 or 60, for example) and see if that changes anything. As far as I can tell, the program looks logically sound otherwise.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Thu May 23, 2013 4:16 pm
Profile
Rookie

Joined: Sun May 12, 2013 3:17 pm
Posts: 21
Post Re: 2D array... I need help! (kinda urgent...).
JohnWatson wrote:
It's probably getting stuck on the case:0 segment of code because of the low power levels being assigned to the motor. Generally, anything under +-15 will not make the robot move (do to friction, gearing, etc). Try kicking the motor values up to a higher magnitude (50 or 60, for example) and see if that changes anything. As far as I can tell, the program looks logically sound otherwise.

Nope, not working as well. When I click "step into" I see it stuck on "while (SensorValue(thefirsttouchsensor) == 0)
{
motor[motorA] = -10;
}"
and continue moving the motor. Then, the code not continue for searching 1's.


Fri May 24, 2013 12:51 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 537
Post Re: 2D array... I need help! (kinda urgent...).
The only other thing I can think of is the touch sensor possibly being bad. Does the value of the touch sensor change values appropriately when you press and hold it (while the program is running, the NXT is connected to the computer, and the Sensors Debug window is up)? Remember, too, that you will have to hold the touch sensor while stepping through in order for ROBOTC to recognize the press during the step; if you tap it while stepping, ROBOTC may miss the tap and read a 0 value on the sensor.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Tue May 28, 2013 4:31 pm
Profile
Rookie

Joined: Sun May 12, 2013 3:17 pm
Posts: 21
Post Re: 2D array... I need help! (kinda urgent...).
JohnWatson wrote:
The only other thing I can think of is the touch sensor possibly being bad. Does the value of the touch sensor change values appropriately when you press and hold it (while the program is running, the NXT is connected to the computer, and the Sensors Debug window is up)? Remember, too, that you will have to hold the touch sensor while stepping through in order for ROBOTC to recognize the press during the step; if you tap it while stepping, ROBOTC may miss the tap and read a 0 value on the sensor.

Thanks.


OK, I've another question, maybe it's gonna by my last quastion. I REALLY need your help, so please help me.
Let's continue with this:
Code:
int image[6][4] = {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,1,0}};

...and the rest of the code as it was written in the last replies.



I want that everytime it comes to the end of each group (forth number ,in this case) it will do something, doesn't matter right know what.
How can I write this down as a code? Like this: if (image[i][4])? Or what?
*And if there's an option to do it in generally way, because the numbers of i and j might be changed. But if not, then it's OK, nevermind, it's not a big deal to change it everytime manually.
Hope I wrote it enough clearly so you could understand me and help me as well.


Last edited by newspaper on Thu May 30, 2013 3:42 pm, edited 2 times in total.



Thu May 30, 2013 3:38 pm
Profile
Rookie

Joined: Sun May 12, 2013 3:17 pm
Posts: 21
Post Re: 2D array... I need help! (kinda urgent...).
Dear guys, please help me. Read above.

By the way, if I want to use RCX (rotation) sensor, what I need to do? Because when I look it on the NXT poll (a picture of it below, from another site) it seems that it stuck on 406 or somthing around it.
And the RCX motor which is connected to the RCX rotation sensor isn't stoping even when I wrote less than 180 or somthing.

In my robot, I'm using the NXT brick and some of the NXT motors, but also RCX motors and RCX sensor.

Picture:
http://4.bp.blogspot.com/_Xq9YetDerKc/R ... erface.JPG


HELP? :oops: :roll: :-(


Mon Jun 03, 2013 11:59 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3116
Location: Rotterdam, The Netherlands
Post Re: 2D array... I need help! (kinda urgent...).
Code:
int image[6][4] = {{0,0,0,5},{0,0,0,1},{0,0,3,0},{0,1,0,9},{0,0,0,6},{0,0,1,0}};

task main()
{
  clearDebugStream();
  for (int x = 0; x < 6; x++)
  {
    for (int y = 0; y < 4; y++)
    {
      if (y == 3)
        writeDebugStreamLine("we care about %d", image[x][y]);
      else
        writeDebugStreamLine("we don't particularly care about %d", image[x][y]);
    }
  }

  writeDebugStreamLine("-------------------------");
  for (int x = 0; x < 6; x++)
  {
    writeDebugStreamLine("we care about %d", image[x][3]);
  }
}


Try this :)

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Jun 03, 2013 12:49 pm
Profile WWW
Rookie

Joined: Sun May 12, 2013 3:17 pm
Posts: 21
Post Re: 2D array... I need help! (kinda urgent...).
mightor wrote:
Code:
int image[6][4] = {{0,0,0,5},{0,0,0,1},{0,0,3,0},{0,1,0,9},{0,0,0,6},{0,0,1,0}};

task main()
{
  clearDebugStream();
  for (int x = 0; x < 6; x++)
  {
    for (int y = 0; y < 4; y++)
    {
      if (y == 3)
        writeDebugStreamLine("we care about %d", image[x][y]);
      else
        writeDebugStreamLine("we don't particularly care about %d", image[x][y]);
    }
  }

  writeDebugStreamLine("-------------------------");
  for (int x = 0; x < 6; x++)
  {
    writeDebugStreamLine("we care about %d", image[x][3]);
  }
}


Try this :)

= Xander


First - thanks.
I didn't understand what you did. After "if" conditions and "else" should be "{", no?
And why the "for(int x =0; X<6; x++)"? I want that in the same time when it does the first part (if y==3 or not) it will also do something when it comes to the image[x][3]. So it's the same thing as you wrote up here?

I asked some more questions in the second message, if you don't mind please.


Mon Jun 03, 2013 1:26 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3116
Location: Rotterdam, The Netherlands
Post Re: 2D array... I need help! (kinda urgent...).
After an if you must have a {}, if you have more than a single command.
The two blocks of code essentially do the same thing. I was just showing you different approaches.
What were your other questions?

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Jun 03, 2013 4:19 pm
Profile WWW
Rookie

Joined: Sun May 12, 2013 3:17 pm
Posts: 21
Post Re: 2D array... I need help! (kinda urgent...).
mightor wrote:
After an if you must have a {}, if you have more than a single command.
The two blocks of code essentially do the same thing. I was just showing you different approaches.
What were your other questions?

= Xander

Why the "for(int x =0; X<6; x++)"? I want that in the same time when it does the first part (if y==3 or not) it will also do something when it comes to the image[x][3]. So it's the same thing as you wrote up here?

if I want to use RCX (rotation) sensor, what I need to do? Because when I look it on the NXT poll (a picture of it below, from another site) it seems that it stuck on 406 or somthing around it.
And the RCX motor which is connected to the RCX rotation sensor isn't stoping even when I wrote less than 180 or somthing.

In my robot, I'm using the NXT brick and some of the NXT motors, but also RCX motors and RCX sensor.

Picture:
http://4.bp.blogspot.com/_Xq9YetDerKc/R ... erface.JPG


Tue Jun 04, 2013 12:21 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3116
Location: Rotterdam, The Netherlands
Post Re: 2D array... I need help! (kinda urgent...).
newspaper wrote:
Why the "for(int x =0; X<6; x++)"? I want that in the same time when it does the first part (if y==3 or not) it will also do something when it comes to the image[x][3]. So it's the same thing as you wrote up here?

Both do the same thing, I just wanted to show you two approaches.

Quote:
if I want to use RCX (rotation) sensor, what I need to do? Because when I look it on the NXT poll (a picture of it below, from another site) it seems that it stuck on 406 or somthing around it.
And the RCX motor which is connected to the RCX rotation sensor isn't stoping even when I wrote less than 180 or somthing.

I am not familiar with that sensor, so someone else may have to help you out there.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Jun 04, 2013 8:21 am
Profile WWW
Rookie

Joined: Sun May 12, 2013 3:17 pm
Posts: 21
Post Re: 2D array... I need help! (kinda urgent...).
mightor wrote:
newspaper wrote:
Why the "for(int x =0; X<6; x++)"? I want that in the same time when it does the first part (if y==3 or not) it will also do something when it comes to the image[x][3]. So it's the same thing as you wrote up here?

Both do the same thing, I just wanted to show you two approaches.

Quote:
if I want to use RCX (rotation) sensor, what I need to do? Because when I look it on the NXT poll (a picture of it below, from another site) it seems that it stuck on 406 or somthing around it.
And the RCX motor which is connected to the RCX rotation sensor isn't stoping even when I wrote less than 180 or somthing.

I am not familiar with that sensor, so someone else may have to help you out there.

= Xander


OK, thanks. But about my first question:
The fourth number could be 0 or 1. If it's 1 I want that it will do same thing as he does on the "image[][] = 1" and if it's 0 it will do what he was asked to do on "else". But then, after that - I want that he'll do something new (something that only the foruth number in a row).It will be good to do it like this way:

for (x)
{
for (y)
{
if (image == 1)
do this

else
do something else

if ( y == 3 )
do something new
}
}

:?:



Edit:
It's working... somehow. Read please the new message below. THANKS.


Last edited by newspaper on Wed Jun 05, 2013 2:50 am, edited 2 times in total.



Tue Jun 04, 2013 11:48 am
Profile
Rookie

Joined: Sun May 12, 2013 3:17 pm
Posts: 21
Post Re: 2D array... I need help! (kinda urgent...).
OK I've checked it and it's working! Yes! Thanks a lot! So forget about all what I've wrote in the previos messages.

But I've seen a problem. I want that the motor will contunue unless a touch sensor is pressed ("1").
However, when I checked it I saw that the motor need to pressed very hard in order the sensor to identify. And my sensor touch is not broken, because I checked it with more than one sensor touch.

In your opinion, there is any solution?


And another question:
Lets say that I have 2d array and I want that black and white dots to be also display on the LCD screen. I know that I need to do "for" loops, but what how?


By the way, do you know any program or softwares that can change black and white images into binary codes of 1 and 0?
I could'nt find one.


Thanks a lot again!!!! :bigthumb:


Wed Jun 05, 2013 2:48 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3116
Location: Rotterdam, The Netherlands
Post Re: 2D array... I need help! (kinda urgent...).
There is almost always a solution! Do you think you could copy and paste your entire program that you have now? The issue wmight be the code and not the sensor :)

Quote:
By the way, do you know any program or softwares that can change black and white images into binary codes of 1 and 0?

Is this for a maze or something?

Quote:
Lets say that I have 2d array and I want that black and white dots to be also display on the LCD screen. I know that I need to do "for" loops, but what how?

I'd like you to think about it for a bit. It is not all that different from how you go through each item in those arrays. Write it in "pseudo code" first.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Jun 05, 2013 1:42 pm
Profile WWW
Rookie

Joined: Sun May 12, 2013 3:17 pm
Posts: 21
Post Re: 2D array... I need help! (kinda urgent...).
mightor wrote:
There is almost always a solution! Do you think you could copy and paste your entire program that you have now? The issue wmight be the code and not the sensor :)

OK, I'll sent it for you later in the PM (Private Messages). For now please try to help me in those problems and questions which are stated in the end of the message:

Quote:
Is this for a maze or something?

Nope. I wrote you what's that in one of the private messages before a week ago (or mabe it was even before a week). Check it out if you don't remember :-)

Quote:
I'd like you to think about it for a bit. It is not all that different from how you go through each item in those arrays. Write it in "pseudo code" first.


I thought about that:

Code:
int i, j;
int image[x][y]
for(i=0; i<x; i++){
  for(j=0; j<y; j++){
    if(image[i][j] == 1){ //1 IS BLACK POINT
      nxtSetPixel(j,x);
    }
  }
}


Am I right? I don't think so... I need to change something and I don't know what. What do you think?





By the way:
What is the ROBOTC funciton if I want to display an image on the LCD screen of the nxt brick? I mean, there are several images in the NXTG of smilies and those kinds of images. In NXTG I just choose the image when I edit the "block" but what should I do in ROBOTC?
Same question if I want sounds - there are some sounds in the NXTG like "Hooray" etc. What are the ROBOTC function that fits to those sounds?

THANK YOU VERY MUCH, YOU HELP ME SO MUCH, YOU ARE GREAT! 8)


Thu Jun 06, 2013 2:24 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 39 posts ]  Go to page Previous  1, 2, 3  Next

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.