Simulink and the I2C interface
이전 댓글 표시
Hi all,
I'm trying to use Simulink to program a Lego Mindstorms NXT vehicle. The main program is complete, except for the sensor interface. The I2C optical sensor is already constructed and meant to be connected to one of the Lego ports. However, I'm not sure how to do that. I've downloaded a tool (Embedded Coder Robot or ECRobot) that is supposed to make Simulink work with the Lego system. However, it only works with standard sensors. See link below.
Since I haven't the faintest clue about how to do this, I thought I would look under the masks of some of the blocks in the ECRobot blockset to get a hint. The interface blocks for all the sensors (compass, gyro, motor, sound, touch, etc.) seem like a good place to start. However, looking under the mask reveals just a Saturation block and a Data Store Write block with no mention of any associated files. Surely, that can't be all there is?! It tells me very little about how to write my own code (or at least modify existing code) to achieve my goal. There are several files in other subdirectories which have codes that address the I2C communication protocol. As I haven't seen them used in any way and I also don't know how they're linked to the Simulink blocks, I'm unable to figure out how they work.
Could somebody please tell me how to uncover more of the inner workings of these blocks? If not, would someone like to share his/her knowledge of getting I2C to work with Simulink? Thanks very much.
Cheers
답변 (1개)
Kaustubha Govind
2011년 3월 28일
0 개 추천
I don't have experience with ECRobot, but have written drivers for other boards in the past. Typically, device drivers are implemented as S-functions with an accompanying TLC file to inline driver code into any code generated for the model. (If you do not intend to generated code from your model, you do not need to write a TLC script).
I downloaded the files for ECRobot and found several such drivers under ecrobotNXT/environment (for example, sfun_color_sensor).
If you have access to C/C++ drivers for the I2C optical sensor, then you can easily write S-function wrappers to create driver blocks.
댓글 수: 7
Joe
2011년 3월 28일
Kaustubha Govind
2011년 3월 29일
Joe: Any answer that I can give will be mostly speculative. Have you tried contacting Takashi-san, who is the author of the ECRobot: http://www.mathworks.com/matlabcentral/fileexchange/authors/68132
Joe
2011년 3월 29일
Kaustubha Govind
2011년 3월 29일
The operations of our Japan office have been affected by the current circumstances in that country. Please excuse any delays in communication from Takashi-san.
Regarding your question about "look under mask" - the simple answer is "Yes, that is all there is to the block". For more perspective, I looked into the ECRobot documentation and found this line for the blocks that you mentioned: "In simulation, these blocks are just place holders; however, they will be used to implement an appropriate device API in the generated code."
I also found several files under the private directory that actually help generate code for these blocks. For example, you can look for usages of iGetColorSensorBlockPortID in that folder and navigate through the code to see how additional source files are generated for these drivers.
This is not a standard way to write drivers, but is legitimate.
Kaustubha Govind
2011년 3월 29일
Also, it is perfectly okay for multiple blocks to be present in the same library model. In fact, this is how most Simulink block libraries are defined.
Joe
2011년 3월 29일
Kaustubha Govind
2011년 3월 30일
Thanks for understanding, Joe. With regards to how the device APIs are generated, unfortunately, my understanding is limited. Have you tried generating code from some simple test models and examined the emitted code? The documentation for the S-function+TLC technique is pretty solid, so you may be able to extend that information to create an S-function driver block.
HTH.
카테고리
도움말 센터 및 File Exchange에서 LEGO MINDSTORMS EV3 Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!