Solved: Error with EV3 Motors using BricxCC

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
endojo
Posts: 12
Joined: 06 Oct 2013, 16:48

Solved: Error with EV3 Motors using BricxCC

Post by endojo »

I have a weird problem regarding using the motors of my EV3.
After setting up BricxCC and codesourcery (which wasn't difficult at all after I've found the right tutorial) everything worked as expected - I tested all 4 test-samples and there was no problem.
(I am using the lms-api to communicate with the brick)

But when trying to write my own programs there seemed to be random crashes of the ev3 brick. It freezes executing one command forever (or until I force it to restart).
It took me some time until I noticed that RotateMotor was responsible for the crashes. And that's where it's getting strage: The output_test worked fine.
So after some more testing the reason was clear: RotateMotor does only work with 2 or all 4 outputs. E.g. RotateMotor(OUT_A, 20, 360) crashes, while RotateMotor(OUT_BD, 20, 360) doesn't.
But since it looks like a very simple and convincing way of rotating one motor for the giben amount of degrees I'd like to use it. (On(OUT_A) works)

Thus I conclude that there's a bug in the lms-api, or I need some alternative firmware (I searched for it but didn't found a EFW for EV3 - i use just V1.03H)

So if anyone has an idea to fix that problem, feel free to post it as I don't have a clue regarding how lms-api works.
There was an error with the LEGO Mindstorms API, which made the EV3 crash when trying to use RotateMotor, OutputStepSync or similar on anything other than exactly 2 motors.
But thanks to John Hansen this problem was solved. Make sure to use his newest API: http://bricxcc.sourceforge.net/test_releases/
and update the Makefile Template in Preferences->Compiler->EV3 to:

Code: Select all

PROGRAM=%PROGRAM%
DOBJECTS=%DOBJECTS%
TOOLPREFIX=%TOOLPREFIX%

all:: realclean $(DOBJECTS) $(PROGRAM)

download:: all

#pscp -scp -pw "%PW%" %PROGRAM% root@%IPADDR%:%FOLDER%

clean::
   rm -f *.o *.ppu *.rst

realclean:: clean
	rm -f $(PROGRAM)

FLAGS=%FLAGS%
LDFLAGS=-Wl,-R/media/card/lib

CC=$(TOOLPREFIX)%CCNAME%

# how to link executable
%PROGRAM%: %MAINSRC%
	$(CC) $(FLAGS) $(LDFLAGS) $< -o$@ %LINKOBJS%

# how to compile source
%.o: %%EXT%
	$(CC) $(FLAGS) %LINKONLY% $< -o$@
That should solve the problem.
Last edited by endojo on 08 Oct 2013, 19:29, edited 1 time in total.
pepijndevos
Posts: 175
Joined: 28 Dec 2011, 13:07
Location: Gelderland, Netherlands
Contact:

Re: Error with EV3 Motors using BricxCC

Post by pepijndevos »

I think I hit the same problem: https://sourceforge.net/apps/phpbb/mind ... 968#p17205

The motor port might give a clue. I seem to remember reading that 2 of the 4 ports are directly connected to some piece of hardware, while the other 2 are not.

Maybe you can spot the bug in the source code? :D Maybe here: https://github.com/mindboards/ev3source ... 08/d_pwm.c
-- Pepijn
http://studl.es Mindstorms Building Instructions
endojo
Posts: 12
Joined: 06 Oct 2013, 16:48

Re: Error with EV3 Motors using BricxCC

Post by endojo »

Is the code you have posted part from the mindstorms ev3 firmware?
Because then I can do probably nothing about that but a workaround. (I won't set up a virtual machine, clone that repo and try to understand all that code just for fixing a bug)

But on the other hand - if that is really a such low-level problem, why is then NXT-G able to use the same funciton on one motor? (I think the motor block equals on OS Level the RotateMotor Command)

But thank you for the tip, you will save me a lot of time for not going to trial & error with those commands.


P.S.: As I read your thread I noticed: You don't have to remove a battery, holding the back, middle and left button on the EV3 restarts it ;)
gloomyandy
Posts: 323
Joined: 29 Sep 2010, 05:03

Re: Error with EV3 Motors using BricxCC

Post by gloomyandy »

In terms of the hardware. I think you are mixing up the Sensor ports with the motor ports. The motor ports are pretty much identical (two pairs one pair on a chip). The sensor ports are different ports 1 and 2 have hardware UARTS ports 3 and 4 use a software UART using the DSP features of the TI processor.

Andy
endojo
Posts: 12
Joined: 06 Oct 2013, 16:48

Re: Error with EV3 Motors using BricxCC

Post by endojo »

Well - then it seems logical that commands like rotating for a given angle crashes but just turning a motor on doesn't.
But now it seems even more odd to me why something like RotateMotor(OUT_AC,...) works and the same with OUT_A or OUT_C does not.

Right now I am a bit confused why nearly nobody else is complaining about those bugs - the official release of EV3 was more than a month ago and there aren't that many alternatives to bricxCC.
And while the technical details aren't uninteresting, I would be glad if someone could bring up a solution or at least confirm this bug.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Error with EV3 Motors using BricxCC

Post by HaWe »

I not even got "hello world" running yet ;)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Error with EV3 Motors using BricxCC

Post by HaWe »

if you post the complete code and the list of files to be included by the project manager I can try to test it!
endojo
Posts: 12
Joined: 06 Oct 2013, 16:48

Re: Error with EV3 Motors using BricxCC

Post by endojo »

That would be great!

That's the code:

Code: Select all

#include <stdio.h>
#include <unistd.h>

#include "ev3_output.h"
#include "ev3_timer.h"
#include "ev3_command.h"

int main()
{

  int i;

  printf("hello world\n");

  printf("start of out_test\n");
  Wait(SEC_1);

  // initialize
  if (!OutputInit())
    printf("output init returned false\n");

  ResetAllTachoCounts(OUT_ABCD);
  OutputSetTypes(DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO);


  RotateMotor(OUT_AB, 75, 360);  //works
  //RotateMotor(OUT_A,75, 360);  //crashes

  printf("Wait(SEC_5)\n");
  Wait(SEC_5);

  OutputClose();
  OutputExit();
  printf("end of out_test\n");

  return 0;
}
You need to add ev3_output.c, ev3_timer.c and ev3_command.c to the dependencies or whatever it is called.

As you posted that you've problems with compiling: I got linker errors if my source code wasn't in the same folder like the includes - maybe another bug? :D

As a side note: What I understood is that the lms-api is just a temporary solution and will be replaced by the NXC / NQC Compiler when John Hansen added support for the EV3.
That would make things easier as there would be no more need for the codesourcery cross-compiler anymore.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: Error with EV3 Motors using BricxCC

Post by afanofosc »

What is not clear to me is what environment are you guys using to execute your code? Are you running with the VM shut down? In order to properly diagnose problems of this sort it is crucial to know every detail, no matter how trivial you may think it is. I can tell you, for certain, that if you are running with the VM shut down and you have not loaded all the LMS kernel modules in the correct order that there is a good chance that your motors will not work properly.

Also, RotateMotor is a bit of a hack at the moment. It implements a wait to force it to be synchronous. The underlying firmware opcodes are asynchronous and the RotateMotorNoWait routine is a better choice if you want to avoid possible API layer bugs.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Error with EV3 Motors using BricxCC

Post by HaWe »

I can only use the standard firmware by Lego with VM on (don't know how to kill it and if then USB would still work ).
I only have USB,
no WiFi, no LAN, no SD card.

I can confirm:
OUT_AB is fine, OUT_A blocks, hangs up, no response any longer.
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 27 guests