Robosavvy pushing new features onto Robobuilder Kits

Korean company maker of Robot kits and servos designed for of articulated robots. Re-incarnation of Megarobotics.
57 postsPage 4 of 41, 2, 3, 4
57 postsPage 4 of 41, 2, 3, 4

Post by AlexanderHWUK » Tue Mar 16, 2010 12:13 am

Post by AlexanderHWUK
Tue Mar 16, 2010 12:13 am

Hi all!

First, if this is a personal discussion then I apologise and I will create my own thread, but as I am working on the same stuff it is logical for me to write my questions in here.

Anyways, had some time to try the code to communicate with the Robobuilder through the Com Port, and for once it is not as difficult as it looks!

I have tried using l3v3rz code
Code: Select all
public int connect(string pn)
etc., but it seems I need some more code behind it (or I'm just a noob with C#), cause I can't get it to work. If there is more code, would you kindly release it? :D

However, mniki's code works like a charm! Also sticks with the RBC protocol which I have began to get used to. Nevertheless, I have some C# pitiful questions:

- I can send bytes through Com port, but how do I receive them? How can I read them, put them on screen, and save them as a string (or something else if more adequate)?

- Is it better for my project (I have an independent Artificial Neural Network code to calculate and learn depending on the Robobuilder PSD inputs), to put everything in the same code file? How do you co-ordinate different codes in C#? (Do you create a solution, and then have a code record its data in a file that another code can read at the same time?)

EDIT - Also forgot to add: In mniki's code, I send for example a motion command and the robot does it, but then it does not recognise if I send another one straight after that. I have tried putting delays (Using Thread.Sleep() ), but even if the delays work, the Robobuilder doesn't execute the next command :( Any hints? What have I forgot?

As always, thanks for all the help ;)

Alex
Hi all!

First, if this is a personal discussion then I apologise and I will create my own thread, but as I am working on the same stuff it is logical for me to write my questions in here.

Anyways, had some time to try the code to communicate with the Robobuilder through the Com Port, and for once it is not as difficult as it looks!

I have tried using l3v3rz code
Code: Select all
public int connect(string pn)
etc., but it seems I need some more code behind it (or I'm just a noob with C#), cause I can't get it to work. If there is more code, would you kindly release it? :D

However, mniki's code works like a charm! Also sticks with the RBC protocol which I have began to get used to. Nevertheless, I have some C# pitiful questions:

- I can send bytes through Com port, but how do I receive them? How can I read them, put them on screen, and save them as a string (or something else if more adequate)?

- Is it better for my project (I have an independent Artificial Neural Network code to calculate and learn depending on the Robobuilder PSD inputs), to put everything in the same code file? How do you co-ordinate different codes in C#? (Do you create a solution, and then have a code record its data in a file that another code can read at the same time?)

EDIT - Also forgot to add: In mniki's code, I send for example a motion command and the robot does it, but then it does not recognise if I send another one straight after that. I have tried putting delays (Using Thread.Sleep() ), but even if the delays work, the Robobuilder doesn't execute the next command :( Any hints? What have I forgot?

As always, thanks for all the help ;)

Alex
AlexanderHWUK offline
Savvy Roboteer
Savvy Roboteer
Posts: 27
Joined: Tue Mar 02, 2010 4:54 pm

Post by l3v3rz » Tue Mar 16, 2010 12:54 am

Post by l3v3rz
Tue Mar 16, 2010 12:54 am

Hi,

its only a code fragment. From scratch - create a new windows form project. Within the window form add a button. And then on the button1_click event call connect("COM1"); Also add the connect function as part of the forms application - You alo need to add to the "using section" for the IO ports and the RobobuilderLib

i.e.

Code: Select all

using System;
using System.Windows.Forms;
using System.IO;
using System.IO.Port;
using RobobuilderLib;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

       public int connect(string pn)
       {
       ...  rest of function
       }

        private void button1_Click(object sender, EventArgs e)
        {
             connect("COM1");
        }
    }
}


You also need to add the RobobuilderLib in the reference section.

It will handle receive bytes for you
Hi,

its only a code fragment. From scratch - create a new windows form project. Within the window form add a button. And then on the button1_click event call connect("COM1"); Also add the connect function as part of the forms application - You alo need to add to the "using section" for the IO ports and the RobobuilderLib

i.e.

Code: Select all

using System;
using System.Windows.Forms;
using System.IO;
using System.IO.Port;
using RobobuilderLib;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

       public int connect(string pn)
       {
       ...  rest of function
       }

        private void button1_Click(object sender, EventArgs e)
        {
             connect("COM1");
        }
    }
}


You also need to add the RobobuilderLib in the reference section.

It will handle receive bytes for you
l3v3rz offline
Savvy Roboteer
Savvy Roboteer
Posts: 473
Joined: Fri Jul 18, 2008 2:34 pm

Post by AlexanderHWUK » Thu Mar 18, 2010 11:02 pm

Post by AlexanderHWUK
Thu Mar 18, 2010 11:02 pm

Hello there,

Tried what you said, and everything works! However I want to know more on how to get data From the Robobuilder To my computer.

I know that you said the RobobuilderLib will handle the receive bytes for me, but how does it do it?

How can I, for example, show the PSD value on a Label in my Windows Form? How can I connect a string to the value shown on the Form?

Is there any possibility of saving this information into a file, so that another C# code can read it?

Many questions, but its the same issue ;)

Also, how much can this Windows Forms Application project handle?
All my Artificial Neural Networks code is done in normal C# Projects (Without crazy forms), so would I be able to implement a Form into them? (By copying this new Form code into that project and running it from there)
I have just tried this but it did not recognise that it was a form. Did I miss something?

C# is fun, but I am new to these Windows Forms :P (And Neural Networks, and Robobuilder, and Com Ports...)

Thanks again for your great support!

Alex
Hello there,

Tried what you said, and everything works! However I want to know more on how to get data From the Robobuilder To my computer.

I know that you said the RobobuilderLib will handle the receive bytes for me, but how does it do it?

How can I, for example, show the PSD value on a Label in my Windows Form? How can I connect a string to the value shown on the Form?

Is there any possibility of saving this information into a file, so that another C# code can read it?

Many questions, but its the same issue ;)

Also, how much can this Windows Forms Application project handle?
All my Artificial Neural Networks code is done in normal C# Projects (Without crazy forms), so would I be able to implement a Form into them? (By copying this new Form code into that project and running it from there)
I have just tried this but it did not recognise that it was a form. Did I miss something?

C# is fun, but I am new to these Windows Forms :P (And Neural Networks, and Robobuilder, and Com Ports...)

Thanks again for your great support!

Alex
AlexanderHWUK offline
Savvy Roboteer
Savvy Roboteer
Posts: 27
Joined: Tue Mar 02, 2010 4:54 pm

Post by l3v3rz » Thu Mar 18, 2010 11:34 pm

Post by l3v3rz
Thu Mar 18, 2010 11:34 pm

I suggest you might want a book on learning c# :)

The examples use forms - but the library RobobuilderLib is a C# library - you don't need windows forms. You can call direct from your ANN code.

If you want windows then I suggest you start by creating a new project (using Visual Studio 2005 or above) and add a button and see if it runs. You can then add a label to a form by drag and drop on the IDE, and write to it using label1.text="data". In the sample of connect() function the readdistance function returns a string res. so you can now set label1.text=res. and it will display in the form - cool.

To write a string value to a file is also quite simple theres a built in object System.IO.File that will do it. But see comment above - no need to transfer data with files.
I suggest you might want a book on learning c# :)

The examples use forms - but the library RobobuilderLib is a C# library - you don't need windows forms. You can call direct from your ANN code.

If you want windows then I suggest you start by creating a new project (using Visual Studio 2005 or above) and add a button and see if it runs. You can then add a label to a form by drag and drop on the IDE, and write to it using label1.text="data". In the sample of connect() function the readdistance function returns a string res. so you can now set label1.text=res. and it will display in the form - cool.

To write a string value to a file is also quite simple theres a built in object System.IO.File that will do it. But see comment above - no need to transfer data with files.
l3v3rz offline
Savvy Roboteer
Savvy Roboteer
Posts: 473
Joined: Fri Jul 18, 2008 2:34 pm

Post by AlexanderHWUK » Fri Mar 19, 2010 12:29 am

Post by AlexanderHWUK
Fri Mar 19, 2010 12:29 am

Hello!

Yea, unfortunately I have to learn C# on the go :?

Here is part of the code I have been using for now:

Code: Select all
         public int connect (string pn)
       {
           {
               string serialNumber = "";

               try
               {
                   SerialPort p = new SerialPort(pn, 115200, Parity.None, 8, StopBits.One);

                   p.ReadTimeout = 1000;
                   p.WriteTimeout = 1000;


                   PCremote pcr = new PCremote(p);

                   p.Open();

                   serialNumber = pcr.readSN();
                   pcr.runMotion(7);
                   PauseForMilliSeconds(3000);
                   string res = pcr.readDistance();
                   label2.Text = res;

                   p.Close();

                   return 1;
               }
               catch (Exception e1)
               {
                   return 0;
               }
           }
       }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = "COM Port Opened!";
            connect("COM2");
            label1.Text = "Finished Commands";
        }


I have a form with several buttons, and a label (Label2) that shows the PSD value when it is returned from the Robobuilder. However, I am getting a constant value of "1799", no matter what object is infront of the robot!

Also, I tried using a set of if statements to play 1 sound or another, depending if the PSD value was greater than 30 (I assumed the value would be cm). In what magnitude is the PSD value returned, and can I easily transform it to an Int instead of a string using System.Convert.ToInt32(res, 10)?

Thanks for all the help, as I am working on it right now I will try to answer/update as soon as I can ;)

UPDATE - The if statements I am using look like this:
Code: Select all
                   string res = pcr.readDistance();
                   int res2 = System.Convert.ToInt32(res, 10);
                   label2.Text = res;
                   if (res2 > 30)
                   {
                       pcr.runSound(8);
                   }
                   else
                   {
                       pcr.runSound(9);
                   }


If there is something wrong with them, or can be done better/easier, please tell ;)

UPDATE - Just checked with the PCControlMode.exe, and I get a constant 257 cm... Is this bad? What has happened? And another random question, any idea why I can't upgrade my firmware using the serial cable? It gives me an enigmatic error "Error encountered while downloading the firmware file" as soon as it starts. I have always upgraded my Robobuilder using bluetooth, that's why I never noticed this problem...

Alex
Hello!

Yea, unfortunately I have to learn C# on the go :?

Here is part of the code I have been using for now:

Code: Select all
         public int connect (string pn)
       {
           {
               string serialNumber = "";

               try
               {
                   SerialPort p = new SerialPort(pn, 115200, Parity.None, 8, StopBits.One);

                   p.ReadTimeout = 1000;
                   p.WriteTimeout = 1000;


                   PCremote pcr = new PCremote(p);

                   p.Open();

                   serialNumber = pcr.readSN();
                   pcr.runMotion(7);
                   PauseForMilliSeconds(3000);
                   string res = pcr.readDistance();
                   label2.Text = res;

                   p.Close();

                   return 1;
               }
               catch (Exception e1)
               {
                   return 0;
               }
           }
       }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = "COM Port Opened!";
            connect("COM2");
            label1.Text = "Finished Commands";
        }


I have a form with several buttons, and a label (Label2) that shows the PSD value when it is returned from the Robobuilder. However, I am getting a constant value of "1799", no matter what object is infront of the robot!

Also, I tried using a set of if statements to play 1 sound or another, depending if the PSD value was greater than 30 (I assumed the value would be cm). In what magnitude is the PSD value returned, and can I easily transform it to an Int instead of a string using System.Convert.ToInt32(res, 10)?

Thanks for all the help, as I am working on it right now I will try to answer/update as soon as I can ;)

UPDATE - The if statements I am using look like this:
Code: Select all
                   string res = pcr.readDistance();
                   int res2 = System.Convert.ToInt32(res, 10);
                   label2.Text = res;
                   if (res2 > 30)
                   {
                       pcr.runSound(8);
                   }
                   else
                   {
                       pcr.runSound(9);
                   }


If there is something wrong with them, or can be done better/easier, please tell ;)

UPDATE - Just checked with the PCControlMode.exe, and I get a constant 257 cm... Is this bad? What has happened? And another random question, any idea why I can't upgrade my firmware using the serial cable? It gives me an enigmatic error "Error encountered while downloading the firmware file" as soon as it starts. I have always upgraded my Robobuilder using bluetooth, that's why I never noticed this problem...

Alex
AlexanderHWUK offline
Savvy Roboteer
Savvy Roboteer
Posts: 27
Joined: Tue Mar 02, 2010 4:54 pm

Post by l3v3rz » Fri Mar 19, 2010 1:18 am

Post by l3v3rz
Fri Mar 19, 2010 1:18 am

When working the value should be in the range 10-50 cm according to the spec. Are you sure the PSD is connected ? Are you running V2.23 or greater of the firmware? Don't understand why you would get different values from the different programs.

Incidentally if you look in your console output window you should see the response message coming back from the robot. Look for "Response: "followed by some hex bytes

Make sure the COM port has been freed up - especially look to see if any old versions of PCRemote application are running in background - quick look at task manager should tell you That can cause RBCUpgrade to fail -although I don't recognise message you mention
When working the value should be in the range 10-50 cm according to the spec. Are you sure the PSD is connected ? Are you running V2.23 or greater of the firmware? Don't understand why you would get different values from the different programs.

Incidentally if you look in your console output window you should see the response message coming back from the robot. Look for "Response: "followed by some hex bytes

Make sure the COM port has been freed up - especially look to see if any old versions of PCRemote application are running in background - quick look at task manager should tell you That can cause RBCUpgrade to fail -although I don't recognise message you mention
l3v3rz offline
Savvy Roboteer
Savvy Roboteer
Posts: 473
Joined: Fri Jul 18, 2008 2:34 pm

Post by l3v3rz » Sun Mar 21, 2010 4:08 pm

Post by l3v3rz
Sun Mar 21, 2010 4:08 pm

BTW - early version of the PCRemote calculated the distance incorrectly -getting the byte order wrong. Ive just tried it on mine and it reads between 10-50cm as per spec. And if I disconnect the sensor altogether I get a constant (unsurprisingly!) 10cm output.

So I can't explain how you get 257cm. Make sure you have latest version of the library ( http://robobuildervc.googlecode.com/fil ... derLib.dll )


After the
string res = pcr.readDistance();
Console.writeLine(pcr.Message); // add this

The byte response should look like this on the console (or Output window)

Response:
16 04 00 00 00 02 32 00 32


cheers
BTW - early version of the PCRemote calculated the distance incorrectly -getting the byte order wrong. Ive just tried it on mine and it reads between 10-50cm as per spec. And if I disconnect the sensor altogether I get a constant (unsurprisingly!) 10cm output.

So I can't explain how you get 257cm. Make sure you have latest version of the library ( http://robobuildervc.googlecode.com/fil ... derLib.dll )


After the
string res = pcr.readDistance();
Console.writeLine(pcr.Message); // add this

The byte response should look like this on the console (or Output window)

Response:
16 04 00 00 00 02 32 00 32


cheers
l3v3rz offline
Savvy Roboteer
Savvy Roboteer
Posts: 473
Joined: Fri Jul 18, 2008 2:34 pm

Post by AlexanderHWUK » Sun Mar 21, 2010 7:39 pm

Post by AlexanderHWUK
Sun Mar 21, 2010 7:39 pm

Hello again,

Ok, did what you said, and I got this:

14 01 00 00 00 01 07 07

Wait, I'll try deleting code around it and see if this solves the issue (always works!)

UPDATE - There you go, I had a delay in front of it, probably not enough, so it was picking up the response from the previous action (dough!) Now I can use the PSD again woohoo!

16 01 00 00 00 02 0A 00 0A - Yay!

However, PCControl still says its 257cm away... I have no idea how to fix this. As long as my code works, rock on :P

A question out of the box, how precise is this IR detector? Do you know its tolerance? (ie +- 2cm?). I suppose I can get around it by placing the objects at greater distances between each other, but still :P

Thanks for helping me solve the issue ;)

UPDATE - New problem!! The test code I have created basically makes the Robobuilder sit up straight, and then read the distance 10 times (play a 1 if its farther than 30cm, a 0 if not). Part of my code looks like this:

Code: Select all
 serialNumber = pcr.readSN();
                   pcr.runMotion(7);
                   PauseForMilliSeconds(6000);
                   for ( int i = 0;i <10;i++ )
                   {
                       pcr.runSound(16);
                   }
                   else
                   {
                       pcr.runSound(15);
                   }
                   PauseForMilliSeconds(2000);
               }
                   p.Close();
 


I don't know why, after sitting up straight, the value I get outputted in the console is 14 00 etc, and then 15 00 etc. but not the PSD Value! Is there any way to fix this? I thought I needed a bigger delay, but that does not solve the issue.
Hello again,

Ok, did what you said, and I got this:

14 01 00 00 00 01 07 07

Wait, I'll try deleting code around it and see if this solves the issue (always works!)

UPDATE - There you go, I had a delay in front of it, probably not enough, so it was picking up the response from the previous action (dough!) Now I can use the PSD again woohoo!

16 01 00 00 00 02 0A 00 0A - Yay!

However, PCControl still says its 257cm away... I have no idea how to fix this. As long as my code works, rock on :P

A question out of the box, how precise is this IR detector? Do you know its tolerance? (ie +- 2cm?). I suppose I can get around it by placing the objects at greater distances between each other, but still :P

Thanks for helping me solve the issue ;)

UPDATE - New problem!! The test code I have created basically makes the Robobuilder sit up straight, and then read the distance 10 times (play a 1 if its farther than 30cm, a 0 if not). Part of my code looks like this:

Code: Select all
 serialNumber = pcr.readSN();
                   pcr.runMotion(7);
                   PauseForMilliSeconds(6000);
                   for ( int i = 0;i <10;i++ )
                   {
                       pcr.runSound(16);
                   }
                   else
                   {
                       pcr.runSound(15);
                   }
                   PauseForMilliSeconds(2000);
               }
                   p.Close();
 


I don't know why, after sitting up straight, the value I get outputted in the console is 14 00 etc, and then 15 00 etc. but not the PSD Value! Is there any way to fix this? I thought I needed a bigger delay, but that does not solve the issue.
Last edited by AlexanderHWUK on Sun Mar 21, 2010 8:44 pm, edited 1 time in total.
AlexanderHWUK offline
Savvy Roboteer
Savvy Roboteer
Posts: 27
Joined: Tue Mar 02, 2010 4:54 pm

Post by l3v3rz » Sun Mar 21, 2010 8:33 pm

Post by l3v3rz
Sun Mar 21, 2010 8:33 pm

Your code doesn't look right . The for loop doesn't have legal syntax etc. Not sure what version of PCControl you're using but I'd ignore it - sound like and old version - just ignore it.

From the sound of your problem though is where you read message, its only valid until the next pcr command. It sounds like you're seeing the response from the sound commands rather than read distance. So for 14 00 etc is the response from runMotion and 15 00 the response from runSound. The read distance reponse is 16 00 - and in your example 16 01 00 00 00 02 0A 00 0A the distance is 0A 00 = 10 cm

The detector seems fairly accurate +/- 1 cm
Your code doesn't look right . The for loop doesn't have legal syntax etc. Not sure what version of PCControl you're using but I'd ignore it - sound like and old version - just ignore it.

From the sound of your problem though is where you read message, its only valid until the next pcr command. It sounds like you're seeing the response from the sound commands rather than read distance. So for 14 00 etc is the response from runMotion and 15 00 the response from runSound. The read distance reponse is 16 00 - and in your example 16 01 00 00 00 02 0A 00 0A the distance is 0A 00 = 10 cm

The detector seems fairly accurate +/- 1 cm
l3v3rz offline
Savvy Roboteer
Savvy Roboteer
Posts: 473
Joined: Fri Jul 18, 2008 2:34 pm

Post by AlexanderHWUK » Sun Mar 21, 2010 8:43 pm

Post by AlexanderHWUK
Sun Mar 21, 2010 8:43 pm

Oups, you're right, that code is wrong, must have been changing it while I copied it. Now it's corrected ;)

I can get around the pcr command output problem by reading the serial number, and ignoring the first output, but I hope there is a more efficient solution.

Cheers,

Alex
Oups, you're right, that code is wrong, must have been changing it while I copied it. Now it's corrected ;)

I can get around the pcr command output problem by reading the serial number, and ignoring the first output, but I hope there is a more efficient solution.

Cheers,

Alex
AlexanderHWUK offline
Savvy Roboteer
Savvy Roboteer
Posts: 27
Joined: Tue Mar 02, 2010 4:54 pm

Post by l3v3rz » Sun Mar 21, 2010 9:09 pm

Post by l3v3rz
Sun Mar 21, 2010 9:09 pm

If you post the code I might be able to suggest a more efficient way. Not sure what you mean about readSN number everytime and ignoring first output - its not necessary.

If you look at the L# maze code - its doing something very similar to what you have here. i.e. checking value from distance sensor, playing a motion depending on current state and value returned and looping.
If you post the code I might be able to suggest a more efficient way. Not sure what you mean about readSN number everytime and ignoring first output - its not necessary.

If you look at the L# maze code - its doing something very similar to what you have here. i.e. checking value from distance sensor, playing a motion depending on current state and value returned and looping.
l3v3rz offline
Savvy Roboteer
Savvy Roboteer
Posts: 473
Joined: Fri Jul 18, 2008 2:34 pm

Post by AlexanderHWUK » Sun Mar 21, 2010 9:41 pm

Post by AlexanderHWUK
Sun Mar 21, 2010 9:41 pm

Sorry for the confusion. Cryptic talking plus my confused spanish mind makes thing sound complicated.

From the beginning, if I run this:

Code: Select all
                   pcr.runMotion(6);
                   PauseForMilliSeconds(2000);
                   string res = pcr.readDistance();
                   Console.WriteLine(pcr.message);


In the console I don't get the Distance value, but the previous returned data (In this case, the Motion return value).

Right, just realised that "string res = pcr.readDistance();" doesn't actually output a pcr message, and that is why... duh! Just included a pcr.readDistance(), and all works well ;)

I am really sorry for the silly mistakes, hopefully I will realise the answer before posting about them...

Alex
Sorry for the confusion. Cryptic talking plus my confused spanish mind makes thing sound complicated.

From the beginning, if I run this:

Code: Select all
                   pcr.runMotion(6);
                   PauseForMilliSeconds(2000);
                   string res = pcr.readDistance();
                   Console.WriteLine(pcr.message);


In the console I don't get the Distance value, but the previous returned data (In this case, the Motion return value).

Right, just realised that "string res = pcr.readDistance();" doesn't actually output a pcr message, and that is why... duh! Just included a pcr.readDistance(), and all works well ;)

I am really sorry for the silly mistakes, hopefully I will realise the answer before posting about them...

Alex
AlexanderHWUK offline
Savvy Roboteer
Savvy Roboteer
Posts: 27
Joined: Tue Mar 02, 2010 4:54 pm

Previous
Previous
57 postsPage 4 of 41, 2, 3, 4
57 postsPage 4 of 41, 2, 3, 4
cron