how can I resolve the compiling issue ? Adding a custom block to the Lego EV3 Simulink package

3 Ansichten (letzte 30 Tage)
I am trying to produce s-function of following code to run it on ev3(legomindstorm)platform but I had trouble compiling the code using MinGw compiler from gcc in matlabR15-windows7.The error I get is that sys/mman.h does not exist. What do you suggest to solve it?
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include "lms2012.h"
#include "driver_ev3.h"
#include "driver_ev3_camera_sensor.h"
//Runtime constants
const int MAX_SAMPLES = 100;
const char XGL_PORT = 0x0; //EV3 label minus 1
const int XGL_PACKET_SIZE = 10; //2(gyyro angle) + 2(gyro rate) + 2(acc x) + 2(acc y) + 2(acc z)
float functionCdriver(void)
{
//int main()
//{
//DEFINE VARIABLES
int xgl_device_file;
IIC *pXgl;
IICDAT IicDat;
int i;
float angle;
float rate;
float acc_x;
float acc_y;
float acc_z;
//INITIALIZE DEVICE
//Open the device xgl_device_file
if((xgl_device_file = open(IIC_DEVICE_NAME, O_RDWR | O_SYNC)) == -1)
{
printf("Failed to open device\n");
return -1;
}
pXgl =(IIC*)mmap(0, sizeof(IIC), PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, xgl_device_file, 0);
if (pXgl == MAP_FAILED)
{
printf("Map failed\n");
return -1;
}
//SPECIAL CONFIGURATION
//Setup IIC to read 2 packets
IicDat.Port = XGL_PORT;
IicDat.Time = 0;
IicDat.Repeat = 0;
IicDat.RdLng = XGL_PACKET_SIZE;
IicDat.WrLng = 2;
// Set the device I2C address
IicDat.WrData[0] = 0x02;
// Specify the register that will be read (0x42 = angle)
IicDat.WrData[1] = 0x42;
// Setup I2C comunication
ioctl(xgl_device_file,IIC_SETUP,&IicDat);
printf("Device is ready\n");
//PROCESS SENSOR DATA
for(i = 0;i<MAX_SAMPLES;i++)
{
//Compute angle, angular rate and accelerations
//acc_z = (pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][0]*256+pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][1])/100.0;
//acc_y = (pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][2]*256+pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][3])/100.0;
//acc_x = (pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][4]*256+pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][5])/100.0;
//rate = (pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][6]*256+pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][7])/100.0;
//angle = (pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][8]*256+pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][9])/100.0;
angle = (unsigned char)pIic->Raw[IIC_PORT][pIic->Actual[IIC_PORT]][0];
//printf("Angle = %0.2f [deg], Rate = %0.2f [deg/s]\n", angle,rate);
//printf("AccX = %0.2f, AccY = %0.2f,AccZ = %0.2f [m/s^2g]\n\n", acc_x, acc_y, acc_z);
//sleep(1);
}
//CLOSE DEVICE
printf("Clossing device\n");
//close(xgl_device_file);
// return 0;
//}
return(angle);
}

Antworten (1)

Shruti Sapre
Shruti Sapre am 17 Dez. 2015
Hi,
I understand that you are using the MinGw on Windows7. The sys/mman.h is a Unix header file not available on Windows. You may have to use a Windows equivalent:
Hope this helps!
-Shruti
  1 Kommentar
Shdn
Shdn am 18 Dez. 2015
Thanks for the reply. I tried to use mman.win also, but it leads to another errors of undeclared flags. As an example: 'O_SYNC' undeclared

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu LEGO MINDSTORMS EV3 Hardware finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by