EV3 "Hello World!" program

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: EV3 "Hello World!" program

Post by afanofosc »

The layer number is encoded into the specified output in this manner by combining one of the OUT_* constants (or a variable containing that constant value) with one of the LAYER_* constants using | or +. The firmware opcodes use two separate parameters for layer and port but the API I have designed combines them into one.

Code: Select all

#define OUT_A    0x01 /*!< Output port A */
#define OUT_B    0x02 /*!< Output port B */
#define OUT_C    0x04 /*!< Output port C */
#define OUT_D    0x08 /*!< Output port D */
#define OUT_AB   0x03 /*!< Output ports A and B */
#define OUT_AC   0x05 /*!< Output ports A and C */
#define OUT_AD   0x09 /*!< Output ports A and D */
#define OUT_BC   0x06 /*!< Output ports B and C */
#define OUT_BD   0x0a /*!< Output ports B and D */
#define OUT_CD   0x0c /*!< Output ports C and D */
#define OUT_ABC  0x07 /*!< Output ports A, B, and C */
#define OUT_BCD  0x0e /*!< Output ports B, C, and D */
#define OUT_ABCD 0x0f /*!< Output ports A, B, C, and D */
#define OUT_ALL  0x0f /*!< All output ports (A-D) */

#define OUT_MASK 0x0f /*!< The output port mask */

  // daisy chain constants
#define LAYER_MASTER 0x00 /*!< The master layer */
#define LAYER_SLAVE1 0x10 /*!< The first slave layer */
#define LAYER_SLAVE2 0x20 /*!< The second slave layer */
#define LAYER_SLAVE3 0x40 /*!< The third slave layer */
#define LAYER_MASK   0x70 /*!< The layer mask */

Code: Select all

  DecodeOutputs(&Outputs, &Layer);
  if (Layer == LAYER_MASTER)
  {
    cmd[0] = opOutputStop;
    cmd[1] = Outputs;
    cmd[2] = useBrake;
    return WriteToPWMDevice(cmd, cmdLen) == cmdLen;
  }
  else
  {
    return false;
    // support for daisychaining not yet implemented
  }
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: EV3 "Hello World!" program

Post by afanofosc »

I do not plan on implementing support for a single call that controls motors on different layers, but I will give it some thought.

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 »

is the restriction to 4 layers made by the ev3 hardware or by software / by your API ?
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: EV3 "Hello World!" program

Post by HaWe »

doc-helmut wrote:is the restriction to 4 layers made by the ev3 hardware or by software / by your API ?
totokan
Posts: 45
Joined: 28 Sep 2013, 04:22

Re: EV3 "Hello World!" program

Post by totokan »

Thank you for the tutorial, it was really helpful in learning everything about low-level EV3 interfacing! If anyone is interested, I wrote a simple, high-level function call to handle getting info from serial sensors, as well as an example program showing its use. It's pretty rough, but it works!
Attachments
SerialTestTerminal.c
(631 Bytes) Downloaded 394 times
serial_read.c
(1.21 KiB) Downloaded 385 times
serial_read.h
(446 Bytes) Downloaded 440 times
lvoc
Posts: 38
Joined: 10 Sep 2013, 13:34

Re: EV3 "Hello World!" program

Post by lvoc »

I like the way you wrapped the code in high level functions. The same could be used for other sensor interafces.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: EV3 "Hello World!" program

Post by HaWe »

I agree,

Code: Select all

int ReadSerial(char port, UART *pUart);
is sth like what I have already been proposing

Code: Select all

GetSensor(char port, long SensorType, long & values[])
// or
GetSensor(char port, long & values[]) // (in plain C: the pointer to the array: * values[])
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 18 guests