Page 1 of 1

Programming Issues for C for EV3 (EVC, EV3-C)

Posted: 18 Dec 2013, 14:06
by devirex
Hello,

I'm playing around with the C api for EV3 (EVC or lms_api). I've some problems with the motor count. Everytime the motor stops the count is resetted to 0.
This happens when the "opOutputStop" Byte Code is written to the PWMDevice. Both functuions Off(output) and OffEx(output, reset) uses this function so the motorcount is always resetted. Is there another way to stop a motor without resetting the count?

Regards

Re: Programming Issues for C for EV3 (EVC, EV3-C)

Posted: 18 Dec 2013, 15:00
by HaWe
what is
Off(OUT_A)
doing ?

Re: Programming Issues for C for EV3 (EVC, EV3-C)

Posted: 18 Dec 2013, 15:20
by devirex
Hello,

Off(OUT_A) stops motor A and turn the brake on.

Re: Programming Issues for C for EV3 (EVC, EV3-C)

Posted: 18 Dec 2013, 16:44
by HaWe
no - what is it doing with the encoders to your observation?

BTW, according to NXT/NXC issues it was a good advice not to use or even manipulate TachoCount but always just RotationCount for your personal programs -
the reason was, TachoCount has been used by the FW always for internal calculations and so there always have been severe interferences with user program settings.
I guess there still might exist similar issues for JH's ev3 lms_api.

Re: Programming Issues for C for EV3 (EVC, EV3-C)

Posted: 19 Dec 2013, 18:16
by devirex
Hello,

I used MotorTachoCount insted of MotorRotationCount and that was the failure.
Thanks for your help

Re: Programming Issues for C for EV3 (EVC, EV3-C)

Posted: 19 Dec 2013, 18:59
by HaWe
:)

Re: Programming Issues for C for EV3 (EVC, EV3-C)

Posted: 22 Dec 2013, 16:57
by desperado50
Hello;

im learning to programm EV3 with Bricx. I wrote a simple code (thanks to devirex) and successfully downloaded and run it on EV3 from the BricxCC. The problem is that i dont know how to run it from the EV3 after downloading?
With the bricxCC EV3 memory explorer i see that code is on the brick though doesnt have extension. When i double click on the file (again from the explorer) the program starts. But i cant see that file from the EV3; it does not show it.
Additionaly; can somebody wrote a few functions with motor tacho (mentioned before in topic)?

Thanks a lot for all in advance!

Re: Programming Issues for C for EV3 (EVC, EV3-C)

Posted: 23 Dec 2013, 10:11
by devirex
Helllo,

here is how to run EVC programs from the EV3 menue. If you have only one EVC program that you want to run you can follow the instructions of the second link.
Compile a lms Script with LMSASM tool.
Here is a tutorial and the code:
http://www.robotnav.com/run-programs-without-network/
Here is a Tutorial of LSASM tool:
https://sourceforge.net/apps/phpbb/mind ... f=3&t=2041



If you want to have a complete overview of the lms_api(EVC) funtions look at "ev3_output.h".
An example of using the RotationSensor is in "ex_RotateMotor.c" in lms_api(EVC) folder.
I use the RotationSensors like this example:

Code: Select all

 
includes...

int main() {
  
     if (!OutputInit())
     {
          printf("doh!\n");
          return -1;
     }
     SetPower(OUT_AB, 70);                               //set power for motors A and B to 70
     Fwd(OUT_AB);                                        //set direction for motors A and B to forward.
     On(OUT_AB);                                         //start motors A and B 
     //OnFwd(OUT_AB);                                    //would do the the same two things above
     while(MotorRotationCount(OUT_A)  <= 720)        
     { 
        wait(1);                                         //Wait while motor A is turning to 720 degree.
     }
     ResetRotationCount(OUT_A);                          //setRotationCount to 0
     RotateMotor(OUT_C, 75, 360);                        //rotate motor C to 360 degrees while motors A and B still running
     while(MotorRotationCount(OUT_A)  >= 720)       
     { 
        wait(1);                                         //Wait while motor A is turning to 720 degrees again.
     }
     Off(OUT_AB);                                        //Stop motor A and B with brake.

I also found out that there are some problems with pthreads and motor rotation counts.
So lets say if you put the rotation of motor C in a different pthread you will have problems with reading the exact MotorRotationCount in real time. (missmatch between 0 and 6 degrees).
Also i could see that there are problems with the synchronization of the motors. Without pthreads the motors are running synchronous. With threads one of them is slower.

This is only the way i use the API so maybe some functions are not used as designed by the developer. I think there is no official documentation about it so far, so i found out all of that code by myself.

Regards

Re: Programming Issues for C for EV3 (EVC, EV3-C)

Posted: 23 Dec 2013, 16:09
by desperado50
Wow, man thanks a lot for all that info! Unfortunately, in a next week or so i will not be able to programm EV3. I'll have to be patient and continue next year.

Best wishes for hollidays!!