Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
B-Robot on Arduino uno
11-07-2015, 06:59 PM
Post: #11
RE: B-Robot on Arduino uno
So, set the timer1 registers serving in both chips are not the same.
The Atmega328 no OCR1C register.
Therefore, we can only cater for two events (sonar excluded).

The initialization procedure:
Code:
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);
}

and interrupts
Code:
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);
}

Since we control pins in software, you can select any of the available pins.
Find all posts by this user
Quote this message in a reply
11-09-2015, 01:16 PM
Post: #12
RE: B-Robot on Arduino uno
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?
Find all posts by this user
Quote this message in a reply
11-09-2015, 02:32 PM (This post was last modified: 11-09-2015 02:39 PM by MaxMagic1986.)
Post: #13
RE: B-Robot on Arduino uno
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.
Find all posts by this user
Quote this message in a reply
11-09-2015, 05:00 PM (This post was last modified: 11-09-2015 05:07 PM by MaxMagic1986.)
Post: #14
RE: B-Robot on Arduino uno
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
Find all posts by this user
Quote this message in a reply
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
12-20-2015, 06:40 PM
Post: #16
RE: B-Robot on Arduino uno
(11-06-2015 09:21 AM)sasa999 Wrote:  
(11-06-2015 09:13 AM)legin.37 Wrote:  Because UNO is more cheaper ...
More cheaper!!!??? Huh
ProMicro is for 4$. That is less than cost petrol for driving to nearest storeSmile
http://www.ebay.com/itm/New-Pro-Micro-AT...SwPgxVNhve

Any way, it is up to you, use Uno or other board.

Подскажи плиз как ты решил проблему отсутствия пина 12 на promicro.

Я в коде поправил на один из свободных согласно схеме пинов (E6) но он как то конфликтует с сервой по прерываниям (заработало только после отключения сервы в коде).
Find all posts by this user
Quote this message in a reply
12-20-2015, 09:15 PM (This post was last modified: 12-20-2015 09:22 PM by sasa999.)
Post: #17
RE: B-Robot on Arduino uno
Я не использую серво для поднятия робота
http://forumsjjrobots.com/thread-738.html
потому могу и ошибаться, но..

Попробуй заменить
pinMode(12,OUTPUT);
на
pinMode(6,OUTPUT);

и PORTD,6 на PORTD,7.

p.s. 12-й пин это вовсе но проблема - можно и без ПроМикро обойтись Smile


Find all posts by this user
Quote this message in a reply
12-22-2015, 09:18 AM (This post was last modified: 12-22-2015 09:20 AM by michael_s.)
Post: #18
RE: B-Robot on Arduino uno
(12-20-2015 09:15 PM)sasa999 Wrote:  Я не использую серво для поднятия робота
http://forumsjjrobots.com/thread-738.html
потому могу и ошибаться, но..

Попробуй заменить
pinMode(12,OUTPUT);
на
pinMode(6,OUTPUT);

и PORTD,6 на PORTD,7.

p.s. 12-й пин это вовсе но проблема - можно и без ПроМикро обойтись Smile


Да, я так и сделал , только еще пришлось закомментить инициализацию серв , иначе на PORTD,7 ничего не появлялось.
А для поднятия робота ты просто поменял в коде углы отключения моторов ?
Поделись секретом Smile Ты научил esp рулить роботом ? ))
Find all posts by this user
Quote this message in a reply
12-22-2015, 10:06 AM
Post: #19
RE: B-Robot on Arduino uno
(12-22-2015 09:18 AM)michael_s Wrote:  Поделись секретом Smile Ты научил esp рулить роботом ? ))

Учим тихэнько-тихэнько.
Библиотека MPU-шная работает уже "на ура". "Мучаем" однотаймерное управление моторами.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


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