che codice stai usando per arduino ?
hai provato a seguire le guide e/o i progetti di altri utenti ?
hai provato a caricare qualche profilo di altri utenti per confrontare le configuraizoni ?
Ciao
soraz wrote:che codice stai usando per arduino ?
hai provato a seguire le guide e/o i progetti di altri utenti ?
hai provato a caricare qualche profilo di altri utenti per confrontare le configuraizoni ?
Ciao
*/
#define BRAKEVCC 0
#define RV 2 //according to cable at 24/11/2011
#define FW 1 //according to cable at 24/11/2011
#define STOP 0
#define BRAKEGND 3
#define CS_THRESHOLD 253 //not use :(
////////////////////////////////////////////////////////////////////////////////
#define pwmMin 128;
#define pwmMax 250;
#define motLeft 0
#define motRigth 1
#define speedPin 10
#define potL A4
#define potR A5
////////////////////////////////////////////////////////////////////////////////
// DECLARATIONS
////////////////////////////////////////////////////////////////////////////////
/* VNH2SP30 pin definitions*/
int inApin[2] = {
7, 4}; // INA: Clockwise input
int inBpin[2] = {
8, 9}; // INB: Counter-clockwise input
int pwmpin[2] = {
5, 6}; // PWM input
int cspin[2] = {
2, 3}; // CS: Current sense ANALOG input
int enpin[2] = {
0, 1}; // EN: Status of switches output (Analog pin)
int statpin = 13;
/* init position value*/
int DataValueL=125; //middle position
int DataValueR=125; //middle position
////////////////////////////////////////////////////////////////////////////////
// INITIALIZATION
////////////////////////////////////////////////////////////////////////////////
void setup()
{
/* serial initialization */
Serial.begin(115200);
/* motor initialization */
pinMode(statpin, OUTPUT);
for (int i=0; i<2; i++)
{
pinMode(inApin[i], OUTPUT);
pinMode(inBpin[i], OUTPUT);
pinMode(pwmpin[i], OUTPUT);
}
// Initialize braked for motor
for (int i=0; i<2; i++)
{
digitalWrite(inApin[i], LOW);
digitalWrite(inBpin[i], LOW);
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////// Main Loop ////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
void loop()
{
int sensorL,sensorR;
serialData();
sensorR = analogRead(A4)/4;
sensorL = analogRead(A5)/4; // echelle 0-1000
/* Serial.print(sensorL);
Serial.print(" ; ");
Serial.println(sensorR);
motorGo(motRigth, FW, 255);
delay(100);
motorOff(motRigth);
delay(1000);
*/
motorMotion(motRigth,sensorR,DataValueR);
motorMotion(motLeft,sensorL,DataValueL);
}
////////////////////////////////////////////////////////////////////////////////
// Procedure: wait for complete trame
////////////////////////////////////////////////////////////////////////////////
void serialData()
{
byte Data[3]={
'0','0','0' };
// il faut limmitter le temps pour garder le contr�le des moteurs
if (Serial.available()>2){ //wait a packets of 6
//test if order R or L data type
Data[0]=Serial.read();
if (Data[0]=='R'){ // ordre connue ?, si non je verrais au prochain tour !
Data[1]=Serial.read();
Data[2]=Serial.read();
DataValueR=NormalizeData(Data);
}
if (Data[0]=='L'){ // ordre connue ?, si non je verrais au prochain tour !
Data[1]=Serial.read();
Data[2]=Serial.read();
DataValueL=NormalizeData(Data);
}
}
if (Serial.available()>16) Serial.flush();
}
////////////////////////////////////////////////////////
void motorMotion(int numMot,int actualPos,int targetPos)
////////////////////////////////////////////////////////
{
// int potPinL=A4; //to include in header procedure
// int potPinR=A5; //to include in header procedure
int Tol=4;
int difference;
int pwm;
int securityLow=20;
int securityHigh=200;
int brakeDistance=16;
boolean move=true;
// encadrements des valeurs
if (targetPos<securityLow+brakeDistance) targetPos=(securityLow+brakeDistance); //software limits, but consideration speed brake.
if (targetPos>securityHigh-brakeDistance) targetPos=(securityHigh-brakeDistance); //software limits, but consideration speed brake.
// calculate speed about distance
difference=abs(targetPos-actualPos);
if (difference<=Tol) pwm=0; // to near to mov
if (difference>Tol) pwm=168;
if (difference>50) pwm=200;
if (difference>75) pwm=225;
if (difference>100) pwm=255;
// pay attention for security for Right motor!!
if (actualPos>securityHigh || actualPos<securityLow) move=false; //mechanicals limits
//to near to move
if (difference<= Tol) move=false; //to near to move
// en avant (haut)
if (actualPos<targetPos && move) {
pwm=255; //need power to go up !
motorGo(numMot, FW, pwm);
}
pwm=255; //test !
// en arriere (bas)
if (actualPos>targetPos && move) motorGo(numMot, RV, pwm);
// ne pas bouger !
if (move==false) motorOff(numMot);// STOP
}
////////////////////////////////////////////////////////////////////////////////
void motorOff(int motor){
////////////////////////////////////////////////////////////////////////////////
digitalWrite(inApin[motor], LOW);
digitalWrite(inBpin[motor], LOW);
analogWrite(pwmpin[motor], 0);
}
////////////////////////////////////////////////////////////////////////////////
void motorGo(uint8_t motor, uint8_t direct, uint8_t pwm)
////////////////////////////////////////////////////////////////////////////////
{
if (motor <= 1)
{
if (direct <=4)
{
// Set inA[motor]
if (direct <=1)
digitalWrite(inApin[motor], HIGH);
else
digitalWrite(inApin[motor], LOW);
// Set inB[motor]
if ((direct==0)||(direct==2))
digitalWrite(inBpin[motor], HIGH);
else
digitalWrite(inBpin[motor], LOW);
analogWrite(pwmpin[motor], pwm);
}
}
}
////////////////////////////////////////////////////////////////////////////////
// testPot
////////////////////////////////////////////////////////////////////////////////
void testPot(){
Serial.print(analogRead(A4));
Serial.print(";");
Serial.println(analogRead(A5));
delay(250);
}
////////////////////////////////////////////////////////////////////////////////
void testpulse(){
int pw=120;
while (true){
motorGo(motLeft, FW, pw);
delay(250);
motorOff(motLeft);
delay(250);
motorGo(motLeft, RV, pw);
delay(250);
motorOff(motLeft);
delay(500);
motorGo(motRigth, FW, pw);
delay(250);
motorOff(motRigth);
delay(250);
motorGo(motRigth, RV, pw);
delay(250);
motorOff(motRigth);
Serial.println("testpulse pwm:80");
delay(500);
}
}
////////////////////////////////////////////////////////////////////////////////
// Function: convert Hex to Dec
////////////////////////////////////////////////////////////////////////////////
int NormalizeData(byte x[3])
////////////////////////////////////////////////////////////////////////////////
{
int result;
if (x[2]==13) //only a LSB and Carrier Return
{
x[2]=x[1]; //move MSB to LSB
x[1]='0'; //clear MSB
}
for (int i=1; i<3; i++)
{
if (x[i]>47 && x[i]<58 ){//for xA to xF
x[i]=x[i]-48;
}
if ( x[i]>64 && x[i]<71 ){//for x0 to x9
x[i]=x[i]-55;
}
}
result=(x[1]*16+x[2]);
return result;
}
soraz wrote:Penso sia superfluo chiederti se hai disattivao l'UAC e lanci x-sim con l'opzione 'Esegui questo programma come amministratore' come specificato a pagina 4 del manuale -> http://www.x-sim.de/documents/X-Sim%20Quick%20Guide.pdf
Prova a vedere anche qui che parla di driver :
viewtopic.php?f=40&t=155&start=40&hilit=uso+error+opening+com#p7154
ciao
Return to Motion simulator Projects in progress
Users browsing this forum: No registered users and 3 guests