Author Topic: Converting MATLAB to C  (Read 11158 times)

0 Members and 1 Guest are viewing this topic.

Offline Half ShellTopic starter

  • Robot Overlord
  • ****
  • Posts: 225
  • Helpful? 0
Converting MATLAB to C
« on: January 14, 2008, 07:50:58 PM »
A frind of mine is currently working on a complicated project which uses some pretty complex controls engineering to stabilize a small water/underwater robot while in a wave pool. They are asking me for help but the controls algorithms are beyond me. They used MATLAB and have all the math (matricies and solving ordinary differential equations) working there, but the robot is far too small to have something like MATLAB or a PC controlling it. I know how to control all 6 of his motors/actuators with microcontrollers but I don't know how to convert the MATLAB code into embedded C code.

Furthermore, I'm kind of scared that there won't be a simple to use micro  controller that can handle their code.

My questions come down to this:

- How do I know if a microcontroller can handle this?
- How can I convert MATLAB code, which I don't know, to embedded C easily? Especially since I don't know how to solve for the ordinary differential equation in C (in MATLAB they just call ode45).

This is the only forum I know of that could posibly have people that would know how to do this.

Offline hazzer123

  • Supreme Robot
  • *****
  • Posts: 460
  • Helpful? 3
Re: Converting MATLAB to C
« Reply #1 on: January 15, 2008, 01:30:49 AM »
Microchip and Mathworks did collaborate and make a matlab/simulink plugin for MPLAB. I haven't used it but i think it creates C code from a matlab/simulink model, that is for use in the microchip C30 compiler.

http://www.kerhuel.eu/RTWdsPIC/examples/ImportSimulinkMPLAB.html
http://www.viddler.com/explore/KJason/videos/3/
Imperial College Robotics Society
www.icrobotics.co.uk

Offline Half ShellTopic starter

  • Robot Overlord
  • ****
  • Posts: 225
  • Helpful? 0
Re: Converting MATLAB to C
« Reply #2 on: January 15, 2008, 09:24:31 AM »
Would i be able to use that code on any micro controller though?

Right now I'm debating telling them to make it a tethered bot and somehow find a way to have MATLAB talk to a microcontroller and have it control motors.

Offline benji

  • Supreme Robot
  • *****
  • Posts: 830
  • Helpful? 0
Re: Converting MATLAB to C
« Reply #3 on: January 15, 2008, 12:01:13 PM »
check the new version of matlab 2007 , it has an embedded systems toolbox,the program help is like a tutorial.
good ol' BeNNy

Offline neo01124

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 0
Re: Converting MATLAB to C
« Reply #4 on: January 16, 2008, 03:15:06 AM »
I know xactly what u are looking for.Sometime ago i worked on a bot where a friend of mine wrote blob detection code in matlab and i had to make the robot  follow the blob colour in realtime.What u'll have to do:
-> interface your robot to the parallel port or the serial port of the computer .This post of mine has the circuit + troubleshooting tips
  http://www.roboticsindia.com/modules.php?name=Forums&file=viewtopic&t=2826
-> Program your pc parallel port or serial port directly using matlab.Just type serial port in matlab help it has all the information u'll need + u can see this post for a simple run down of instructions
       http://www.roboticsindia.com/modules.php?name=Forums&file=viewtopic&t=2698
->u can even make it untethered using bluetooth wireless serial cable replacement ( http://www.sparkfun.com/commerce/product_info.php?products_id=8332 ) or using xigbee

I gess this pretty much solves ur problem

Offline Lubin

  • Beginner
  • *
  • Posts: 1
  • Helpful? 0
Re: Converting MATLAB to C
« Reply #5 on: January 30, 2008, 02:07:01 PM »
Hi Half Shell,

The complex controls engineering part has been realized with matlab. I guess, your friend uses some .m files, or perhaps a Simulink model (.mdl file). In the Simulink file, there is one part to simulate the behavior of the underwater robot, and there is the controller part which attempt to control the submarine.
Simulink is probably the most appropriate tool to simulate and tune the controls algorithms.

The most boring and complicate part of the project is to program a microcontroller. Since I had exactly the same problem, I built a toolbox for matlab/Simulink that make me able convert the simulink model into the binary .hex file, ready to be downloaded into a PIC24 or dsPIC.

Thanks to this toolbox, I only concentrate on the math part, and on the mechanical realization.
Please, try the toolbox (The evaluation version of the toolbox should be sufficient for this project). (You need matlab, Simulink and the toolbox Real Time Workshop, Real Time Workshop embedded coder and the one you can download here: http://www.kerhuel.eu/RTWdsPIC/download.html )

And let me know if you encounter any problems.

Also, one example of realization: http://www.kerhuel.eu/RTWdsPIC/examples/IMU.html

a forum for question about the toolbox is also available: http://www.kerhuel.eu/forum/index.php

Note that I am still developing this toolbox, I would be glad if I can get your feedback.

Lubin

PS : My website has been cited by hazzer123. I would like to correct  : this toolbox is not a Microchip and Mathworks collavoration  ;)



Offline S2L

  • Beginner
  • *
  • Posts: 1
  • Helpful? 0
Re: Converting MATLAB to C
« Reply #6 on: January 30, 2011, 11:25:10 AM »
Hi guys,

just for your information, I suggest to take a look also to my website: http://www.sim2lab.com
Here you can find a good alternative for developing embedded systems in Simulink for dsPIC chips. The name of my Simulink blockset is SIM2LAB Blockset and offers a cost effective solution for rapid-prototyping. You can also build your own GUI (Graphical User Interface) for data logging/monitoring, as well as change on-the-fly the software parameters.
Visit my website for further details and download your evaluation copy.

Regards,
S2L

 


data_list