Daten vom Raspberry Pi über I2C in den TXT Controller

Alles rund um TX(T) und RoboPro, mit ft-Hard- und Software
Computing using original ft hard- and software
Forumsregeln
Bitte beachte die Forumsregeln!
Antworten
sven.oceantdial
Beiträge: 3
Registriert: 11 Apr 2020, 14:11

Daten vom Raspberry Pi über I2C in den TXT Controller

Beitrag von sven.oceantdial » 11 Apr 2020, 14:32

Hallo liebe Community,

ich habe folgendes Problem: Ich habe meinen TXT Discovery "Fussballroboter" mit zusätzlicher Messtechnik ausgestattet:
- Ultraschallsensoren
- Ein Gyroskop
- Ein Kompass

Diese Daten lese ich über einen Raspberry Pi (RaPi) ein. Es müsste möglich sein den RaPi als I2C Slave zu nutzen und die Messwerte dem TXT Controllter zur Verfügung zu stellen (hier habe ich verschiedene Seiten in RaPi Foren gefunden, aus denen ich aber nicht schlau werde). Insgesamt rede ich über 7 analoge und 1 digealen Messwert.

Hat jemand so etwas schon mal gemacht? Hat jemand ein Beispielprogramm in Python zum konfigurieren des "I2C Slaves" sowie dem versenden der Daten und in Robo-Pro zum empfangen der Daten? Würde mich über Hilfe sehr freuen :D

Vielen Dank im Vorab...

Liebe Grüße, schöne Ostern und bleibt alle gesund...
Sven

Rei Vilo
Beiträge: 95
Registriert: 19 Dez 2015, 15:39

Re: Daten vom Raspberry Pi über I2C in den TXT Controller

Beitrag von Rei Vilo » 11 Apr 2020, 19:58

For time-sensitive measures, I wouldn't use a Raspberry Pi but a micro-controller instead. The Raspberry Pi may be delayed by Linux-related tasks and provide readings on a regular period. Only a micro-controller can provide real-time processes.

Option 1
The micro-controller would then perform data acquisition, filtering —filtering is critical as analog values are often noisy, the Kalman filter offers good performance—, then fusion —eg. to calculate the Euler angles— and finally export.

The gyroscope and the compass, along with an accelerometer, are part of an inertial measurement unit —or IMU.

Option 2
Instead of processing all the raw measures and performing data fusion manually, I would recommend using an IMU with a built-in controller.

You could connect such an IMU directly to the Robotics TXT through the I²C bus. I've reviewed some of them here.

Have fun and happy Easter!
Zuletzt geändert von Rei Vilo am 11 Apr 2020, 23:01, insgesamt 1-mal geändert.

vleeuwen
Beiträge: 1564
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: Daten vom Raspberry Pi über I2C in den TXT Controller

Beitrag von vleeuwen » 11 Apr 2020, 22:36

The combination of a RP as I2C slave could be useful but like Rei is writing, the overhead can also make your control system slow.

In the past I have connected a BNO055 directly to the I2C TXT bus.
(Smart sensor combining accelerometer, gyroscope, magnetometer and orientation software )
The BNO055 has been mounted on a breakout board.
For implementation of the I2C driver I used a RoboPro extension SLI as interface betweem RoboPro and the basic BNO055 API from Bosch
I also wrote the calibration procedure in RoboPro.
No need for a extra controller. It can be in certain application useful the do so extra pre-processing of the sensor data on a dedicated micro controller.
However the BNO055 itself does already the necessary pre-processing because a microcontroller is part of the device.
The sensor is not the cheapest but with all the extra it is direct useable.
raw mode tester
raw mode tester
BNO055_c.JPG (135.64 KiB) 3964 mal betrachtet
conv tester
conv tester
BNO055_b.JPG (156.79 KiB) 3964 mal betrachtet
Main test program
Main test program
BNO055_a.JPG (91.38 KiB) 3964 mal betrachtet
Zuletzt geändert von vleeuwen am 12 Apr 2020, 10:29, insgesamt 1-mal geändert.

vleeuwen
Beiträge: 1564
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: Daten vom Raspberry Pi über I2C in den TXT Controller

Beitrag von vleeuwen » 11 Apr 2020, 22:41

=======================Google translate ====================
Die Kombination eines RP als I2C-Slave könnte nützlich sein, aber wie Rei schreibt, kann der Overhead auch Ihr Steuerungssystem verlangsamen.
In der Vergangenheit habe ich einen BNO055 direkt an den I2C TXT-Bus angeschlossen.
(Intelligenter Sensor, der Beschleunigungsmesser, Gyroskop, Magnetometer und Orientierungssoftware kombiniert)
Der BNO055 wurde auf einem Breakout Board montiert.
Für die Implementierung des I2C-Treibers habe ich eine RoboPro-Erweiterung SLI als Schnittstelle zwischen RoboPro und der grundlegenden BNO055-API von Bosch verwendet
Ich habe auch das Kalibrierungsverfahren in RoboPro geschrieben.
Kein zusätzlicher Controller erforderlich. In bestimmten Anwendungen kann es nützlich sein, die Sensordaten auf einem dedizierten Mikrocontroller zusätzlich vorzuverarbeiten.
Der BNO055 selbst führt jedoch bereits die erforderliche Vorverarbeitung durch, da ein Mikrocontroller Teil des Geräts ist.
Der Sensor ist nicht der billigste, aber mit all dem Extra ist er direkt verwendbar.
(Teil 3)
Im Teil Werksbibliothek finden Sie Informationen zur Verwendung der Bosch-Bibliotheken in Bezug auf die fischertechnik I2C-API. In der Bibliothek haben sie einen Bosch BME680-Sensor verwendet, aber die Idee für die Verwendung der I2C-API ist dieselbe.
Zuletzt geändert von vleeuwen am 11 Apr 2020, 22:47, insgesamt 1-mal geändert.

vleeuwen
Beiträge: 1564
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: Daten vom Raspberry Pi über I2C in den TXT Controller

Beitrag von vleeuwen » 11 Apr 2020, 22:46

(part 3)
In the [url=https://github.com/fischertechnik/txt_d ... o99_BNO055]txt_demo_c_download [/url] you can find some basics about the BNO055 to make a SLI with extended RoboPro elements.
In the [url=https://github.com/fischertechnik/txt_t ... oryLib/src]factory library part[/url] you can find how to use the Bosch libraries in relation with the fischertechnik I2C API. In the lib they have used a Bosch BME680 sensor but the idea for the I2C API use is the same.
Zuletzt geändert von vleeuwen am 13 Apr 2020, 11:21, insgesamt 1-mal geändert.

Rei Vilo
Beiträge: 95
Registriert: 19 Dez 2015, 15:39

Re: Daten vom Raspberry Pi über I2C in den TXT Controller

Beitrag von Rei Vilo » 11 Apr 2020, 23:07

The BNO055 from Bosch is the all-in-one IMU I was referring to in my review.

IMHO, there is no need for developing a CLI library, a driver based RoboPro handles I²C nicely.

An exception would be time-critical calculations, like double-integrating acceleration to get distance.

The data-sheet and application note for the BNO055 or equivalent are well written.

Moreover, most of the default settings can be used to get Euler angles.

vleeuwen
Beiträge: 1564
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: Daten vom Raspberry Pi über I2C in den TXT Controller

Beitrag von vleeuwen » 11 Apr 2020, 23:40

The SLI drivers for complex drivers will makes the I2C calls probably a lot faster.
This because the write/read calls sequence can be bundled in one function.
SLI makes it possible to make full use of the Bosch bno055 library including the I2C abstraction and calculations.
This makes also the size of the RoboPro program a lot smaller.
And the RoboPro program can acting at a higher level.

For example: sensor initialization with I2C abstraction (see also the fischertechnik trainings factory software)
This is difficult to do directly in RoboPro.

The extended RoboPro element:

Code: Alles auswählen

       /*!   RoboPro element
	 * initialisation of the TBO055 sensor software.
	 * This set also the I2C communication.
	 * error workflow -1 = SLI is not init, -2 = sensor is not initialized.
	 */
	int	setInitSensorShort(short v)     //RoboPro set element name =InitSensor, type= Short,  RoboPro data input (v) is not used
	{
		if (!IsInit)
		{
			fprintf(stderr,	"libSliTxtBNO055.setOpearationModeShort: Not initialized!\n");
			return -1; //make use of the RoboPro element error workflow continuation
		}
		int res = sensor->initSensor(user_delay_ms);
		return res;  //make use of the RoboPro element error workflow continuation
			}
The underlying code:

Code: Alles auswählen

s32 TxtBNO055::initSensor(void(*f)(uint32_t))
{
	bno.bus_read = &(TxtBNO055::user_i2c_read);
   	bno.bus_write = &(TxtBNO055::user_i2c_write);
        bno.delay_msec = &(*f);//user_delay_ms;
	bno.dev_addr = BNO055_I2C_ADDR1;
        int8_t ret = bno055_init(&bno);
	if (ret != BNO055_SUCCESS) {
            printf("error: exit bno055_init");
	    return -2;   //make use of the RoboPro element error workflow continuation
	}
	return 0;
};

Code: Alles auswählen

int8_t TxtBNO055::user_i2c_read(uint8_t dev_id, uint8_t reg_addr,	uint8_t *reg_data, uint8_t len)
 {
	int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
	//Adr, Anz Wr, Wr-Data, Anz Read, Rd-Data, Speed
	uint32_t u32RetValue = KeLibI2cTransfer(dev_id, 1, &reg_addr, len,	reg_data, I2C_SPEED_400_KHZ);
	rslt = (u32RetValue == 0 ? 0 : -1); //0=success, -1 error
	return rslt;
}

==========================Google translate================
Die SLI-Treiber für komplexe Treiber werden die I2C-Aufrufe wahrscheinlich viel schneller machen.
Dies liegt daran, dass die Schreib- / Leseaufrufsequenz in einer Funktion gebündelt werden kann.
SLI ermöglicht die vollständige Nutzung der Bosch bno055-Bibliothek einschließlich der I2C-Abstraktion.
Dies macht auch die Größe des RoboPro-Programms viel kleiner.
Und das RoboPro-Programm kann auf einer höheren Ebene agieren.

Zum Beispiel: Sensorinitialisierung mit I2C-Abstraktion (siehe auch die Fabriksoftware fischertechnik trainings)
Dies ist in RoboPro nur schwer direkt möglich.

Das erweiterte RoboPro-Element:

sven.oceantdial
Beiträge: 3
Registriert: 11 Apr 2020, 14:11

Re: Daten vom Raspberry Pi über I2C in den TXT Controller

Beitrag von sven.oceantdial » 12 Apr 2020, 13:44

Hey Vleeuwen,
Hey Rei,

many thanks for your valuble ideas. I will try to use the I2C interface of the TXT controller directly with the IMU. And I can certainly buy the BNO055. Then I have the acceleration data and the heading available.

I tried to control the ultrasonic measurements from the TXT controller directly (not from Fischertechnik) but I think the cycle time is to slow for that. So I guess I need to buy the Fischertechnik device for that.

Thank you for all your help...

Kind Regards,

Sven

sven.oceantdial
Beiträge: 3
Registriert: 11 Apr 2020, 14:11

Re: Daten vom Raspberry Pi über I2C in den TXT Controller

Beitrag von sven.oceantdial » 13 Apr 2020, 17:14

Hello,

I need to ask again. I have found the TxtDemo99_BNO055 in the GitHub and I could download it. How does the import into ROBOPro work? I guess I can not use standart function blocks which are available?

I am sure I will have more questions. The delivery date for the sensor is around end of this week. I hope it will work...

Thank you very much...

Kind regards,

Sven

vleeuwen
Beiträge: 1564
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: Daten vom Raspberry Pi über I2C in den TXT Controller

Beitrag von vleeuwen » 13 Apr 2020, 19:03

The downloads are stand alone programs for the TXT.
They are working without RoboPro.
But this is a good bases to create a SLI.
The SLI is offering the step between RoboPro and C/++ based dynamic loadable libraries.
How is also descript on the same Github, SLI
The two RoboPro elements (blocks) for extended functions , a set and a get, are available in RoboPro.
RoboPro SLI elements
RoboPro SLI elements
SIL-blocks.JPG (41.98 KiB) 3720 mal betrachtet

vleeuwen
Beiträge: 1564
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: Daten vom Raspberry Pi über I2C in den TXT Controller

Beitrag von vleeuwen » 14 Apr 2020, 09:12

@sven
If you like I can send you my experimental SLI dynamic library file (.so) and accompanying RoboPro tests programs.
But it is for what it is.
I can't give support. It is an old project of my and for the moment I am busy what complete different things.
If this has your interest, send me a private message.

Antworten