Ultrasonic sensor with simulink
38 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am using an arduino Mega 2560 board with Simulink. I have installed the simulink library for this board using 'targetinstaller'. I have also built a simple system with a hobby rc servo using the predefined Simulink blocks. I am trying to using the Ping Ultrasonic Range Finder from Parallax as a position feedback sensor in my control algorithm. However, I do not see any code blocks written for this in the simulink library. I have found a tutorial from Arduino's website that explains how the distance can be read from the sensor: http://arduino.cc/en/Tutorial/Ping?from=Tutorial.UltrasoundSensor . Is there any way this code can be turned into a simulink block? I'm not good with writing code so a step by step explaination would be appreciated. I just want a block that provides the object's distance in inches with no input. An option to adjust the sampling time would also be useful. I am running Matlab 2012a on windows 7 professional 64-bit.
0 comentarios
Respuestas (3)
Ryan G
el 17 de Sept. de 2012
You're best bet is a s function builder but you probably won't get a lot of assistance here beyond that until you put in a good amount of effort to get the job done yourself.
If you do manage to pull this together I'm sure the Arduino community and file exchange would appreciate having the working block uploaded.
4 comentarios
Ryan G
el 21 de Sept. de 2012
Simulink generates code for 'real time' operation (again, I'm not the most familiar with the whole arduino part). Depending on what oyu mean about accurate with timing, Simulink does 2 things:
1) At every time step, simulink is going to process everything in the model. This means it will grab the inputs -> follow lines to stateflow ->process stateflow chart -> generate outputs in the s-function for arduino -> send the outputs to arduino
Depending on how you decide to actually order these things.
2) Simulink takes this model and generates code for arduino. It will run as fast as arduino tells it to run given the context of sample time.
As far as implmenting stateflow, it can be tough when first encountered since it is a bit different from base simulink. Stateflow had a major update in 2012b, unfortunately you're on 2012a. There's a lot of demos available in the documentation and videos online, I would check those out to get started. Stateflow can be as complicated or simple as you want depending on how you design the chart.
Rolfe Dlugy-Hegwer
el 18 de Sept. de 2012
The easiest solution might be to use a separate Uno board with the Ping sensor. Then transfer the value back to the Mega via one of the digital serial pins.
0 comentarios
Rolfe Dlugy-Hegwer
el 19 de Sept. de 2012
Another possible approach might be:
- Add a MATLAB Function block to the model.
- Port the logic portion of the Arduino code to MATLAB code
- Use the coder.ceval function to call standard built-in Arduino functions, such as pulseIn().
- Use pinMode(), digitalRead(), digitalWrite() (avoid Arduino Digital Input/Output blocks, which do not have pinMode)
- Adjust the timing of code in MATLAB Function block to fit within the timing of the model.
This would require a fair amount of experimentation.
2 comentarios
Rolfe Dlugy-Hegwer
el 24 de Sept. de 2012
Editada: Rolfe Dlugy-Hegwer
el 25 de Sept. de 2012
You have to choose between the MATLAB Support Package for Arduino (aka ArduinoIO Package) or Simulink Support Package for Arduino Uno and Mega 2560 hardware. Have you tried using pulseIn() with the MATLAB support package?
Ver también
Categorías
Más información sobre Modeling en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!