analogue into an arduino a-star controlling a robo claw controller in encoder mode hooked up exactly like in page 48 in the orion manual
analogue into an arduino a-star controlling a robo claw controller in encoder mode hooked up exactly like in page 48 in the orion manual
Dear: Allan
You said to element 14 that you are not getting how to use a rotary encoder but what are you not getting? You are not very specific.
From: Noah
I am trying to write a program for the arduino a-star to accept analog input from a pot with 0 to 5 volt output, go threw the arduino a-star and come out of it with packet serial to the roboclaw in encoder feedback mode like a servo.
Dear: Allan
Apparently in the datasheet they did have something you should know about. Here is the code I modified. Good Luck.
//Basic Micro RoboClaw RC Mode. Control RoboClaw
//with servo pulses from a microcontroller.
//Mode settings: Mode 2 with Option 4.
#include <Servo.h>
Servo myservo1; // create servo object to control a RoboClaw channel
Servo myservo2; // create servo object to control a RoboClaw channel
int pos = 0; // variable to store the servo position
void setup()
{
myservo1.attach(5); // attaches the RC signal on pin 5 to the servo object
myservo2.attach(6); // attaches the RC signal on pin 6 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
delay(1000);
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
delay(1000);
}
From: Noah
Dear: Allan
Ignore my last comment. I forgot you asked how to use your encoder not your servos so here is the code I found in your datasheet.
//Basic Micro RoboClaw Packet Serial Mode.
//Switch settings: SW3=ON, SW4=ON, SW5=ON
#include “BMSerial.h”
#include “RoboClaw.h”
#define address 0x80
#define Kp 0x00010000
#define Ki 0x00008000
#define Kd 0x00004000
#define qpps 44000
BMSerial terminal(0,1);
RoboClaw roboclaw(5,6);
void setup() {
terminal.begin(38400); roboclaw.begin(38400);
roboclaw.SetM1Constants(address,Kd,Kp,Ki,qpps); roboclaw.SetM2Constants(address,Kd,Kp,Ki,qpps);
}
void loop() {
uint8_t status;
bool valid;
uint32_t enc1= roboclaw.ReadEncM1(address, &status, &valid);
if(valid){
terminal.print(“Encoder1:”); terminal.print(enc1,HEX); terminal.print(“ “); terminal.print(status,HEX); terminal.print(“ “);
}
uint32_t enc2 = roboclaw.ReadEncM2(address, &status, &valid);
if(valid){
terminal.print(“Encoder2:”); terminal.print(enc2,HEX); terminal.print(“ “); terminal.print(status,HEX); terminal.print(“ “);
}
uint32_t speed1 = roboclaw.ReadSpeedM1(address, &status, &valid);
if(valid){
terminal.print(“Speed1:”); terminal.print(speed1,HEX); terminal.print(“ “);
}
uint32_t speed2 = roboclaw.ReadSpeedM2(address, &status, &valid);
if(valid){
terminal.print(“Speed2:”); terminal.print(speed2,HEX); terminal.print(“ “);
}
terminal.println();
delay(100);
}
Dear: Allan
Ignore my last comment. I forgot you asked how to use your encoder not your servos so here is the code I found in your datasheet.
//Basic Micro RoboClaw Packet Serial Mode.
//Switch settings: SW3=ON, SW4=ON, SW5=ON
#include “BMSerial.h”
#include “RoboClaw.h”
#define address 0x80
#define Kp 0x00010000
#define Ki 0x00008000
#define Kd 0x00004000
#define qpps 44000
BMSerial terminal(0,1);
RoboClaw roboclaw(5,6);
void setup() {
terminal.begin(38400); roboclaw.begin(38400);
roboclaw.SetM1Constants(address,Kd,Kp,Ki,qpps); roboclaw.SetM2Constants(address,Kd,Kp,Ki,qpps);
}
void loop() {
uint8_t status;
bool valid;
uint32_t enc1= roboclaw.ReadEncM1(address, &status, &valid);
if(valid){
terminal.print(“Encoder1:”); terminal.print(enc1,HEX); terminal.print(“ “); terminal.print(status,HEX); terminal.print(“ “);
}
uint32_t enc2 = roboclaw.ReadEncM2(address, &status, &valid);
if(valid){
terminal.print(“Encoder2:”); terminal.print(enc2,HEX); terminal.print(“ “); terminal.print(status,HEX); terminal.print(“ “);
}
uint32_t speed1 = roboclaw.ReadSpeedM1(address, &status, &valid);
if(valid){
terminal.print(“Speed1:”); terminal.print(speed1,HEX); terminal.print(“ “);
}
uint32_t speed2 = roboclaw.ReadSpeedM2(address, &status, &valid);
if(valid){
terminal.print(“Speed2:”); terminal.print(speed2,HEX); terminal.print(“ “);
}
terminal.println();
delay(100);
}
is line 9( RoboClaw roboclaw(5,6);) for PWM input on pins 5 and 6?
I am getting an error in this line terminal.print(“Encoder1:”); terminal.print(enc1,HEX); terminal.print(“ “); terminal.print(status,HEX); terminal.print(“ “);
And I think the error says, stray "(" in program
Dear: Allan
Sorry it took me so long to respond to your post I was running into a problem with my computer. No pins EN1 and EN2 are your pin inputs and outputs to your encoder. EN1 which stands for encoder 1 is your pins for your first encoder. Pins EN2 which stands for encoder two is your second encoder. Good luck.
From: Noah
is this what you mean terminal.print(“En1:”); terminal.print(enc1,HEX); terminal.print(“ “); terminal.print(status,HEX); terminal.print(“ “);
Give this code a shot I am pretty sure it will work
//Basic Micro RoboClaw Packet Serial Mode.
//Switch settings: SW3=ON, SW4=ON, SW5=ON
#include “BMSerial.h”
#include “RoboClaw.h”
#define address 0x80
#define Kp 0x00010000
#define Ki 0x00008000
#define Kd 0x00004000
#define qpps 44000
BMSerial terminal(0,1);
RoboClaw roboclaw(5,6);
void setup() {
terminal.begin(38400); roboclaw.begin(38400);
roboclaw.SetM1Constants(address,Kd,Kp,Ki,qpps); roboclaw.SetM2Constants(address,Kd,Kp,Ki,qpps);
}
void loop() {
uint8_t status;
bool valid;
uint32_t enc1= roboclaw.ReadEncM1(address, &status, &valid);
valid = terminal.print("Encoder1:") && terminal.print(encl,HEX) && terminal.print(" ") && terminal.print(status,HEX) && terminal.print(" ");
uint32_t enc2 = roboclaw.ReadEncM2(address, &status, &valid);
valid = terminal.print("Encoder2:") && terminal.print(enc2,HEX) && terminal.print(" ") && terminal.print(status,HEX) && terminal.print(" ");
uint32_t speed1 = roboclaw.ReadSpeedM1(address, &status, &valid);
valid = terminal.print("Speed1:") && terminal.print(speed1,HEX) && terminal.print(" ");
uint32_t speed2 = roboclaw.ReadSpeedM2(address, &status, &valid);
valid = terminal.print("Speed2:") && terminal.print(speed2,HEX) && terminal.print(" ");
terminal.println();
delay(100);
}
From: Noah
do I write this to the roboclaw or to the a-star or both?
I am pretty sure you send it to the robo claw but what is the difference?
Dear: Allan
It is neither this code is supposed to work with arduino uno. But you could probably make it compatible with the board and in that case I wish you good luck!!!
From: Noah
Thank you I will try to make it work.
Allan Manuel