program options

Sorry for posting two threads right after each other;

I’ve used easy c for a while mainly because I learned c++ at 8 or 10 and love the language, along with the fact it was the first vex program environment I was introduced to.
Now I have need for an advanced programming option.

My main need is for a program that can execute multiple actions at one time. I don’t know if this is impossible with the microcontroller because I know very little about circuits besides basics.

Reading the products comparison page, RobotC says it can run subprograms and tasks concurrently.

Im an autonomous man and lead programmer for a team that has a robot that navigates a maze. though the maze is always the same, I’d like to switch from dead recknoning (I can’t spell or pronounce that) using ultrasounds to know where I am to a robot that uses ultrasounds to navigate any 90 degree angle maze, and this requires (imo) side-by-side tasks running.

So, for an upgrade, should I go with RobotC or what appears to be the more powerful (and more funded) MPLab? Or maybe the easier to use easyC Pro? As I said before, I’m looking for advanced autonomous options that really give me a lot of control over what the robot is doing.

If you want to be VERY technical and are an advanced programer I suggest getting MPLAB because it allows the greatest flexibility. However in my opinion you should by EasyC Pro because it should suit your needs perfectly

Technic-R-C

As far as subroutines and all that I can’t offer any advice seeing as any of the coding that I do doesn’t involve any of that. However as far as writing the actual code one thing people often forget is that in easyC pro you can write directly in C.

I’m a fan of MPLAB and I use it for all my VEX projects. Since you are already familiar with C++ (and thus C), you should be able to write code for it just fine.

Having multiple tasks going at once means setting up interrupts, and probably using timers. This is where the real complexity comes from, since there isn’t an OS below you providing these services.

After you boil it all down, dealing with each PIC functional block is only a dozen lines of code or so, but you will sift through lots of PIC documentation to figure out what those dozen lines need to be.

Cheers,

  • Dean

MPLAB is free so give it a try. Just link complier to EasyC’s mcc18 complier. It worked for me.

Read the advice and suggestions of the other posts.

I would say that for the ultimate control of the Vex you need to use MPLAB and the MCC18 compiler.

EasyC 2.x and EasyC Pro let you run subprograms and to develop your own tasks that run concurrently read these articles I have linked to:

Advanced Programming Ideas

Advanced Programming Ideas (part 2)

Advanced Programming Ideas (Part 9)

I am working on a Programming Framework that will allow communication between Vex Controllers and will include a Cooperative Multitasking System like the one describe in Advanced Programming Ideas (part 2).

easy 2 lets you run subroutines… but I do not believe they run concurrently. Am I mistaken? If so, how do you do them? if i call up two tasks right after another they won’t activate until the first one is done

As a Technical Point, no programs run concurrently, unless there is more than One Processor executing the code base. It is all done with Cooperative Multitasking or Preemptive Multitasking.

Can you give me an example of two Subroutines that you want to run concurrently??

Hello,

The discussion seems to pass over part of bloodsheddragon’s question: how to make a program that does multiple things at once. Lets see if I can help with that idea.

Lets assume you are using the MPLAB software to program a PIC microcontroller in microcode for this example.

First lets define a couple things so we are sure we are communicating without any confusion.

The PIC CPU has a single working register. The working register is where you actually make it do useful things by performing copy, compare or calculate operations. Generally speaking most of a microcode program’s efforts are spent moving data (or the contents of registers) to/from the working register.

Next it is true that by using PIC’s on-board perpherials you can get it to do more than one thing at a time. However, its also true that your program always has to be doing something, and whatever that something is, it can’t be doing anything else. To start an independent process on a PIC, your program must set up the proper registers and then set the perpherial action in motion. Once that is done, you can then go on to do other things with your program.

Finally interrupts are just that. When an interrupt occurs, your program stops doing whatever it was doing and is sent to an ‘interrupt vector’ (in PIC that means line 4 of your program) and starts executing the code you have written there. Interrupt processes are under complete control of the programmer. That means you have to figure out what caused the interrupt, what to do about it, and how to gracefully resume your program where it left off. Its a lot easier said than done, but you can do it.

Let explain the idea with a simple example. Say you have a PIC and you want it to monitor two motors, each with a sensor. The aim is to keep the motors running at a constant speed. One classic approach to this situation is to use a timer to trigger an interrupt.

Lets say you decide that monitoring the motors every 25mS is good enough for your application. Just preset a timer to overflow after 25mS and use that overflow to generate an interrupt. Next set the program to go into an infinite loop where it will stay until it is interrupted.

When interrupted, your code then goes out and reads the status of both sensors (one at a time of course), and compares the readings to some constant that represents the desired speed. It can then update the PWM settings as needed.

Once the motors are updated, you next reset the interrupt registers so they will work again, restart the timer and set the program back into its infinite loop. It will remain in the loop until the next interrupt and the whole thing repeats.

When running the program it will appear as if the PIC is controlling both motors (or any reasonable number of things) all at once. In reality its doing them one at a time. However, since the PIC processes instructions so quickly it appears as if its all happening at once.

This approach is far too simple to be used to run a complex robot. But the intention was to give you an idea of how to use the basic parts of a microcontroller to make it appear as if it is actually monitoring and controlling several things all at once. You can build on the idea. Do a little research and testing and I’m sure you’ll be able to make it all work. Enjoy!

Hope this helps. Have a safe and Happy 4th of July eveyone!
KHall

how i miss the NXT for this thing and this thing only compared to Vex:
task main()
{
//run at same time
}

task coolio()
{
//run at same time as main()
}

Ah, timers, I remember those from my llscript days…

so, does easyc 2 or pro have a timer function? I don’t think so. I’m saving up for MPlab anyways because I used to do a lot of terminal window apps using c++, and want to get in touch with my inner skills… however, I know pro allows you to type in your own c, too.

“Saving Up” what??? MPLAB is free to download and use for Non-Profit use.

Use MPLAB with your mcc18 compiler that comes with EasyC, or Download the mcc18 compiler by itself (the Student Version of mcc18 is avalible at jvex-robotics, Microchip only seems to have the Upgrade Version of mcc18).

EasyC Pro is not as flexible as MPLAB. In MPLAB, you can build whatever kind of robot you want, but using EasyC, there are limits to how you can build your machine.

I would prefer MPLAB, but EasyC Pro is a great program.

how do you “link” mplab to the mcc18 compiler that came with easyc? mplab looks really nice…