Any Online-Code Control From PC Examples?

Hi,

We are building a robot with an array of sensors (ultrasonic, infared, light, cmucam3, encoders, etc etc), motors and servos.

What I want to do is take an old Dell laptop (small C400 1ghz, 1gb ram, 20gb drive with 12" screen), and ditch the screen, case and keyboard, mounting it in a custom low profile plastic case, and use the programming cable to control the microcontroller from the laptop via an automomous application I am thinking about developing that actually will allow the robot to learn from mistakes, save/gather data, etc.

While I know what I want to do, unfortunately I can find not one good example of controlling the sensors and motors connected to the vex controller from a pc application.

I am looking for someone with actual PC based code snippets in c, c++ or c# (vb.net would be fine to I will just translate it) that control the motors, obtain data from the sensors, etc.

For example how would I make a call to start an ultrasonic sensor, and get its data, how would I get the data from bumper sensors, how would I set a motor to run?

Can ALL things on the controller be controlled from the pc?

Thanks in advance! :slight_smile:

Good for you!!! Sounds like a challenge. :wink:

I like your thinking!! Keeping the Weight Down is important, but there is lots of value in the Screen and Keyboard, unless you are going for a version of Linux, in which case those are very moot.

Yes, there has been some work done in that area, but it is far from complete. The PC Control of the Vex is done through the Vex On-Line Code found in the VEX Starter Code, located on the VEX Robotics Support page.

The Vex On-Line Code by default seems to support status (read) and control (write) of the PWM port (e.g. Motors and Servos), read and write of the EEPROM, and read and write of the RAM. Additional Support for the I/O might already be possible, or could be added.

Look at the Source Files PicSerialDrv.h and PicSerialDrv.c. for the Code

Start with Thread, Serial Interface: On-line code.

Motor is easy, see above Thread. The Vex Controller I/O appears to not be documented, but I am looking into it… I would guess that ALL things can be controlled, either through read and write of the RAM or through additions to the On-Line Code. I am looking to that as well. :wink:

Glad to have you here… Welcome to Vex…

I wouldn’t carry the laptop around. Go wireless if the range of operation does not exceed the wireless device. I use http://www.ipenabled.com/bluetooth-rs232-usb.html . To make it independent from the power supply you need a 4 AA batery pack and a H adapter from RadioShack.
That should take care of the COMM part.
Now for the controller…

  1. Use the On-Line mode provided. Advantage of it is speed. Limitation of it is since you can’t get the source code your stuck with default configuration of 4 Analogs, 6 digital in and 6 digital out. The controller will keep on writing smth like ‘BOARDDATA a1…a4 d1 … d6 i1… i6’ where a1 through a4 are values of analog ports follwed by 6 digital inputs and finally the interrupts. As far as telling the controller what to do I used a serial port sniffer and came up with this:
    InitializeOnLineMode 0F 0F 08 40 B8 04 C9 17 01 00 00 00 or
    15 15 8 64 184 4 201 23 1 0 0 0
    SetMotor( 00-07, 00-FF) C9 17 04 00 FF 00 or
    201 23 4 0 255 0
    SetDigitalOutput( 00-05, 00-01 ) C9 17 06 00 01 00 or
    201 23 6 0 1 0
    Reset C9 17 03 00 00 00 or
    201 23 3 0 0 0
    Close C9 17 02 00 00 00 or
    201 23 2 0 0 0
Another problem I was facing using this was that I couln't use the ultrasonic sensor. Look for posts by me (not too many to go through). I just went for a SHARP sensor which is using only one analog port and it doesn't need a start, get, stop. You can always overcome limitations like this by finding diffrent sensors.

I managed to wrap all this in a nice component so I can reuse it as many times by diffrent robot programs. Just wish they would release the source code for the online mode.

  1. You can write your program to interpret what you send from the PC. For example (using easyC)
    unsigned char inChar;
    inChar = Read1USART(); //this seems to be the serial port
    if (inChar == ‘w’)
    SetMotor(1, 200);
    Problem I had with this appoach is I couldn’t beat or come close to the speed of the on line code.

Finally the PC.

I use C# with visual studio 2008 express edition (free from microsoft)

You need a serial port object nothing to it and a thread to keep on reading the port. When it comes to sending data even easier. I will only post snippets.

using System.IO.Ports;

....

SerialPort port = new SerialPort("COM40", 115200); //com 40 if you install the gizmo I mentioned at the begining.

 .... make a thread that does  port.Read() or port.ReadLine() depending on what programm your runnig on the controller

... assuming your using the on line mode to set motor 3 to speed 200 you would do smth like 
 byte] commandBytes = new byte] {201, 23, 4, 3 -1 , 200 , 0};
 port.Write(commandBytes , 0, commandBytes .Length);    

 I like the ideea of your project. I'd appreciate if you keep posting the progress. :) I'm playing with a more advanced robot that would be impossible without a PC to do the  'heavy lifting'.

Thanks all for your valuable info! This should get me started…

I liked the idea about using a serial port sniffer, I didn’t think of that.

I have some sharp infareds sensors as well as the vex ultrasonic so I will play around with those for now but eventually I want to try and get all of them working together.

I will definitely start posing some pictures, video, and progress as this project moves along!

Thanks!

Well I have been working hard since Sat, 06-SEP-2008 to Reverse Engineer the Vex 1.x, Vex 2.x and Ver 3.x On-Line Code (see Thread Source Code for of the On-Line Code, What’s Up!!?). I have learned a lot… :wink:

I have a Ver 2.x On-Line Code just about ready to be released. I have ALL the Inputs working (e.g. 4 Analog, 6 Digital, 6 Interrupt). I just need to get the Outputs (e.g. PWM, and Digital Outputs) working.

Because of Timing Issues, I will need to provide some Custom Code for Ultra Sonic and Quadrature Inputs. I also will make the Number of Inputs and Outputs selectable, which will Break the Ver 2.x On-Line Window (the PC Program), but give the Vex Inventor (that would be YOU) much more flexibility in the interfacing the Vex to your PC.

I plan to make a Hybrid System of DDT and Ver 2.x On-Line Code. All Documented, with Source Code available for experimentation.

Now, a request for one or two of you…

I could use some help on the PC side of things… I have VB 6.0, and VC 6.0 . I also have VB and VC in VS 2005 and I think also VS 2008. But I can barely make an Windows Application, let alone one that accesses the Serial Port. Can anyone figure that out??? I can tell you what needs to be generated and sent, and what to receive. Use the On-Line Window of the IFI/intelitek Loader v2.x for an example of what data will be exchanged between the Vex and the PC.

How are you reverse engineering the code? I know I tried with no luck.
As far as the windows application: would you consider C# visual studio 2008 or 2005? If so what exactly do you want the application to do. Be a ‘copy’ of the OnLine terminal command window?

MarkO,

I am working on a project that would require an interface very similiar to what you talking about. I however lack the knowledge to figure out how to interface to the controller. It sounds like you are pretty close to having that part of it worked out. I am pretty good at designing applications using visual basic for applications (using Excel and Access). I have VS express 2008 and would like to help if you are interested.

At the very least I could design a really good looking User Interface using a Visual Studio Form. Hopefully along the way we can figure out how to tie the two together. If you are interested you can send me whatever you’ve got to get me started.

Regards,

-Brando:D

Check out the JVEX (JAVA) links and Sensor Tagging using Vex hardware for control of Vex robots using a PC or laptop host. The JVEX firmware is based on the original IFI Dynamic Debug Tool firmware (DDT), but also has the bumper sensors and Vex optical encoder and Vex Ultrasonic Ranger sensor functions that can also be called from Microchip PIC18 C using MPLAB.

https://jvex-robotics.dev.java.net/servlets/ProjectForumView

An excellent Question!

For the following presentation, “Vex On-Line Controller Code” refers to the Vex Controller Program that is downloaded to the Vex Controller and is intended to communicate with the “IFI/intelitek Loader On-Line Window” of the IFI/intelitek Loader. There are at least 3 different Major Versions of the “IFI/intelitek Loader” program. I have them Labeled as Ver 1.x, Ver 2.x and Ver 3.x.

Reverse Engineering the Code (AKA Machine Language) would get me Assemble Language, that can possibly infer some of the ‘C’ code. But that is a lot of effort. (Yes, I am Lazy… I thought I was just a clever Engineer, but my boss says I am just Lazy :wink: )

So looking at the 50,000 Foot View (15,240 Meters for our Metric friends) the real goal here is to make a Vex Controller Program that works with the IFI/intelitek Loader On-Line Window, (since this is a good starting point of how to control the Vex Robot through the Serial Connection) but allows us to modify it to better suit our Mission Requirements.

Since the Vex Dynamic Debug Tool (DDT Code) has Source Code in the VEX Starter Code, And the Vex On-Line Code for Version 1.x of the IFI/intelitek Loader On-Line Window seems very simular to the DDT Code (See Thread Source Code for of the On-Line Code, What’s Up!!?), I Reverse Engineered the Data Stream between the Vex Controller and the IFI/intelitek Loader On-Line Window with a home made serial port sniffer.

I looked at the Data Stream in Version 1.x, 2.x and 3.x (Pro) of the IFI/intelitek Loaders, Plus I looked at the DDT in the IFI Loader. I will post the differences I find, for all of you. I admit I would not be able to find every possible feature of the Vex On-Line Controller code without a lot of Trial and Error, but at least I can see what the IFI/intelitek Loader sends to the Vex On-Line Control program and what the Vex On-Line Control program sends back to the IFI/intelitek Loader.

I can see from your above post that you have Version 2.x of the IFI/intelitek Loader program (Ver 1.x and 3.x have different Data formats). I discovered like you that the “SetMotor( 00-07, 00-FF)” has a command format of “C9 17 04 00 FF 00” and “SetDigitalOutput( 00-05, 00-01 )” has a command format of C9 17 06 00 01 00". So what happened to a command format of “C9 17 05 00 00 00”? Well, the IFI/intelitek Loader ver 3.x gives that answer… It is the Relay Control on the FRC Robot Controllers. There might be more Commands, but if you can not get the IFI/intelitek Loader On-Line Window to send them, you can not find out what they might do.

Here is my “low tech” response from the Vex On-Line Controller Code for IFI/intelitek Loader On-Line Window Ver 2.x:

  printf("BOARDDATA ");

  printf("%04u ", Get_Analog_Value (rc_ana_in01));

  printf("%04u ", Get_Analog_Value (rc_ana_in02));

  printf("%04u ", Get_Analog_Value (rc_ana_in03));

  printf("%04u ", Get_Analog_Value (rc_ana_in04));

  printf("%1d %1d %1d %1d %1d %1d ", rc_dig_in05, rc_dig_in06, rc_dig_in07, 
	rc_dig_in08, rc_dig_in09, rc_dig_in10);
  printf("%1d %1d %1d %1d %1d %1d\x0d", rc_dig_int1, rc_dig_int2, rc_dig_int1,
	rc_dig_int4, rc_dig_int5, rc_dig_int6); 

I setup the I/O block to match the Vex On-Line Controller Code 2.x (e.g. 4 Analog, 6 Digital Inputs, 6 Digital Outputs, and the 6 Digital Interrupts). One change that I made to the Analog Output was choosing a format of “%04u” verses “%4u”. For a number like One-Thousand-Twelve (1012) it make no difference, but for a number like Six-Hundred-Twelve (612), the difference is “0612” verses “612”. I chose this so that even if every Analog input was Zero (0), the line would be a consistent length (54 bytes including the Return [0x0d]).

For this project, sure… But first a word from my Conscience…

[Political Rant]MicroSoft S**ks!! My WinXP Desktop TODAY is as stable as my OS/2 Warp 3.0 Desktop of 1994, it only took MicroSoft 14 years to Get There!!! MicroSoft’s Proprietary Offerings are not to my liking, (e.g. .NET, C#, SilverLight, ect…) I have plenty more to say, but Enough Said, this is about Robotics!!
[/Political Rant]

C# will be fine at this point, since visual studio 2008 or 2005 is available to download (for free) and everyone could be able to access both the Vex Controller Code and the PC Controller Code. For the Long Term, a Platform Neutral Language, Like ‘C’ or ‘C++’ or JAVA would be a much better choice.

You could start by mimicking the “IFI/intelitek Loader On-Line Window Ver 2.x”. By that I mean mimic the “Functionality”, not so much “Look and Feel”, you can if you want mimic the “Look and Feel”, but it the “real world” you might get a Copyright Infringement against you… :wink:

Get the Sliders and Check Boxes and of course the Status Displays for the Inputs. Leave it Flexible, program for Abstraction. I will get you the Commands, although you know most of them already, that you need to assign to the Sliders and Check Boxes.

Yep, I can surely help with the Windows portion.

If you send me what to try as far and send/recieve I can definitely give it a try.

The only sensors that I do not have from Vex are the gyro and the newer encoders.

But the Vex Gyros aren’t out yet…

Technic-R-C

**Vex On-Line Controller Code v2.x (Available Source Version 0.80 Beta) ** is now available in the Vex Code section.

I forgot to add in the Compiled .hex file. So I will try to attach it here (along with the Source).
Vex_On-Line_2_Code_v0-80.zip (27.3 KB)

Maybe you can work on a VB PC Interface and bg_blea can work on VC# PC Interface.

Read my post to bg_blea on What to Start on. I will explain the other parts as you ask questions.

JVex Robotics is a handy site… I should look in there for some more ideas…

Read my post to bg_blea on What to Start on. I will explain the other parts as you ask questions.

MarkO,
I already made a windows application that looks and does what the online terminal does. I made it when playing with the online code to test my findings.
I will simplify it and post it but I think it might have to wait 'till the weekend.
I don’t think you can license the appearence of on application so I’m not worried about infringing on their rights. The ‘reverse engineering’ part sure does, but not the way your proposing. I think we are all in the clear. :wink:
Regarding the DDT application I remember having problems compiling the downloaded version. I will have a look at what you posted.
As far as Microsoft vs not Microsoft (just can’t help myself). I think debating this is like talking politics and who we should vote for :). You will always find experts supporting both sides. To defend my side: I think it’s the best out there for what I like doing and what my job is: programming. It fits my needs.

Great!! You do know which codes to send for each Slider and Check Box??

I can think a few might disagree with you… The iPod® appearance comes to mind.

Yes, I did too… On Thursday and Friday (04/05-SEP-2008) I was having all kinds of Compiler, Assembler and Linker Errors and could not figure out what was what. I can post a whole message on that as well, but to sum it up. “If asked about which Linker to use, select the one in the “mcc18” directory, not the MPLAB one. If you select WRONG, and the Compile fails to Build and Link, you can correct the project under “Project->Set Language Tool Locations…->Microchip C18 Toolsuite->Executables”.”

Hence the impromptu use of the [Political Rant][/Political Rant] tags.

MarkO,
What codes does you version support for setMotor and the rest? Same as the ones I posted at the beginning of the thread?

You may even want to research GNAT Ada GPS language for writing Vex based applications on the PC and laptops. The Ada GPS compiler is free and runs on Linux, Unix, Windows XP and VISTA. It is used for the NASA Space Station, US department of Defense, the Boeing 787, and the French Grand Vitesse Bullet Train. It is also used for developing medical devices and other embedded “life critical” applications.

This is great stuff MarcO!

Does anyone know the correct call to make to retrieve a value from say analog 1 from c# or C in Widnows? I can move motors and servos just fine but I am having issues reading the data of the various sensors like the bumper or an IR sensor.

I thought it was like port.Read(buffer, 0, bufferlength) or something but I am not seeing anything in my console app.