Page 1 of 2

NXC Error : Invalid Opcode : stopthread

Posted: 28 Oct 2011, 17:42
by monxc
Hello,

I'm having a problem starting and stopping tasks with NXC that I was hoping somebody might be able to help me with, please?

I've written a task that tracks the heading of an autonomous vehicle and adjusts the steering based on the output of a compass sensor to keep the vehicle tracking in a straight line. My main() task starts a navigation() task using the Precedes() function, but I only want to start the tracking task when the vehicle is actually in motion, so I'm trying to do it like this:

Code: Select all

task truckNav()
{
  cntrSteer();
  taskBeep();
  StartTask(truckTracking);
  while(distF > 30)                 //have to allow for the coasting here - about 10cm on the flat!
  {
    truckFwd(75);                   //start moving forward at 75% motor power
  }
  StopTask(truckTracking);
  truckStp();
  endBeep();
  StopAllTasks();
}
...but, when I compile this, the NXC compiler complains that the StopTask() line contains the error "Invalid opcode: StopThread".

I assume I'm just starting/stopping the tasks incorrectly, but all the documentation seems to suggest that this is the way to do it - can anybody lend any help, please?

Thanks,

Paul

Re: NXC Error : Invalid Opcode : stopthread

Posted: 28 Oct 2011, 18:51
by afanofosc
The ability to stop a running task requires the enhanced NBC/NXC firmware and that you tell the compiler to target that firmware. That is why you are getting these compiler errors.

I may need to update the documentation to make this requirement clear.

John Hansen

Re: NXC Error : Invalid Opcode : stopthread

Posted: 28 Oct 2011, 20:25
by monxc
Hi John,

thanks for your reply.

I don't really want to change the firmware in my NXT, so I'll come up with some sort of work-around, I think...

Thanks for your help,

Paul

Re: NXC Error : Invalid Opcode : stopthread

Posted: 28 Oct 2011, 21:52
by afanofosc
Is there any particular reason why you don't really want to replace your firmware? The enhanced NBC/NXC firmware is fully compatible with the standard LEGO firmware and it fixes a large number of bugs in the standard firmware. For example, you cannot successfully use arrays of strings or any 2-d array with the standard firmware and several operations that involve floating point/integer mixed operations that will not work in NXC unless you use the enhanced NBC/NXC firmware. You can't use any of the sin/cos/tan functions or the array operations and starting a task with the start keyword or StartTask is a hack with the standard firmware which is not very reliable.

John Hansen

Re: NXC Error : Invalid Opcode : stopthread

Posted: 28 Oct 2011, 22:07
by monxc
Hi John,

the NXT unit I'm using isn't actually mine - I'm just borrowing it.

If somebody wanted to reprogramme the unit using NXT-G, would they still be able to?

Where can I get hold of the updated firmware? Can I upload it into the NXT using Bricx-CC?

Thanks for your help again,

Paul

Re: NXC Error : Invalid Opcode : stopthread

Posted: 28 Oct 2011, 22:17
by mattallen37
monxc wrote:...If somebody wanted to reprogramme the unit using NXT-G, would they still be able to?

Where can I get hold of the updated firmware?

Can I upload it into the NXT using Bricx-CC?...
Yes, the FW is fully backwards compatible.

It is included with the release of BricxCC

Yes, the downloader is in the tools menu.

Re: NXC Error : Invalid Opcode : stopthread

Posted: 28 Oct 2011, 22:27
by monxc
Hello,

OK, so I took a risk and flashed the firmware to version lms_arm_nbcnxc_131.rfw - the flashing process finished successfully, but now the NXT is unresponsive and just "ticks"...

How do I recover the NXT now?

Thanks,

paul

Re: NXC Error : Invalid Opcode : stopthread

Posted: 28 Oct 2011, 22:30
by mattallen37
If you are running the latest version of BCC, that shouldn't have happened. However, on the older versions, I never had it not happen. I always used to just do it twice. The first time it would tick, and the second it would do it successfully. Try it again.

Re: NXC Error : Invalid Opcode : stopthread

Posted: 28 Oct 2011, 22:35
by monxc
I'm running version 3.3.8.9 of BCC - is there a newer version?

I can't download the new firmware into the NXT again, as the NXT now won't turn on...it just ticks.


Paul

Re: NXC Error : Invalid Opcode : stopthread

Posted: 28 Oct 2011, 22:48
by mattallen37
Yes there is a newer version (3.3.8.10 test release from 10/24/11), but I think a new official release is due to be released this weekend.

Even though it doesn't appear to be on, it is, it's just booted in SAMBA.