Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
B-Robot on Arduino uno
11-09-2015, 06:38 PM (This post was last modified: 11-09-2015 06:45 PM by KomX.)
Post: #15
RE: B-Robot on Arduino uno
MaxMagic1986 Wrote:the ex robot code does not compiling. I use ide version 1.06

and in the code of ex robot alot of unusial code that i dont need. Wifi, ultrasonic, led's, servo and osc. I need that robot only balancing after switch on. Battery sensor also does not need. Where i need to put this part of code. can some body please send working example?

Quote:i try to add this part of code to EX_robot file and remove ewerything that i not use.

Not working. but compiling. i want to just made standing balancing robot without autonomus mode, led's and servos.
i have connected these pins

motors enable -pin 4
motors dir - pin6
motor1 - step 13
motor2 step -7

have modified ex_pins file without port change.

Quote:and what resolution of motors i should use? Maybe here is somebody who can help me with code? I've been spend many hours soldering pcb, an wiring everything. I not use 3d printed parts, everything done with hands from alluminium. It is sad thing, that robot does not want to work with atmega 328, and the code itself is dificult for understand for me.

motors only start spining little bit immedeatly after switching on. 1 sec, not more and then device not responding

Create a new sketch and replace all the text of this code.
Test the stepper motors.
P.S. PIN 13 replaced by PIN 8!!! Suddenly you want blinked LED...
Code:
#include <Wire.h>
#include <I2Cdev.h>
#include <JJ_MPU6050_DMP_6Axis.h>

#define MOTORS_DIR_PIN      6
#define MOTORS_ENABLE_PIN   4
#define MOTOR1_STEP_PIN     8
#define MOTOR2_STEP_PIN     7

#define SERIAL_SPEED        115200

#define  ZERO_SPEED         65535
#define  MAX_ACCEL          8
#define  MAX_CONTROL_OUTPUT 500
#define  MICROSTEPPING      16


int16_t    speed_M1, speed_M2;
uint16_t   period_M1, period_M2;
int8_t     dir_M1, dir_M2;

void eX_Motors_Init(void)
{
  dir_M1 = 0;
  dir_M2 = 0;
  TCCR1A = 0;
  TCCR1B = B00000010;
  TCCR1C = 0;
  OCR1A  = ZERO_SPEED;
  OCR1B  = ZERO_SPEED;
  TCNT1  = 0;
  TIMSK1 = B00000110;
  digitalWrite(MOTORS_ENABLE_PIN,HIGH);
}

void delay_1us()  
{
  __asm__ __volatile__ (
    "nop" "\n\t"
    "nop" "\n\t"
    "nop" "\n\t"
    "nop" "\n\t"
    "nop" "\n\t"
    "nop" "\n\t"
    "nop" "\n\t"
    "nop" "\n\t"
    "nop");
}

ISR(TIMER1_COMPA_vect)
{
  if (dir_M1==0) return;
  if (dir_M1>0)
  {
    digitalWrite(MOTORS_DIR_PIN,HIGH);            // DIR Motors (Forward for Motor1)
  }
  else
  {
    digitalWrite(MOTORS_DIR_PIN,LOW);            // DIR Motors (Revers for Motor1)
  }
  OCR1A  = OCR1A + period_M1;
    __asm__ __volatile__ (
    "nop" "\n\t"
    "nop" "\n\t"
    "nop" "\n\t"
    "nop");
  digitalWrite(MOTOR1_STEP_PIN,HIGH);           // STEP MOTOR 1
  delay_1us();  
  digitalWrite(MOTOR1_STEP_PIN,LOW);
}

ISR( TIMER1_COMPB_vect )
{
  if (dir_M2==0)    return;
  if (dir_M2>0)
  {
    digitalWrite(MOTORS_DIR_PIN,LOW);            // DIR Motors (Revers for Motor2)
  }
  else
  {
    digitalWrite(MOTORS_DIR_PIN,HIGH);            // DIR Motors (Forward for Motor2)
  }
  OCR1B  = OCR1B + period_M2;
      __asm__ __volatile__ (
    "nop" "\n\t"
    "nop" "\n\t"
    "nop" "\n\t"
    "nop");
  digitalWrite(MOTOR2_STEP_PIN,HIGH);           // STEP MOTOR 2
  delay_1us();  
  digitalWrite(MOTOR2_STEP_PIN,LOW);
}

void eX_Set_Motors_Speed(int16_t tspeed_M1, int16_t tspeed_M2)
{
  long      timer_period_1, timer_period_2;
  int16_t   speed_1, speed_2;
  int8_t    dir_1, dir_2;

  if ((speed_M1 - tspeed_M1)>MAX_ACCEL)
    speed_M1 -= MAX_ACCEL;
  else if ((speed_M1 - tspeed_M1)<-MAX_ACCEL)
    speed_M1 += MAX_ACCEL;
  else
    speed_M1 = tspeed_M1;
    
  if ((speed_M2 - tspeed_M2)>MAX_ACCEL)
    speed_M2 -= MAX_ACCEL;
  else if ((speed_M2 - tspeed_M2)<-MAX_ACCEL)
    speed_M2 += MAX_ACCEL;
  else
    speed_M2 = tspeed_M2;

#if MICROSTEPPING==16
  speed_1 = speed_M1*46;   // Adjust factor from control output speed to real motor speed in steps/second
  speed_2 = speed_M2*46;
#else
  speed_1 = speed_M1*23;   // 1/8 Microstepping
  speed_2 = speed_M2*23;
#endif
// Расчёт периода для motor1
  if (speed_1==0)
  {
    timer_period_1 = ZERO_SPEED;
    dir_1 = 0;
  }
  else if (speed_1>0)
  {
    timer_period_1 = 2000000/speed_1;   // 2Mhz timer
    dir_1 = 1;
  }
  else if (speed_1<0)
    {
      timer_period_1 = 2000000/-speed_1;
      dir_1 = -1;
    }
  if (timer_period_1 > 65535)
    timer_period_1 = ZERO_SPEED;
  if (speed_2==0)
  {
    timer_period_2 = ZERO_SPEED;
    dir_2 = 0;
  }
  else if (speed_2>0)
  {
    timer_period_2 = 2000000/speed_2;   // 2Mhz timer
    dir_2 = 1;
  }
  else if (speed_2<0)
    {
      timer_period_2 = 2000000/-speed_2;
      dir_2 = -1;
    }
  if (timer_period_2 > 65535)
    timer_period_2 = ZERO_SPEED;
  dir_M1 = dir_1;
  dir_M2 = dir_2;
  period_M1 = timer_period_1;
  period_M2 = timer_period_2;
}


void setup() {
  pinMode(MOTORS_DIR_PIN,OUTPUT);        // DIR MOTORS
  pinMode(MOTORS_ENABLE_PIN,OUTPUT);   // ENABLE MOTORS
  pinMode(MOTOR1_STEP_PIN,OUTPUT);       // STEP MOTOR1
  pinMode(MOTOR2_STEP_PIN,OUTPUT);       // STEP MOTOR2

  Serial.begin(SERIAL_SPEED);
  delay(5000);
  Serial.println("Steper motors initialization");
  eX_Motors_Init();
}

void loop() {
  digitalWrite(MOTORS_ENABLE_PIN,LOW);
  
  Serial.println("Steper Motor №1 -> Forward");
  Serial.println("Steper Motor №2 -> Stop");
  eX_Set_Motors_Speed(250,0);
  delay(1000);

  Serial.println("Steper Motor №1 -> Stop");
  Serial.println("Steper Motor №2 -> Forward");
  eX_Set_Motors_Speed(0,250);
  delay(1000);

  Serial.println("Steper Motor №1 -> Forward");
  Serial.println("Steper Motor №2 -> Revers");
  eX_Set_Motors_Speed(250,-250);
  delay(1000);
  
  Serial.println("Steper Motor №1 -> Revers");
  Serial.println("Steper Motor №2 -> Forward");
  eX_Set_Motors_Speed(-250,250);
  delay(1000);
  
  Serial.println("Steper Motor №1 -> Stop");
  Serial.println("Steper Motor №2 -> Stop");
  
  digitalWrite(MOTORS_ENABLE_PIN,LOW);
  delay(5000);
}

P.P.S. Please, in the future is described in detail that you can not, the sketch is compiled normally, or an error during compilation (what?)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
B-Robot on Arduino uno - MaxMagic1986 - 11-03-2015, 07:54 PM
RE: B-Robot on Arduino uno - JohnQ - 11-05-2015, 04:04 PM
RE: B-Robot on Arduino uno - sasa999 - 11-05-2015, 04:44 PM
RE: B-Robot on Arduino uno - legin.37 - 11-05-2015, 08:59 PM
RE: B-Robot on Arduino uno - sasa999 - 11-05-2015, 10:48 PM
RE: B-Robot on Arduino uno - legin.37 - 11-06-2015, 09:13 AM
RE: B-Robot on Arduino uno - sasa999 - 11-06-2015, 09:21 AM
RE: B-Robot on Arduino uno - legin.37 - 11-06-2015, 10:22 AM
RE: B-Robot on Arduino uno - michael_s - 12-20-2015, 06:40 PM
RE: B-Robot on Arduino uno - MaxMagic1986 - 11-06-2015, 09:47 AM
RE: B-Robot on Arduino uno - KomX - 11-06-2015, 11:10 AM
RE: B-Robot on Arduino uno - KomX - 11-07-2015, 06:59 PM
RE: B-Robot on Arduino uno - MaxMagic1986 - 11-09-2015, 01:16 PM
RE: B-Robot on Arduino uno - MaxMagic1986 - 11-09-2015, 02:32 PM
RE: B-Robot on Arduino uno - MaxMagic1986 - 11-09-2015, 05:00 PM
RE: B-Robot on Arduino uno - KomX - 11-09-2015 06:38 PM
RE: B-Robot on Arduino uno - sasa999 - 12-20-2015, 09:15 PM
RE: B-Robot on Arduino uno - michael_s - 12-22-2015, 09:18 AM
RE: B-Robot on Arduino uno - KomX - 12-22-2015, 10:06 AM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)