Hi,
I having problem using packet serial..How calculate the QPPS,speed,acceleration and distance?
I have made some simple program using command 42- buffered motor M2 with speed and distance using PIC16F877a microcontroller with hitech C compiler..
Code:
/*
Control RoboCLaw using packet serial.
By: Khairul Anuar Juhari
*/
#include<htc.h>
#include "PS2controller_code.h"
void uart_send(unsigned long data);
main(){
//setup USART
BRGH = 1; //baud rate low speed option
SPBRG = 0x40; //set boud rate to 19200bps for 20Mhz crystal spbrg64
TX9 = 0; //8-bit transmission
TXEN = 1; //enable transmission
CREN = 1; //enable receive
SYNC = 0; //asynchronous
SPEN = 1; //enable serial port
/*
This line will move motor M2 according to speed,direction and distance
*/
__delay_ms(2500); ///delay 2.5 second
uart_send(128);
uart_send(42); //command 42
uart_send(0);
uart_send(6);
uart_send(26);
uart_send(128);
uart_send(0);
uart_send(0);
uart_send(7);
uart_send(208);
uart_send(0);
uart_send(545&0x7f);
__delay_ms(2300);
/*
This line will stop motor M2
*/
uart_send(128);
uart_send(42);//command 42
uart_send(0);
uart_send(0);
uart_send(0);
uart_send(0);
uart_send(0);
uart_send(0);
uart_send(0);
uart_send(0);
uart_send(0);
uart_send(170&0x7f);
__delay_ms(2300);
}
void uart_send(unsigned long data)
{
while(TXIF==0); //only send the new data after
TXREG=data;
}
The problem are:
Motor not stop when command to stop motor is send.Bythe way, the encoder resolution is 200ppr and is attached to the main shaft of the motor(attached after gearbox).
=========================================================================
Problem 1:
from my calculation the encoder resolution i should get is:
200ppr x 4 = 800ppr =====> correct me if i'm wrong
==========================================================================================
Problem 2:
to calculate the Qspeed, i used:
lets say i want the motor speed to 20rpm,so
20rpm x 800ppr = 16000 pulse / min ======> correct me if i'm wrong..is this 16000 value must be put to Qspeed??
==========================================================================================
Problem 3:
For acceleration, i dont know how to calculate so i just put 12,000 as said in the manual.
==========================================================================================
Problem 4:
My wheel diameter is 15cm and is attached directly to 200ppr encoder.
To find distance, i use this formula:
distance to go= (distance to go / wheel diameter) * 800
let say i want the motor rotates 1 rotation only..so,
circumference of wheel = Pi * wheel diameter
= 3.142* 15cm
= 47.13cm ~ 47cm
so, the value of distanceM2 should be is:
( 47cm / 47cm ) * 800 = 800 ========> is this value must be put in distanceM2? correct me if im wrong..
===============================================================================================
Problem 5:
Lastly, when o key in all the data, the motor does not move according to distance, speed and acceleration..PLease refer the attached source code above..
Finally, i really hope that somebody experts in this forum could lend me a hand:)) i really appreciate if can give any suggestions because almost 5 days i focused on this problem to solve.
By the way, if someone know how to set the PID, please kindly share it with us:))