c4ev3 / ev3-api Goto Github PK
View Code? Open in Web Editor NEWEV3-API for Programming the LEGO Mindstorms EV3 in C
Home Page: http://c4ev3.github.io
License: GNU General Public License v2.0
EV3-API for Programming the LEGO Mindstorms EV3 in C
Home Page: http://c4ev3.github.io
License: GNU General Public License v2.0
does c4ev3 support bluetooth messaging betwen two ev3 bricks?
In the Commands PDF under Outputs (Motoren) and help, it says that the parameter "<Speed>" is a char between 0 to 100...
This should be int instead...
Hi,
I think that it is impossible to override ev3_timer's timer_interval_mutliplier
once TimerInit()
is called. If TimerInit()
is called again, it will remove the already registered handlers. This means that currently the interval is locked to 250 ms because that is what ev3_lcd
sets it to.
Best regards,
Jakub
Hi,
I'm trying to use the API but nothing happens when I launch the program from the Brick, or from the ev3duder.
I'm working under Debian Stretch.
The program, test.c :
#include <stdio.h>
#include <stdlib.h>
#include <ev3.h>
int main(void) {
InitEV3 () ;
PlayTone ( SOUND_DOUBLE_BEEP, 500 ) ;
LcdInit() ;
LcdClean() ;
LcdPrintf ( 1, "toto" ) ;
sleep ( 2 ) ;
FreeEV3 () ;
return EXIT_SUCCESS;
}
Compiler config:
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/arm-linux-gnueabi/6/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../src/configure -v --with-pkgversion='Debian 6.3.0-18' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-armel-cross/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-armel-cross --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-armel-cross --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libgcj --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-sjlj-exceptions --with-arch=armv4t --with-float=soft --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux- gnueabi --program-prefix=arm-linux-gnueabi- --includedir=/usr/arm-linux-gnueabi/include
Thread model: posix
gcc version 6.3.0 20170516 (Debian 6.3.0-18)
Command used for compiling:
arm-linux-gnueabi-gcc test.c -static-libstdc++ -o test -I../ev3-api/API ../ev3-api/API/libev3api.a
Compiler version:
Commands used to transfer the program to the Brick:
ev3duder up test ../prjs/BrkPrg_SAVE/test
ev3duder mkrbf ../prjs/BrkPrg_SAVE/test test.rbf
ev3duder up test.rbf ../prjs/BrkPrg_SAVE/test.rbf
Despite everything seems fine, nothing happens when I launch the program on my EV3 brick.
Am I missing something?
Regards,
Fabien
When printing on the lcd with LcdPrintf() and then clearing it with LcdClean() seems to always skip the rest of the program that still needs to be run on the EV3.
I'm interested in doing a rewrite of ev3_output.c, and I noticed that some of the functions took an owner
parameter, but I have no idea what this does. They set OutputInstance.Owner to whatever is passed to the function, but the only defined value for this to be is OWNER_NONE
which resolves to zero. Can this be safely removed from the API?
InitEV3 and setallsensormode must be called in this fixed order.
Sometimes, newbies and students and others do mix both vice versa and got unexpected program results.
There is a strong wish, to init the EV3 from setallsensormode if this is not done before.
Thanks in advance
J. Abke
The 4th mode of the color sensor "RGB" is not supported. You can use it to read the actual R, G and B values and not only one out of 7 colors. It's also not officially supported by lego but there is a way to use it in the official software: http://mindcuber.com/mindcub3r/mindcub3r.html
Monobrick supports it, too: https://github.com/Larsjep/monoev3/blob/release/MonoBrickFirmware/Sensors/EV3ColorSensor.cs
Hi there,
I have an issue with the LcdClean() function.
If I call the function, everything is fine and the display of the EV3 gets cleared.
But when I use the function LcdPrintf() afterwards to cursor position has not been reseted.
In other words: If the screen is completly full with text and I use the LcdClean() function the screen gets cleard but I can't print output text anymore.
Has someone also had this issue or knows how to fix it?
Thanks for your answers.
BTW: The project C4EV3 is very nice but for newbies it is quite hard to install the whole thing and also the commands.pdf didn't help me that much.
Trotzdem riesiges Lob an die Entwickler dieses Projekts und vielen Dank für eure Mühe.
Benutze C4EV3 aktuell für meine Maturaarbeit (Semesterarbeit in der Schweiz auf der Sekundarstufe II) und war begeistert, dass ich den Roboter in C programmieren konnte, da ich schon seit längerem C lernen wollte.
Hello,
I'm rewriting ev3sensors for better maintainability and I've stumbled around a problem. The code for decoding fetched measurements is very hard to understand.
case GYRO_ANG:
case GYRO_RATE:
help = *(data)&0xFFFF;
if(help & 0x8000)
{
help = ((help&0x7FFF) - 0x7FFF);
}
return help;
After about an hour of thinking, I've finally discovered how it works:
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
int main(int argc, char **argv) {
if (argc != 2) {
puts("bad argc");
return 1;
}
uint16_t data = (int16_t)strtol(argv[1], NULL, 10);
int32_t help;
int retval;
// ANALYSIS
help = data; // help = 0b_XYYYYYYY_YYYYYYYY
printf("data: %x\n", help);
if (help & 0x8000) { // 0b_1YYYYYYY_YYYYYYYY
// 0b_0YYYYYYY_YYYYYYYY
int32_t masked = help & 0x7FFF;
printf("masked: %x\n", masked);
// 0b_0!!!!!!!_!!!!!!!!
int32_t inverted_sub = 0x7FFF - masked;
printf("sub: %x\n", inverted_sub);
// 0b_1YYYYYY_YYYYYYYYY + 1
help = -inverted_sub;
printf("minus: %x\n", help);
}
retval = help;
// BETTER VERSION
int16_t mine = (int16_t)data;
if (mine < 0) mine++;
printf("f(%d) -> %d\n", (int32_t)data, retval);
// printf("f(%lx) -> %x\n", data, retval);
printf("g(%d) -> %d\n", (int32_t)data, mine);
}
It increments each negative number by one.
Why is this operation necessary? Does NXT HT Gyro have two zero points?
Why couldn't simple if branch be used? Is the performance that bad?
Hi,
I'm trying to use a NXT ultrasonic sensor on the EV3 using C4EV3. From what I understand, this is an IIC sensor, therefore, I was not suprised for it not to work (always reading 0) as a US_DIST_CM sensor, which seems to be UART.
While going through C4EV3 source code, it seems the IIC is not fully implemented (commented //ioctl(g_iicFile, IIC_SET_CONN, &devCon); in ev3sensor.c). I just need to read the distance in cm from NXT ultrasonic sensor, so I'm trying to implement "by hand" the required function, but when trying to read it using readIicSensor(IN_4), seems I always get the value "66" in the address returned by the function.
Some help would be very welcome here.
Manu
Hi everyone,
I'd like to know which licenses can I use for a project which makes use of this project by compiling user programs with it. Particularly, I'd like to know if I can use GPL 3.0 for the engine.
I'm confused by that this project is released under the terms of the Mozilla Public License Version 1.1 and GNU General Public License for the Sensors-API.
Is it even legal to distribute a program which makes use of both parts (i.e. linking code covered by two incompatible licenses together)?
Hi everyone,
I think I found a bug in ev3_times.c
, but I'm not sure if I understand it correctly. I have problem with the timer_interval_mutliplier
global variable. I think that it contains the interval in centiseconds that there is between two SIGALRM signals. However, then I think that the following code should have a different comparison:
Lines 152 to 159 in 9a43708
I interpret it like this:
If the comparison was timer_interval_mutliplier > TIMER_100MS
, it would make more sense to me, though it is still not 100 % bug free:
TIMER_*
constants, then this should be non-issue.However the intent could also be to disable the slow handlers altogether with counter % TIMER_100MS == 0 && timer_interval_mutliplier <= TIMER_100MS
:
What do you think?
Best regards,
Jakub
The default hello world program compiled without errors, and also the uploading works great, but the brick does not print the hello world. It shows the windows the robot is executing something, but the brick does not show Hello World. Thanks for helping...
When I use the c4ev3 eclipse ide plugin, I noticed that the files "inputs" and "sensors" were not downloaded and included. This means I can't use functions like ReadHTCompassSensor()
etc. Is this intended as functions like ReadSensor()
should do the job? or should I download the non-included files and include them manually?
How do I play a sound? There is no documentation on that in commands.pdf.
I ran into the problem mentioned in #13 concerning LcdClean() where it doesn't reset the cursor position. I've created a program to demonstrate the problem:
#include <ev3.h>
int main() {
InitEV3();
LcdPrintf(1, "Hello World!\n");
Wait(1000);
LcdClean();
LcdPrintf(1, "I am a line farther down than I should be.\n");
Wait(2000);
FreeEV3();
return 0;
}
I realize that this might break code for a small subset of users, but it would be an easy enough fix as long as they find out about it.
Update: It has since turned out, the MPL1.1 licensed parts are infringing on GPL-2.0 parts of the original LEGO Firmware, thus the only compatible license choice we have
is GPL-3.0-or-later as that's the one used for the sensor code. It would be nice if we could've GPL-2.0-or-later however.
Permission of following authors needed to relicense as GPL-2.0-or-later
Since mid 2016, we have been redistributing binary packages of the EV3-API along with the c4ev3 toolchain, which have been downloaded nearly 10.000 times and, according to feedback, found quite some users in introductory programming courses around the world.
It has come to my attention, however, that this redistribution was a license violation: The Mozilla Public License (MPL) 1.1 used for parts of the API originally created by John Hansen is incompatible with the GNU General Public License (GPL) 3.0 used for the sensors API and likely some of the other files that were written after exposure to the lms2012 GPL-2.0-or-later licensed headers.
To respect the authors original copyright, I've since taken down our binary downloads. I am not a lawyer, but my interpretation is that users may still use the self-built library,
but they are also not legally allowed to redistribute their results.
I'd like to ask the copyright holders on the MPL-1.1 licensed code to relicense their code as MPL-2.0. The MPL-2.0 is explicitly compatible with the GPL-2.0 and the GPL-3.0, so we could continue to provide binary downloads and integrate code from other GPL-licensed projects.
Contributors to MPL-1.1 code and whose permission is required:
Why not relicense the GPL parts? The lms2012 software used in the LEGO firmware is itself licensed under the GPL-2.0-or-later, so it makes most sense to have a license that's compatible to it.
What happens if not all copyright holders agree to relicense all their current contributions to the EV3-API under the new license? As I don't actively develop this (and never really did, I did mostly the Toolchain/Uploader part), it's unlikely that we'll reimplement the missing functionality. In this case, binary downloads will not be reinstated to respect the original authors' copyright.
Is there another way? I don't see any. I am not a lawyer and open to discussion.
Thanks for reading.
I have question about compiled file.
When i compile file on ev3 exists .elf file, but ev3 can't start that file and I see that file only when connect ev3 with computer.
Does anyone know how to solve this problem?
hello,
as you wrote,
The basis of this API was developed by John Hansen and Carsten Zeiffert. These API's were merged and extended.
I am curious if it would be possible to use the small and handy BricxCC IDE, also developed by John Hansen and Dave Baum, which already ever worked fine both for the NXT (NXC) and EV3/gpp. IMO, Eclipse is far too complicated to use and not suitable for beginners. OTOH, BricxCC also provides editing, compiling, linking by makefile, uploading via USB and BT, and also provides lots of additional Brick tools.
The documentation of the commands says, that the is of type int in range 0-100 but rotating motors backwards is actually achieved by using a negative which was not quite easy to see from the documentation.
This should be targeted.
I have had troubles with the EV3 sensor, specifically with the function ReadEV3ColorSensorReflectedLight() which takes around 20 to 30 milliseconds to get a lecture of the sensor, I do not know why is too slow to get the data from the sensors. I measured the performance, seeing the times the sensor was read in one second inside a loop. Furthermore, I am working with the latest API and with the Windows installer code sorcery. I am using eclipse IDE to program some code to link with the libev3api.a library.
Hi,
I'm thinking about how to solve the problem with timers interrupting running syscalls.
SA_RESTART
Best regards,
Jakub
Hi.
Is it possible to use this lib to communicate the EV3 Brick with an external board (like arduino) via usart or i2c? Thanks
I'm trying to get a Hitechnic Color Sensor V2 to work, but only the color number mode is working so far.
Here is, what I've done:
In file ev3sensor.h
following lines were added:
//HiTechnc Color V2
#define HT_COL2_COL 30 // Color
#define HT_COL2_RED 31 // Red
#define HT_COL2_GRN 32 // Green
#define HT_COL2_BLU 33 // Blue
#define HT_COL2_WHT 34 // White
#define HT_COL2_RAW 35 // RGBW - Raw
#define HT_COL2_NRM 36 // RGBW - Normalized
#define HT_COL2_ALL 37 // CRGBW
In file ev3sensor.c
the lines in section sensor setup were added. The values were taken from Lego's firmware (version 1.09) documentation:
//HiTechnc Color V2
#define HTC_TYPE 54
#define HTC_MODE_COL 0 // Color
#define HTC_MODE_RED 1 // Red
#define HTC_MODE_GRN 2 // Green
#define HTC_MODE_BLU 3 // Blue
#define HTC_MODE_WHT 4 // White
#define HTC_MODE_RAW 5 // RGBW - Raw
#define HTC_MODE_NRM 6 // RGBW - Normalized
#define HTC_MODE_ALL 7 // CRGBW
In function ReadSensorData
the switch statement has been extended by following cases:
case HT_COL2_COL:
return readIicSensor(sensorPort);
case HT_COL2_RED:
return readIicSensor(sensorPort);
case HT_COL2_GRN:
return readIicSensor(sensorPort);
case HT_COL2_BLU:
return readIicSensor(sensorPort);
case HT_COL2_WHT:
return readIicSensor(sensorPort);
case HT_COL2_RAW:
return readIicSensor(sensorPort);
case HT_COL2_NRM:
return readIicSensor(sensorPort);
case HT_COL2_ALL:
return readIicSensor(sensorPort);
and in function ReadSensor:
case HT_COL2_COL:
return *((DATA8*)data);
case HT_COL2_RED:
return *((DATA8*)data);
case HT_COL2_GRN:
return *((DATA8*)data);
case HT_COL2_BLU:
return *((DATA8*)data);
case HT_COL2_WHT:
return *((DATA8*)data);
(the missing cases will be handled by function ReadSensorData)
I successfully compiled the API with the included make file and wrote a simple test program like follows:
#include <ev3.h>
#include <basictypes.h>
int main(void)
{
int i;
char str[32];
InitEV3();
setSensorMode(IN_3, HT_COL2_GRN);
Wait(MS_500);
for (i=0; i<10; i++)
{
LcdClearDisplay();
LcdSelectFont(2);
sprintf (str, "%i", ((DATA8*)readSensorData(IN_3))[0]);
LcdText(1, 50, 50, str);
Wait(MS_500);
}
FreeEV3();
return 0;
}
Whatever mode I used in function setSensorMode
- I always got a color number. Then I changed the sensor mode with Lego's EV3-G software. Now I got a four byte result, which presumably has been the values for RGB + White.
But:
These values never changed. Whenever I started the program, the same values were delivered. Obviously the sensor wasn't polling for new values.
What am I missing? It seems that function setSensorMode
doesn't work at all for IIC sensor types. I'm wondering, if it works for the NXT_TEMP type, which is also an IIC sensor and has two modes. I don't have such, but was this ever tested?
Any help to fix this problem is welcome!
Many thanks in advance,
Rainer
One thing that bugs me with this project is the lack of consistency.
You have some files like ev3_xxx (eg. ev3_button), some files like ev3xxx (eg. ev3sensor) and some files like xxx (eg. analog).
Along with this, although all the function names are camelcased some start with capital letters (eg. LcdClean) while others dont (eg. readSensor)
Finally, some functions take char's when needing a small number (eg. LcdPrintf) while others take byte's (eg. SetLedPattern) [imo. You should either use int's or enums instead of worrying over getting the smallest value possible]
This is a really great project (probably one of the best and most maintained attempts at C for native EV3 [no new OS or anything]) but I believe it should be a bit more consistent with its naming.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.