Roborealm with C#
Berk from Turkey  [10 posts]
13 year
Hi guys,

Im trying to get COGX and COGY values from RR into my C# but i wasnt able to make it work. Im using;
string COGX, COGY;

                COGX = rr.getVariable("COGX");
                COGY = rr.getVariable("COGY");

                COGXtextBox.Text += COGX + Environment.NewLine;

line to get the values but nothing happens. I actually look for the method and everything seems to be fine. Please help me, thank you.
BTW, i checked API page and RR_API classes but still nothing for me :))
Berk from Turkey  [10 posts] 13 year
No one knows how to deal with it ? Please guys, i really need to do it asap... Thanks
Anonymous 13 year

You probably need to include more context. You are only showing a couple lines and not saying what the actual problem is.

Are you getting any results in COGX and COGY?
Are you not able to communicate with RR?
Are the results just not showing correctly but you can see them in debug mode? The += part of the code you show is a little suspect ... if it is just a text value box a straight = should do the trick.


Berk from Turkey  [10 posts] 13 year
Thanks for your reply Steven. The problem is that eventhougt i connect API server, it seems like not turning values. I dont get any values in both variables. When the code comes to the line
COGX = rr.getVariable("COGX"); it just crashes and thats it.

Im using multiple line textbox thats why i used +=.

Anonymous 13 year

What module is generating the variables? If it is the Center of Gravity module then the variables have an underscore in them. I.e. COG_X and COG_Y

Where is the crash happening? Which line number and what are the contents of the line?

Berk from Turkey  [10 posts] 13 year
        private void veriOku()
            RR_API rr = new RR_API();
            if (rr.connect("localhost"))
                //List<string> koordinat = new List<string>();
                string COGX, COGY;

                COGX = rr.getVariable("COG_X");
                COGY = rr.getVariable("COG_Y");


                //COGXtextBox.Text += COGX + Environment.NewLine;

Thats  the part, i try to read variables. And yes, COG values are generated by Center of Gravity.
Berk from Turkey  [10 posts] 13 year
Its been 3 days and nobody can suggest any option ? I really dont know what is wrong and what possible i can do? Please help me find a way. Thx
Ringo from United States  [18 posts] 13 year
Here is some code from an old program of mine that tracks a color.
      private void buttonTrack_Click(object sender, EventArgs e)
            int cogx,cogy,centerx,centery;
            int offset = 0;
           // int dir=0;
            int pan = 0;
           // int tilt = 0;
            Dimension d = rr.getDimension();
            centerx = d.width / 2;// int.Parse(d.width) / 2;
            centery = d.height / 2;// int.Parse(d.height) / 2;
            if (d != null)
                Console.WriteLine("center =  " + centerx + " ," + centery);
            while (true)
                cogx = int.Parse(rr.getVariable("COG_X"));
                Console.WriteLine("X={0}", cogx);
                cogy = int.Parse(rr.getVariable("COG_Y"));
                Console.WriteLine("Y={0}", cogy);
                offset = Math.Abs(centerx - cogx);
                if (centerx < cogx)
                    pan --;// offset;
                    pan++;// offset;
                Console.WriteLine("Offset={0} new pan value is {1}", offset,pan);
                sp.Write("servo 1:" + pan + "\r");
emilysoft11 from American Samoa  [1 posts] 13 year
Haven't I temporarily wanted to take how to do?
Berk from Turkey  [10 posts] 13 year
Thx Ringo. By your help, i was somehow able to make it work. Now i want to apply Gaussian blur and RGB_Filter and Center of Gravity. But i dont have clue how to set these modules values. For example, the window size of Gaussian blur or the values of RGB_filter as min_hue and hue_hysteresis... Can you suggest me a page or something like that so i can have list of request messages to set them. Thank you :)
Anonymous 13 year

Easiest way to do this is to use variables in the appropriate fields using something like


and then use the SetVariable api to change those values.

Alternatively, you can use the module in RR, save the pipeline in a RR config file (.robo) and then see what numbers correlate to what values. I.e. if you enter in 33 for the window size you should see which XML field that is in the saved .robo file by loading it back into a text editor. The .robo files are simple XML text.

Berk from Turkey  [10 posts] 13 year
Thank you very much Steven. It was really really helpful. Thank you :)

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index