Pages: [1]   Go Down
Author Topic: controlling arduino with software like matlab etc  (Read 1011 times)
0 Members and 1 Guest are viewing this topic.
Norway/Hurum/Oslo
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Building a 4-revolute-joint Robotic arm
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm building a robot-arm with 4 dc motors and two arduino usb boards (duemilanove). I can control two and two motors on each arduino with for example tera term but I need to control and calculate the motors together to get a robot arm.

I know matlab can communicate with several serial ports (COM) on hardware like:

s = serial('COM1');
fopen(s)

but I dont know how to communicate and control the digital pins on the arduinos with matlab. Especially if I allready have some setup-code in the arduino processing language and only want to control the motors together from a more high-level programming/script language.

I have used the arduino processing language to control the motors until now that I need a more complex algorithm to control all the 4 motors together in an arm.

I know about the arduinoTarget scripts for matlab but I had some problems with the installationscript and it looked like the scripts only was for one arduino at the time.

I'm open for suggestions on other software to use for this purpuse but I think matlab is pretty good on calculations as well when I have to calculate the forward and inversekinematics for the robotic arm.

Please help!
« Last Edit: October 27, 2009, 08:11:20 am by Pilkaster » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The easiset way is to write a program for the Arduino that listens for commands over the Serial port.  When the Arduino receives the correct commands, it should move motors in your arm accordingly.  Once that works. you can use MATLAB (or any other language) to send these commands over the Serial port.
« Last Edit: November 02, 2009, 09:10:51 am by jpgr87 » Logged

Norway/Hurum/Oslo
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Building a 4-revolute-joint Robotic arm
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I now know how to send simple data fram matlab to arduino but the problem now is that I don't know how to separate the commands/strings from matlab in arduino. i. e.

Matlab:
s1 = serial('COM3', 'BaudRate', 9600, 'Parity', 'none', 'DataBits', smiley-cool;
fopen(s1);
fprintf(s1, 'Hello World!') - or if I'm going to control 4 motors:
fprintf(s1, 100(motorspeed), 1(as in motor no. 1), 0(as in direction 1 of 2 on motor 1)) and perhaps
fscanf(s1) - if I'm going to read something from the arduino back to matlab

In Arduino - I know the setup() and loop() methods, this is just some of the code:
char info;
  if(Serial.available())
  {
      info = Serial.read();
  }
  Serial.println('I want to send something back to matlab');

I can for instance send the char '8' from matlab to arduino and let the motors run when char info detects the char '8' but that solves nothing because then all my motors will run and I will not be able to control them separately. I'm thinking on splitting the string I get from matlab and separate the words/integers to each motor but I don't know if it's possible yet.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49033
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's possible. You'll need to define the format of the string. For instance, you could do something like this:

S:100;M:1;D:0

This would set a speed, select a motor, and define a direction. Send this from matlab.

Then, on the Arduino, in loop, check for serial data. If any is present, read a byte. Decide what that byte means:

Code:
int speed = 0;
int direction = 0;
int motor = 0;

switch(byteRead)
{
   case 'S':
      // read until you find a ;
      // if not a :
      // speed *= 10;
      // speed += byte - '0';
      break;
   case 'M':
      // similar logic for motor, except
      // you probably will not have 10 or more
      // motors, so you could just expect one byte
      break;
   case 'D':
      // similar logic for direction
      break;
}

After the switch block ends, do something with the values in speed, direction, and motor.
Logged

Pages: [1]   Go Up
Jump to: