Go Down

Topic: servo reverse on one channel (Read 875 times) previous topic - next topic

MikeMCA

Hi, I have a working sketch that is great and works well. but, I need to reverse one channel.
The sketch operates two 270deg servos, but I need one to do the same as the other but rotate the other way around. I know I could change the servo motor and pot wires, I have done this on one other set up but its far from ideal. the display should display the same deg 


Can any one help please. 

slipstick

"do the same as the other but rotate the other way round" isn't easy to understand. If it's doing the same how can it be rotating in the other direction?

I think what you may want is what would normally be write(x) to one and write(180-x) to the other. You've confused it a bit by using microseconds but it's still just arithmetic. If your range is 600-2300 then it will be x and 2900-x.

Unless of course that isn't what you mean.

Steve

MikeMCA

Hi Steve,
 yes sorry, one servo has to go one way and the other has to be going in the opposite direction. like one clock wise and the other anti clock wise. (but stay in sync with each other)
The two servos are rotating a platform, there is one servo on one side and the other servo is on the other side, both work together. 
How did you get 2900-x this 2900 would be over the servo limit, or am I not understanding, I can see you added 600 and 2300 to get 2900
would it be -600-2300
 please could you explain or poss edit the line for me then i could see how this works.
 Mike

missdrew

Servo a can go 0 - 270
Servo b can go 0 - 270

if I move servo a to 100, I move servo b to 270-100
This way they will still be in tandem but mirrored.

slipstick

#4
Jan 23, 2021, 03:52 pm Last Edit: Jan 23, 2021, 03:53 pm by slipstick
If you're writing 600 to one servo the other needs 2300 doesn't it? And vice versa. Hence 2900-x.

Anyway try it out and check it really is what you want.

Steve

MikeMCA

HI ill give it go both ways, i will let you know
Head is spinning, trying at the mo to get some RC nav lights working without an RC input aghh..
 sketch seems to work ish..

MikeMCA

Hope this is what you both mean, i had to change the angle numbers a tad, I'm still playing with the stop angles
servoLeft.attach(servoLeftPin, 544, 2400); // <<<<<<<< set these min and max to suit a 270 servo
servoRight.attach(servoRightPin, 2400, 544);

TheMemberFormerlyKnownAsAWOL

#7
Jan 23, 2021, 05:36 pm Last Edit: Jan 23, 2021, 05:39 pm by TheMemberFormerlyKnownAsAWOL
You'd normally do the reverse in the servo write/writeMicroseconds.

Code: [Select]
int time = 1234;

...
....
fwdServo.writeMicroseconds (time);
revServo.writeMicroseconds (2944 - time);
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

slipstick

Hope this is what you both mean, i had to change the angle numbers a tad, I'm still playing with the stop angles
servoLeft.attach(servoLeftPin, 544, 2400); // <<<<<<<< set these min and max to suit a 270 servo
servoRight.attach(servoRightPin, 2400, 544);

No! I have no idea what the servo library does if you claim that 2400 is the MINIMUM value and 544 is the MAXIMUM but I wouldn't think it's anything good.

It is the values in the writeMicroseconds() commands that you need to change.

Steve

MikeMCA

You'd normally do the reverse in the servo write/writeMicroseconds.

Code: [Select]

// same as 31 mar 2020
//  but 1 april changed lcd to be non-i2c

//***************************************************************************
// ************* check the screen, pin and button pin numbers ***************
//***************************************************************************

// *** this version V2 uses microseconds not degrees ***
//    but still uses degrees for display purposes
//    V2.1 is non-i2c lcd



// not clear from those ^^^^ instructions if the servo has to go in sequence
//    *** code below allows movement in any order

//    *** code below is tested with 2x "normal" 0-180 servos ***
//    *** change these values for the real 0-270 servos ***
// V2: these pos values are for the LCD display


const byte pos1 = 0;
const byte pos2 = 90;  //will be 90
const byte pos3 = 180; //will be 180
const byte pos4 = 270; //will be 270
byte pos;
// V2: these microPos values are for the write.microseconds <<<< adjust these
const int micropos1 = 600; // <<<< adjust these, I just stuck some values in to test
const int micropos2 = 1200;
const int micropos3 = 1800;
const int micropos4 = 2300;
int micropos;

char posMessage[] = "   DOWN"; // later will hold the actual word to display

//                 **** V2.1 i2c lcd stuff commented out
/*
  //bperrybap library for lcd
  // install from ide: Sketch > Include Library > Manage Libraries, search hd44780
  #include <Wire.h>
  #include <hd44780.h>                       // main hd44780 header
  #include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
  hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto config expander chip
  // LCD geometry
  const int LCD_COLS = 16;
  const int LCD_ROWS = 2;
*/
//               *** and replaced with
#include <LiquidCrystal.h>
//const int rs = 6, en = 7, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
//LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);  //dfr0009 shield uses different pins

#include <Servo.h>
Servo servoLeft;
Servo servoRight;
// ******** check pins in next lines
//dfr0009 shield leaves different pins vacant
const byte servoLeftPin = 2; //was 8
const byte servoRightPin = 3; //was 9

const byte button1 = 19; //aka A5, was 10
const byte button2 = 11;
const byte button3 = 12;
const byte button4 = 13;

void setup()
{
  Serial.begin(9600);

  servoLeft.attach(servoLeftPin, 544, 2400); // <<<<<<<< set these min and max to suit a 270 servo
  servoRight.attach(servoRightPin, 2400, 544); // <<<<<<<< set these min and max  to suit a 270 servo

  pinMode(13, OUTPUT);
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  pinMode(button3, INPUT_PULLUP);
  pinMode(button4, INPUT_PULLUP);

  //lcd.begin(LCD_COLS, LCD_ROWS); //out
  lcd.begin(16, 2); //in
  lcd.setCursor(0, 0);
  lcd.print("  673090..V2.1  ");
  delay(1000);
  lcd.setCursor(0, 1);
  lcd.print("Pos: ");

}//setup

void loop()
{
  if (!digitalRead(button1))
  {
    pos = pos1; // for the display
    strcpy(posMessage, "   DOWN"); // for the display, I may have these wrong for the degrees ;) <<<<
    micropos = micropos1; //for the servo
  }
  if (!digitalRead(button2))
  {
    pos = pos2;
    strcpy(posMessage, "  RIGHT"); // for the display, I may have these wrong for the degrees ;)
    micropos = micropos2;
  }
  if (!digitalRead(button3))
  {
    pos = pos3;
    strcpy(posMessage, "     UP"); // for the display, I may have these wrong for the degrees ;)
    micropos = micropos3;
  }
  if (!digitalRead(button4))
  {
    pos = pos4;
    strcpy(posMessage, "   LEFT"); // for the display, I may have these wrong for the degrees ;)
    micropos = micropos4;
  }

  //servoLeft.write(pos);
  //servoRight.write(pos);  //these replaced by next 2:
  servoLeft.writeMicroseconds(micropos);
  servoRight.writeMicroseconds(micropos);
  lcd.setCursor(5, 1);
  if (pos < 10) lcd.print(" ");
  if (pos < 100) lcd.print(" ");
  lcd.print(pos);
  lcd.print((char)223); //degree symbol
  lcd.print(posMessage);
}//loop

here is the sketch

TheMemberFormerlyKnownAsAWOL

Code: [Select]
servoRight.attach(servoRightPin, 2400, 544); I don't think the Servo library will allow this.
I'm posting from my phone, and don't have access to the source of the Servo library, so I can't check.

But, it shouldn't be necessary, if you follow the advice in reply #7.
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

jimLee

Its like they can't hear you.

-jim lee
PNW Ardiuno & Maker club
1012 9Th Street, Anacortes, WA 98221 (Around the back of building)
GITHUB -> https://github.com/leftCoast

MikeMCA

Yes jim i get this all the time, i am not a software person hardware is my thing.
Mike

jimLee

Yeah, I actually know the feeling. I have a really nice digital scope on my desk. When I need to use it I prefer to have my EE buddy drive it. I'm totally lost in electronics.

RC servos typically run on around a 20 ms frequency with a 1..2 ms pulse. The position is given by the pulse width, with 1.5 ms being center. The frequency is a very sloppy number and can sometimes be cut down as much as 10ms. I've seen it where it actually works better like that. (Some servos can read a wider pulse with band and give  a larger swing)

AWOL is giving you the most common solution from our software world. Its a way to feed your value into the servo backwards (with a simple subtraction) Effectively reversing your servo.

Good luck!

-Jim lee
PNW Ardiuno & Maker club
1012 9Th Street, Anacortes, WA 98221 (Around the back of building)
GITHUB -> https://github.com/leftCoast

MikeMCA

Hi, well I tried what they said, it didn't work, i spent an hour rewiring the servo just to get me going on the project.

But I still need the code fix, the servo project is part of a very large multiple project so I have to do this in software as hard wiring changes will take to much time plus for swop outs it will be a nightmare.

I do hope someone will edit the code for me, I am crap at software lol

Mike

Go Up