EV3 "Hello World!" program
EV3 "Hello World!" program
I went trough the process of creating and running a simple C-program for the EV3. I wrote a simple tutorial at:
http://www.robotnav.com/ev3/
http://www.robotnav.com/ev3/
Last edited by lvoc on 20 Nov 2013, 15:11, edited 3 times in total.
Re: EV3 "Hello World!" program
Have you seen my BricxCC videos on this subject?
http://www.youtube.com/watch?v=7X_uV4oh1Yc
John Hansen
http://www.youtube.com/watch?v=7X_uV4oh1Yc
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: EV3 "Hello World!" program
Yes, I saw it. I could not quite figure how to set up the compiler. Also I wanted to do try it in Linux that I am more familiar with.
Lauro
http://www.robotnav.com
http://www.robotnav.com
Re: EV3 "Hello World!" program
Is there a way to control the motors and sensors via C?
Re: EV3 "Hello World!" program
An API to allow you to control motors, sensors, LCD, LEDs, Buttons, Sounds, etc... is a work in progress. You can start with my lms_api.zip in the BricxCC test_releases folder. I still need to incorporate Xander's work on sensor API functions.
John Hansen
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: EV3 "Hello World!" program
I added some "basic" instructions of how to use the motors using the Linux way for interacting with external devices
http://www.robotnav.com/motors/
Lauro
http://www.robotnav.com/motors/
Lauro
Last edited by lvoc on 17 Oct 2013, 19:44, edited 2 times in total.
Lauro
http://www.robotnav.com
http://www.robotnav.com
Re: EV3 "Hello World!" program
I would really recommend showing people how to use an API layer that completely hides the interaction with the low level devices.
http://bricxcc.sourceforge.net/test_rel ... ms_api.zip
John Hansen
http://bricxcc.sourceforge.net/test_rel ... ms_api.zip
Code: Select all
/*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Initial Developer of this code is John Hansen.
* Portions created by John Hansen are Copyright (C) 2009-2013 John Hansen.
* All Rights Reserved.
*
*/
#include <stdio.h>
#include <unistd.h>
#include "ev3_output.h"
int main()
{
int i;
printf("start of out_test\n");
Wait(SEC_1);
// initialize
if (!OutputInit())
printf("output init returned false\n");
ResetAllTachoCounts(OUT_ABCD);
SetPower(OUT_A, 90);
SetSpeed(OUT_B, 40);
SetPower(OUT_C, 60);
SetPower(OUT_D, -60);
On(OUT_ALL);
bool isBusy = false;
for(i=0; i < 10; i++)
{
printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));
printf("OUT_C: %d %d %d\n", MotorRotationCount(OUT_C), MotorTachoCount(OUT_C), MotorActualSpeed(OUT_C));
printf("OUT_D: %d %d %d\n", MotorRotationCount(OUT_D), MotorTachoCount(OUT_D), MotorActualSpeed(OUT_D));
Wait(SEC_1);
isBusy = MotorBusy(OUT_ALL);
printf("Any output isBusy = %d\n", (byte)isBusy);
}
printf("Float(OUT_ALL)\n");
Float(OUT_ALL);
printf("Wait(SEC_2)\n");
Wait(SEC_2);
printf("ResetAllTachoCounts(OUT_ALL)\n");
ResetAllTachoCounts(OUT_ALL);
OutputClose();
OutputExit();
printf("end of out_test\n");
return 0;
}
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: EV3 "Hello World!" program
John,
that's really fine, I love those "SetPower", "On" and "MotorBusy" commands, it's a really good work!
4 small remarks:
- I'd recommend to always prefer "coast" instead of "Float" because of semiotic confusion with "float"
- just out interest: in the source you are using MotorRotationCount to read encoders, but finally you reset the encoders by a ResetAllTachoCounts.
TachoCount always has been an issue to NXC because of obscured fw interferences, here I would love to have the differences and details of those counter variables a little more elaborated.
- Ivoc's motor device numbers defined as A = 1, B = 2, C =4, D = 8 appear to be very logical (e.g., 12 = 0x0C for OUT_CD); how did you set up the motor numbers and combinations?
... what about continue counting to remote motors (16, 32, 64, 128,...) to be able to access them just as if they were local?
- On the other hand, please let us talk again about the future design of relative and absolute motor position control including PID control.
that's really fine, I love those "SetPower", "On" and "MotorBusy" commands, it's a really good work!
4 small remarks:
- I'd recommend to always prefer "coast" instead of "Float" because of semiotic confusion with "float"
- just out interest: in the source you are using MotorRotationCount to read encoders, but finally you reset the encoders by a ResetAllTachoCounts.
TachoCount always has been an issue to NXC because of obscured fw interferences, here I would love to have the differences and details of those counter variables a little more elaborated.
- Ivoc's motor device numbers defined as A = 1, B = 2, C =4, D = 8 appear to be very logical (e.g., 12 = 0x0C for OUT_CD); how did you set up the motor numbers and combinations?
... what about continue counting to remote motors (16, 32, 64, 128,...) to be able to access them just as if they were local?
- On the other hand, please let us talk again about the future design of relative and absolute motor position control including PID control.
Re: EV3 "Hello World!" program
HaWe,
Regarding the motor number definitions, I did not come up with them, this is the way Lego uses and expects them.
See function Device1Write in https://github.com/mindboards/ev3source ... 08/d_pwm.c
The current kernel module (d_pwm) can only handle four motors. In order to use remote motors in the way you describe, you will need to create a new kernel module. I think, this can be better handled with a program at a user level.
Regarding the motor number definitions, I did not come up with them, this is the way Lego uses and expects them.
See function Device1Write in https://github.com/mindboards/ev3source ... 08/d_pwm.c
The current kernel module (d_pwm) can only handle four motors. In order to use remote motors in the way you describe, you will need to create a new kernel module. I think, this can be better handled with a program at a user level.
Last edited by lvoc on 20 Nov 2013, 15:17, edited 1 time in total.
Lauro
http://www.robotnav.com
http://www.robotnav.com
Re: EV3 "Hello World!" program
ok, thank you, I see!
But anyway how it might work on hardware level, the idea appears to be logic for the user-level:
OUT_CD=4+8=12 for simulataneously C+D local
OUT_CD2= 4+128=132 for simulataneously local-C + remote-D at brick2
OUT_CD2A3= 4+128+256=388 for simulataneously local-C + remote-D at brick2 + remote-A at brick3
for an isomorphism you may define
ABCD local
EFGH remote 1
IJKL remote 2
MNOP remote 3
QRST remote 4
UVWX remote 5
(..?..)
But anyway how it might work on hardware level, the idea appears to be logic for the user-level:
OUT_CD=4+8=12 for simulataneously C+D local
OUT_CD2= 4+128=132 for simulataneously local-C + remote-D at brick2
OUT_CD2A3= 4+128+256=388 for simulataneously local-C + remote-D at brick2 + remote-A at brick3
for an isomorphism you may define
ABCD local
EFGH remote 1
IJKL remote 2
MNOP remote 3
QRST remote 4
UVWX remote 5
(..?..)
Who is online
Users browsing this forum: Semrush [Bot] and 4 guests