EV3 BCC / C software problem(s)

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

EV3 BCC / C software problem(s)

Post by HaWe »

hi,
if I'm running out_test_cpp.cpp (in the API folder) then I get a compiler error:
out_test_cpp.cpp: In function 'int main()':
out_test_cpp.cpp:31: error: 'Wait' was not declared in this scope
make: *** [out_test_cpp] Error 1
Any ideas what's wrong here?

this is the code:

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("hello world\n");

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

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

  ResetAllTachoCounts(OUT_ABCD);

//  OutputSetType(OUT_A, DEVICE_TYPE_TACHO);
//  OutputSetType(OUT_B, DEVICE_TYPE_TACHO);
//  OutputSetType(OUT_C, DEVICE_TYPE_MINITACHO);
  OutputSetTypes(DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO);

  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);
  }
//  Wait(SEC_5);

  printf("Float(OUT_ALL)\n");
  Float(OUT_ALL);

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

  printf("ResetAllTachoCounts(OUT_ALL)\n");
  ResetAllTachoCounts(OUT_ALL);

  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));

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

  printf("RotateMotorNoWait(OUT_AB, 75, 7200)\n");
  RotateMotorNoWait(OUT_AB, 75, 7200);

  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));

  isBusy = MotorBusy(OUT_AB);
  printf("A or B isBusy = %d\n", (byte)isBusy);

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

  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("resetting all tacho counters\n");
  ResetAllTachoCounts(OUT_ALL);

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

  printf("OnForSync(OUT_AB, SEC_10, 75)\n");
  OnForSync(OUT_AB, SEC_10, 75);

  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));

    isBusy = MotorBusy(OUT_AB);
    printf("A or B isBusy = %d\n", (byte)isBusy);

    isBusy = MotorBusy(OUT_CD);
    printf("C or D isBusy = %d\n", (byte)isBusy);

    Wait(SEC_1);
  }

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

  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));

  // synchronized motor movement without tacho or time limitation
  printf("OnFwdSync(OUT_AB, 75)\n");
  OnFwdSync(OUT_AB, 75);

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

  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("Off(OUT_AB)\n");
  Off(OUT_AB); // stop with braking

  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("Wait(SEC_1)\n");
  Wait(SEC_1);

/*
 *  Turn ratio is how tight you turn and to what direction you turn
 *   - 0 value is moving straight forward
 *   - Negative values turns to the left
 *   - Positive values turns to the right
 *   - Value -100 stops the left motor
 *   - Value +100 stops the right motor
 *   - Values less than -100 makes the left motor run the opposite
 *     direction of the right motor (Spin)
 *   - Values greater than +100 makes the right motor run the opposite
 *     direction of the left motor (Spin)
 */

  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("OnFwdSyncEx(OUT_AB, 75, -20, RESET_NONE)\n");
  OnFwdSyncEx(OUT_AB, 75, -20, RESET_NONE);

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

  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("OnFwdSync(OUT_AB, 50, -50, RESET_NONE)");
  OnFwdSyncEx(OUT_AB, 50, -50, RESET_NONE);

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

  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("OnFwdSync(OUT_AB, 20, -100, RESET_NONE)\n");
  OnFwdSyncEx(OUT_AB, 20, -100, RESET_NONE);

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

  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("OnFwdSync(OUT_AB, 80, -150, RESET_NONE)\n");
  OnFwdSyncEx(OUT_AB, 80, -150, RESET_NONE);

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

  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("OnFwdSync(OUT_AB, 30, -200, RESET_NONE)\n");
  OnFwdSyncEx(OUT_AB, 30, -200, RESET_NONE);

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

  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("Off(OUT_AB)\n");
  Off(OUT_AB);

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

  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("ResetAllTachoCounts(OUT_AB)\n");
  ResetAllTachoCounts(OUT_AB);

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

  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));

  // a blocking version of RotateMotor (function call does not return
  // until the motor rotation is complete)
  printf("RotateMotor(OUT_AB, 75, 1800)");
  RotateMotor(OUT_AB, 75, 1800); // 5 rotations

  // by the time the function above returns the motors are no longer busy
  isBusy = MotorBusy(OUT_AB);
  printf("A or B isBusy = %d\n", isBusy);

  // this call starts the motors running Forward without regulation or
  // synchronization and the function call does not return until the
  // specified amount of time has elapsed.
  // at the end of the elapsed time the motors are stopped with braking.
  printf("OnFor(OUT_AB, SEC_3)\n");
  OnFor(OUT_AB, SEC_3);

  printf("Off(OUT_AB)\n");
  Off(OUT_AB);

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

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

  return 0;
}
Last edited by HaWe on 06 Dec 2013, 08:13, edited 1 time in total.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: EV3 BCC / C software problem(s)

Post by HaWe »

update:
If I use out_test_c.c instead, I get lots of errors:
c:\Temp\ccMywLlS.o: In function `main':
out_test_c.c:(.text+0x20): undefined reference to `Wait'
out_test_c.c:(.text+0x24): undefined reference to `OutputInit'
out_test_c.c:(.text+0x48): undefined reference to `ResetAllTachoCounts'
out_test_c.c:(.text+0x5c): undefined reference to `OutputSetTypes'
out_test_c.c:(.text+0x68): undefined reference to `SetPower'
out_test_c.c:(.text+0x74): undefined reference to `SetSpeed'
out_test_c.c:(.text+0x80): undefined reference to `SetPower'
out_test_c.c:(.text+0x8c): undefined reference to `SetPower'
out_test_c.c:(.text+0x98): undefined reference to `OnEx'
out_test_c.c:(.text+0xb4): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0xc0): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0xcc): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0xe8): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0xf4): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x100): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x11c): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x128): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x134): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x150): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x15c): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x168): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x184): undefined reference to `Wait'
out_test_c.c:(.text+0x18c): undefined reference to `MotorBusy'
out_test_c.c:(.text+0x1d0): undefined reference to `FloatEx'
out_test_c.c:(.text+0x1e0): undefined reference to `Wait'
out_test_c.c:(.text+0x1f0): undefined reference to `ResetAllTachoCounts'
out_test_c.c:(.text+0x1f8): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x204): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x210): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x22c): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x238): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x244): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x260): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x26c): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x278): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x294): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x2a0): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x2ac): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x2d0): undefined reference to `Wait'
out_test_c.c:(.text+0x2fc): undefined reference to `RotateMotorNoWaitEx'
out_test_c.c:(.text+0x304): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x310): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x31c): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x338): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x344): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x350): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x36c): undefined reference to `MotorBusy'
out_test_c.c:(.text+0x394): undefined reference to `Wait'
out_test_c.c:(.text+0x39c): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x3a8): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x3b4): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x3d0): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x3dc): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x3e8): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x40c): undefined reference to `ResetAllTachoCounts'
out_test_c.c:(.text+0x41c): undefined reference to `Wait'
out_test_c.c:(.text+0x440): undefined reference to `OnForSyncEx'
out_test_c.c:(.text+0x454): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x460): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x46c): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x488): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x494): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x4a0): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x4bc): undefined reference to `MotorBusy'
out_test_c.c:(.text+0x4dc): undefined reference to `MotorBusy'
out_test_c.c:(.text+0x4fc): undefined reference to `Wait'
out_test_c.c:(.text+0x524): undefined reference to `Wait'
out_test_c.c:(.text+0x52c): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x538): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x544): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x560): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x56c): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x578): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x5a8): undefined reference to `OnFwdSyncEx'
out_test_c.c:(.text+0x5b8): undefined reference to `Wait'
out_test_c.c:(.text+0x5c0): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x5cc): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x5d8): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x5f4): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x600): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x60c): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x634): undefined reference to `OffEx'
out_test_c.c:(.text+0x63c): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x648): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x654): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x670): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x67c): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x688): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x6ac): undefined reference to `Wait'
out_test_c.c:(.text+0x6b4): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x6c0): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x6cc): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x6e8): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x6f4): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x700): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x730): undefined reference to `OnFwdSyncEx'
out_test_c.c:(.text+0x740): undefined reference to `Wait'
out_test_c.c:(.text+0x748): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x754): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x760): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x77c): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x788): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x794): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x7c4): undefined reference to `OnFwdSyncEx'
out_test_c.c:(.text+0x7d4): undefined reference to `Wait'
out_test_c.c:(.text+0x7dc): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x7e8): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x7f4): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x810): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x81c): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x828): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x858): undefined reference to `OnFwdSyncEx'
out_test_c.c:(.text+0x868): undefined reference to `Wait'
out_test_c.c:(.text+0x870): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x87c): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x888): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x8a4): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x8b0): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x8bc): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x8ec): undefined reference to `OnFwdSyncEx'
out_test_c.c:(.text+0x8fc): undefined reference to `Wait'
out_test_c.c:(.text+0x904): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x910): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x91c): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x938): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x944): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x950): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x980): undefined reference to `OnFwdSyncEx'
out_test_c.c:(.text+0x990): undefined reference to `Wait'
out_test_c.c:(.text+0x998): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x9a4): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x9b0): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0x9cc): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0x9d8): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0x9e4): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0xa0c): undefined reference to `OffEx'
out_test_c.c:(.text+0xa1c): undefined reference to `Wait'
out_test_c.c:(.text+0xa24): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0xa30): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0xa3c): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0xa58): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0xa64): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0xa70): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0xa94): undefined reference to `ResetAllTachoCounts'
out_test_c.c:(.text+0xaa4): undefined reference to `Wait'
out_test_c.c:(.text+0xaac): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0xab8): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0xac4): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0xae0): undefined reference to `MotorRotationCount'
out_test_c.c:(.text+0xaec): undefined reference to `MotorTachoCount'
out_test_c.c:(.text+0xaf8): undefined reference to `MotorActualSpeed'
out_test_c.c:(.text+0xb38): undefined reference to `RotateMotorEx'
out_test_c.c:(.text+0xb40): undefined reference to `MotorBusy'
out_test_c.c:(.text+0xb74): undefined reference to `OnForEx'
out_test_c.c:(.text+0xb88): undefined reference to `OffEx'
out_test_c.c:(.text+0xb98): undefined reference to `Wait'
out_test_c.c:(.text+0xb9c): undefined reference to `OutputClose'
out_test_c.c:(.text+0xba0): undefined reference to `OutputExit'
collect2: ld returned 1 exit status
make: *** [out_test_c] Error 1
the code:

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("hello world\n");

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

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

  ResetAllTachoCounts(OUT_ABCD);

//  OutputSetType(OUT_A, DEVICE_TYPE_TACHO);
//  OutputSetType(OUT_B, DEVICE_TYPE_TACHO);
//  OutputSetType(OUT_C, DEVICE_TYPE_MINITACHO);
  OutputSetTypes(DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO);

  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);
  }
//  Wait(SEC_5);

  printf("Float(OUT_ALL)\n");
  Float(OUT_ALL);

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

  printf("ResetAllTachoCounts(OUT_ALL)\n");
  ResetAllTachoCounts(OUT_ALL);

  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));

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

  printf("RotateMotorNoWait(OUT_AB, 75, 7200)\n");
  RotateMotorNoWait(OUT_AB, 75, 7200);

  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));

  isBusy = MotorBusy(OUT_AB);
  printf("A or B isBusy = %d\n", (byte)isBusy);

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

  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("resetting all tacho counters\n");
  ResetAllTachoCounts(OUT_ALL);

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

  printf("OnForSync(OUT_AB, SEC_10, 75)\n");
  OnForSync(OUT_AB, SEC_10, 75);

  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));

    isBusy = MotorBusy(OUT_AB);
    printf("A or B isBusy = %d\n", (byte)isBusy);

    isBusy = MotorBusy(OUT_CD);
    printf("C or D isBusy = %d\n", (byte)isBusy);

    Wait(SEC_1);
  }

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

  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));

  // synchronized motor movement without tacho or time limitation
  printf("OnFwdSync(OUT_AB, 75)\n");
  OnFwdSync(OUT_AB, 75);

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

  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("Off(OUT_AB)\n");
  Off(OUT_AB); // stop with braking

  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("Wait(SEC_1)\n");
  Wait(SEC_1);

/*
 *  Turn ratio is how tight you turn and to what direction you turn
 *   - 0 value is moving straight forward
 *   - Negative values turns to the left
 *   - Positive values turns to the right
 *   - Value -100 stops the left motor
 *   - Value +100 stops the right motor
 *   - Values less than -100 makes the left motor run the opposite
 *     direction of the right motor (Spin)
 *   - Values greater than +100 makes the right motor run the opposite
 *     direction of the left motor (Spin)
 */

  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("OnFwdSyncEx(OUT_AB, 75, -20, RESET_NONE)\n");
  OnFwdSyncEx(OUT_AB, 75, -20, RESET_NONE);

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

  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("OnFwdSync(OUT_AB, 50, -50, RESET_NONE)");
  OnFwdSyncEx(OUT_AB, 50, -50, RESET_NONE);

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

  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("OnFwdSync(OUT_AB, 20, -100, RESET_NONE)\n");
  OnFwdSyncEx(OUT_AB, 20, -100, RESET_NONE);

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

  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("OnFwdSync(OUT_AB, 80, -150, RESET_NONE)\n");
  OnFwdSyncEx(OUT_AB, 80, -150, RESET_NONE);

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

  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("OnFwdSync(OUT_AB, 30, -200, RESET_NONE)\n");
  OnFwdSyncEx(OUT_AB, 30, -200, RESET_NONE);

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

  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("Off(OUT_AB)\n");
  Off(OUT_AB);

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

  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("ResetAllTachoCounts(OUT_AB)\n");
  ResetAllTachoCounts(OUT_AB);

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

  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));

  // a blocking version of RotateMotor (function call does not return
  // until the motor rotation is complete)
  printf("RotateMotor(OUT_AB, 75, 1800)");
  RotateMotor(OUT_AB, 75, 1800); // 5 rotations

  // by the time the function above returns the motors are no longer busy
  isBusy = MotorBusy(OUT_AB);
  printf("A or B isBusy = %d\n", isBusy);

  // this call starts the motors running Forward without regulation or
  // synchronization and the function call does not return until the
  // specified amount of time has elapsed.
  // at the end of the elapsed time the motors are stopped with braking.
  printf("OnFor(OUT_AB, SEC_3)\n");
  OnFor(OUT_AB, SEC_3);

  printf("Off(OUT_AB)\n");
  Off(OUT_AB);

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

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

  return 0;
}
pepijndevos
Posts: 175
Joined: 28 Dec 2011, 13:07
Location: Gelderland, Netherlands
Contact:

Re: EV3 BCC / C software problem(s)

Post by pepijndevos »

I had the same problem. Something with the includes is not right.
-- Pepijn
http://studl.es Mindstorms Building Instructions
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: EV3 BCC / C software problem(s)

Post by HaWe »

thank you for confirming this!
What might be the reason....?
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: EV3 BCC / C software problem(s)

Post by afanofosc »

As you can tell from the very first message in the compiler output window these are linker problems, not compiler problems. If they were compiler problems they would show up under the editor. Linker errors are fixed by adding source files to the project manager for your project. In this case, to successfully link out_test_c.c or out_test_cpp.cpp you need to add the right source files to your project using the project manager window. I did not include .prj files for all of the test code. Figuring out which files to add to the project manager is quite simple. You start with the source file associated with the included headers. Since this sample program includes ev3_output.h then it would seem logical to add (or verify that the project already includes) ev3_output.c. Then you can look at ev3_output.h to see which headers it includes. Add the .c file associated with those headers (if there is one) to the project manager for out_test_c.c. You might look in other sample code projects to see what they include. Alternatively, you can modify the makefile to link to the libev3.so shared library, in which case you would not need to add any source files to the project.

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

Re: EV3 BCC / C software problem(s)

Post by HaWe »

thanks, I see.
So far I had nothing to do with a linker or a makefile, I only knew that there existed sort of this.
1st) question: where did you hide the Wait() command?

But now here arises a couple of follow-up-questions:

First a comment in between - to my understanding a *.c file is a program file having a task or a procedure main(),
while *.h files are header files which are not executable but contain a library for frequently used functions or definitions, and further on the one and only *.c file is linked with the headers to an executabe file.


2) So why does a *.h header file need another *.c file (of the same name) and this *.c file needs even another a *.h header file which needs again any other *.c file to run (that seems to be odd and more than confusing) ?

3) Why do we need to have either of these *.c files which are not designed to be real program files, i. e., what actually is their job ?

4) Why is it not possible to merge all library code just into *.h header files which then could be simply #included into the main *.c program file code (either if they #include other *.h files by themselves which also could be simply #included)?

5) How can I modify makefile to make all this automatically?

6) Last but not least - why does this following super-simple program not run ?? I see it on the nxt screen after ctrl+F5, it does not start automatically, and if I start it manually the brick says
" ! Error! "

Code: Select all

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


int main()
{
   int i;

   printf("hello world\n");
   usleep(5000000);

   return 0;
}
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: EV3 BCC / C software problem(s)

Post by afanofosc »

If I get sufficiently motivated then all of the API layer will be completed and documented but at the moment I am feeling very unmotivated.

Regarding 1, I hid it in a file named after the NXT Command module, i.e., ev3_command.c.h. I didn't think it fit anywhere else. That is where you find Wait in the NXC API help:

http://bricxcc.sourceforge.net/nbc/nxcd ... tions.html

Regarding the comment prior to 2, your understanding is completely wrong about the C programming language or C++ or C# or Java etc... Some of those languages don't have the concept of a header file vs a source file but regardless a source file with a .c, .cpp, .cs, or .java extension may or may not have a "main" procedure in it. It is not necessarily a "program" file at all. Just a file with executable source code in it. There are virtually no programs written in any of these real programming languages that involve a single source code file and a single associated header file (if the language has such a concept).

In the land of not exactly or not quite real programming languages that don't support multiple source files linked together into a single executable then you are restricted to one source file and some number of headers. In the not really real land you may find "source code" in header files just because the language doesn't support linking. But in C and C++ it is generally considered (with some exceptions) to be bad form to put executable code in header files. This is more so in C than in C++ but still mostly true even in C++. It is also considered to be bad form to put all your source code into a single huge file. The header files describe the interface and the source files contain the implementation of the interface. A consumer of a source code library only needs the header files to know what functions can be called and what parameters those functions take. And they know that they have to link to the .o (compiled object code) or .so (shared library of compiled object code) provided by the author of the library.

So 2 is because that is just how things work in the real world of programming in C. 3 is because that's just how good programmers organize their source code and the job of those files is to contain in an organized fashion all the code needed to execute if a consumer of the API library calls one of the functions in the application programming interface (API) which is defined in the header files. 4 is that's just a bad idea but not impossible and if a programmer has access to source code they are free to organize it differently than the original developer designed things. 5 is perhaps with effort you could come up with a scheme to make all this happen automatically if you don't like the scheme I had in mind when I created the Project Manager tool. I don't know how you could modify the makefile to make all this happen automatically, other than have it link to libev3.so as I mentioned previously.

Regarding 6 I am befuddled. What do you mean by "nxt screen"? What do you mean by "the brick says "! Error!"? I can only assume you mean "EV3" when you say "NXT" but I am not certain that is a valid assumption on my part. To the best of my knowledge it is impossible to get the EV3 to say "! Error!" but I could be wrong. Native executables don't show up on the EV3 using the standard VM user interface.

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

Re: EV3 BCC / C software problem(s)

Post by HaWe »

hahaha, not already finished with reading this... world of not quite or not exactly hahaha, OMG, it's sooo funny !

Image

ps
edit: ok, right, NXT screen should mean ev3 screen as you assumpted....and there surely appears the error message "! Error!" if I try to execute the hello_world program! You doubt that?

I don't know how Icould modify the makefile to make all the linking of the *.c api helper files happen automatically, and also I don't know what you mean by other than have it link to libev3.so as you mentioned previously.
have it link to libev3.so as I mentioned previously??
link?
to libev3.so???
SO WHAT????
Please recall that me and the rest of approximately all over 99.999999% of all ev3 users are no such good programmers as you are known to be. At best, we all just use letters instead of motley coloured icon salad.
Please explain more understandable how to link exactly what and how to libev3.so or so.

Actually now having finished reading (and probably understanding not quite real 100%), and because not at least that simple printf("hello world\n") program works yet, I have to give up for now -
you should know that I now feel very depressed.
I think I'll wait for another BCC C release to make the EV3 world a little more not-quite or not-exactly and then I will start anew with my printf("hello world\n") program.
Shall the power be with you.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: EV3 BCC / C software problem(s)

Post by afanofosc »

Please, Doc, can you address the questions I pose here:
Regarding 6 I am befuddled. What do you mean by "nxt screen"? What do you mean by "the brick says "! Error!"? I can only assume you mean "EV3" when you say "NXT" but I am not certain that is a valid assumption on my part. To the best of my knowledge it is impossible to get the EV3 to say "! Error!" but I could be wrong. Native executables don't show up on the EV3 using the standard VM user interface.
Simple hello world programs work just fine and cannot produce an "! Error !" on the EV3 screen when executed. Please explain what you tried when you had trouble downloading and running a simple hello world program. You do know, of course, that you won't see anything on the EV3 screen as a result of a printf call since all that does and all it will ever do is write to the terminal window and not to the EV3 screen. If you connected to your EV3 via wired ethernet and telnet and you ran your executable from a linux shell prompt it would output hello world to the terminal window.

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

Re: EV3 BCC / C software problem(s)

Post by HaWe »

ok, I didn't understand that I won't see anything on the ev3 screen. I expected that printf would write to the screen "Hello World" anyway.

Code: Select all

// file name: hello_world.c
#include <stdio.h>
#include <unistd.h>

int main()
{
  int i;

  printf("hello world\n");
  usleep(5000000);

  return 0;
}
I have only the standard ev3 Linux plus Lego VM plus USB connection PC -> brick.
As the program hadn't started automatically by ctrl+F5 I had downloaded it by F6.
What I saw was that the file "hello_world" appeared in the file window above the ev3 demo file.
when I pressed the ev3 center button to execute this file, the display showed this "/!\ error !" and then the file disappeared from the ev3 screen.

I don't use telnet, I have no ethernet, I don't use a Linux shell and I have no idea about command lines, linux shell prompt, or terminal windows.
I guess I will simply have to wait until I can kill the Lego-VM task and then download and run compiled C executables just in the way I'm doing it with my NXT via USB.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests