EV3 "Hello World!" program

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
lvoc
Posts: 38
Joined: 10 Sep 2013, 13:34

EV3 "Hello World!" program

Post by lvoc »

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/
Last edited by lvoc on 20 Nov 2013, 15:11, edited 3 times in total.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: EV3 "Hello World!" program

Post by afanofosc »

Have you seen my BricxCC videos on this subject?

http://www.youtube.com/watch?v=7X_uV4oh1Yc

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
lvoc
Posts: 38
Joined: 10 Sep 2013, 13:34

Re: EV3 "Hello World!" program

Post by lvoc »

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.
dwalton76
Posts: 4
Joined: 09 Sep 2013, 04:40

Re: EV3 "Hello World!" program

Post by dwalton76 »

Is there a way to control the motors and sensors via C?
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: EV3 "Hello World!" program

Post by afanofosc »

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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
lvoc
Posts: 38
Joined: 10 Sep 2013, 13:34

Re: EV3 "Hello World!" program

Post by lvoc »

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
Last edited by lvoc on 17 Oct 2013, 19:44, edited 2 times in total.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: EV3 "Hello World!" program

Post by afanofosc »

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

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;
}
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: EV3 "Hello World!" program

Post by HaWe »

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.
lvoc
Posts: 38
Joined: 10 Sep 2013, 13:34

Re: EV3 "Hello World!" program

Post by lvoc »

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.
Last edited by lvoc on 20 Nov 2013, 15:17, edited 1 time in total.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: EV3 "Hello World!" program

Post by HaWe »

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
(..?..)
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests