Dear All;
I am making red round object tracking project by using MSP430G2553 and
Matlab. When red round object moves, a car will track red round object.
Project is consist of from two parts as image processing and
motion part. In motion part I am using L298N motor driver card,
MSP430G2553. and a car that consist of from 2 wheels with 2 dc motors and
a swivel castor. Image processing part in matlab is working as smooth.
But when a red ball moves, car can not track red object. When I compiled
code in Code Composer Studio, it doesn't give any error. Therefore I can
not find problem in code. I added MSP430G2553 code and parts of
image processing code that provide commnication between MSP430 and MATLAB.
I think remander part of matlab code is working correctly.
MATLAB PART
priorPorts = instrfind % finds any existing Serial Ports in MATLAB
delete(priorPorts) % and deletes them
s = serial('COM3');
set(s,'BaudRate',4800);
fopen(s);
IMAGE PROCESSING CODES
case 1
fwrite(s,'C');
case 2
fwrite(s,'L');
case 3
fwrite(s,'R');
case 4
fwrite(s,'B');
case 5
fwrite(s,'F');
otherwise
fwrite(s,'N');
end
CODE COMPOSER STUDIO PART
#include <msp430.h>
//P1.3 ENA
//P1.4 IN1
//P1.5 IN2
//P1.6 ENB
//P2.0 IN3
//P2.1 IN4
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
DCOCTL = 0; //
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT1; // P1.1 = RXD
P1SEL2 = BIT1; // P1.1 = RXD
UCA0CTL1 |=UCSWRST;
UCA0CTL1 |= UCSSEL_2;
UCA0BR0 = 104; // 1MHz 9600 baudrate
UCA0BR1 = 0; // 1MHz 9600 baud rate
UCA0MCTL = UCBRS0; // UART Baud adjustment
UCA0CTL1 &= ~UCSWRST;
IE2 |= UCA0RXIE; // USCI_A0 RX interrupt enable
__bis_SR_register(LPM0_bits + GIE); // General interrrupts and LPM0
mode are active
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
unsigned char received;
received = UCA0RXBUF;
if(received=='C') { //C=CENTER
P1OUT &= ~(BIT3 + BIT6);
}
else if(received=='R') { //R=RIGHT
P1OUT |=(BIT3 + BIT4);
P1OUT &= ~BIT5;
}
else if(received=='L') { //L=LEFT
P1OUT |=BIT6;
P2OUT |=BIT0;
P2OUT &= ~BIT1;
}
else if(received=='F') { //F=FORWARD
P1OUT |=(BIT3 + BIT6);
P1OUT |=BIT4;
P1OUT &= ~BIT5;
P2OUT |=BIT0;
P2OUT &= ~BIT1;
}
else if(received=='B') { //B=BACK
P1OUT |=(BIT3 + BIT6);
P1OUT |=BIT5;
P1OUT &= ~BIT4;
P2OUT |= BIT1;
P2OUT &= ~BIT0;
}
else if(received=='N') { //N=NO MOTION
P1OUT &= ~(BIT3 + BIT6);
}
}
I hope you will be able to provide information.
---------------------------------------
Posted through http://www.EmbeddedRelated.com
MSP430g2553 and Matlab
Started by ●March 19, 2017
Reply by ●March 19, 20172017-03-19
On 3/19/2017 4:46 AM, engineergc wrote:> Dear All; > > I am making red round object tracking project by using MSP430G2553 and > Matlab. When red round object moves, a car will track red round object. > Project is consist of from two parts as image processing and > > motion part. In motion part I am using L298N motor driver card, > MSP430G2553. and a car that consist of from 2 wheels with 2 dc motors and > a swivel castor. Image processing part in matlab is working as smooth. > > But when a red ball moves, car can not track red object. When I compiled > code in Code Composer Studio, it doesn't give any error. Therefore I can > not find problem in code. I added MSP430G2553 code and parts of > > image processing code that provide commnication between MSP430 and MATLAB. > I think remander part of matlab code is working correctly.Who wrote the code? If you wrote it, you should understand it and should be able to tell us what it does. If you can explain what it does, you should be able to add code to indicate what it happening. Print to a log file or light up LEDs or something. If worst comes to worst, you will need to use a debugger. -- Rick C
Reply by ●March 19, 20172017-03-19
On Sun, 19 Mar 2017 03:46:20 -0500, engineergc wrote:> Dear All; > > I am making red round object tracking project by using MSP430G2553 and > Matlab. When red round object moves, a car will track red round object. > Project is consist of from two parts as image processing and > > motion part. In motion part I am using L298N motor driver card, > MSP430G2553. and a car that consist of from 2 wheels with 2 dc motors > and a swivel castor. Image processing part in matlab is working as > smooth. > > But when a red ball moves, car can not track red object. When I compiled > code in Code Composer Studio, it doesn't give any error. Therefore I can > not find problem in code. I added MSP430G2553 code and parts of > > image processing code that provide commnication between MSP430 and > MATLAB. > I think remander part of matlab code is working correctly.I'm not going to look at your code for you -- if someone does, more power to them. Make a distinct separation between your image processing part and your motion part, and test them separately. It sounds like you haven't done this. You should be able to hand-feed a target angle error to the motion control and watch the car spin -- if this doesn't happen, you know that your problem isn't in the image processing. Ditto, you should be able to have Matlab look at an image and tell you an angle error, independently of the car. Get the two parts working _independently_, then glue them together -- if both bits work but the glued-together thing doesn't, then you know that the glue is at fault. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com I'm looking for work -- see my website!
Reply by ●March 20, 20172017-03-20
Tim's advice is good. Please heed it. Your code shows there's a lot you need to learn. I happen to know something about MSP430s. Here's what I can say: 1. I think you're trying to sleep in the main() while waiting for the UART to wake it up. You're only waiting once and then exiting main. The dead giveaway is that there is no loop running in main(). 2. The UART interrupt handler is not sending the wakeup signal so that the main can wake up. That's one reason why it appears dead. I'll bet there are other problems in your init code. If initialization isn't perfect, nothing that follows it will run like you want. JJS







