Adafruit_PWMServoDriver.h

Processing/Wiring (illetve C) nyelvű programozási fogások, tippek. (AVR-Duino, Arduino, EthDuino, Diecimila, Severino, Nano, LilyPad)
Válasz küldése
IKEnovice
Újonc
Újonc
Hozzászólások: 5
Csatlakozott: 2015. július 11. szombat, 15:23

Adafruit_PWMServoDriver.h

Hozzászólás Szerző: IKEnovice »

Sziasztok!

Használta már valaki ezt a library-t? Van valakinek tapasztalata?

Nem rég vettem 2 db 16-Channel 12-bit PWM/Servo Driver - I2C interface - PCA9685 -öt, ugyan nem Adafruit gyártmány de a library támogatja. Odáig el is jutottam, hogy sorosporton kiküldött érték alapján be tudom állítani a servo motornak a PWM jelet (jéé nem csak 0-180 fokig mozoghat egy servo :mrgreen: persze csak 1 pillanatra lett túlvezérelve kalibrálás közben :wink: ), illetve hogy milyen gyorsan tegye meg a servo kar az utat.

Viszont van pár kérdésem:

Itt találkoztam először az uint8_t és a uint16_t kifejezésekkel, ha jól értem ez is INT, csak van valami min max határa. Pontosan mitől függ h melyiket használom?

Valamint a servo nevű példa kódban a "void setServoPulse(uint8_t n, double pulse)" funkció mi célt szolhál? Nem láttam hasznát.

Köszi a válaszokat előre is!

Ui.: Róbert, köszönöm szépen a 60 napos tanfolyamot, már a ráadás leckék jönnek és a kezdő csomag is kivállóan működik. Le a kalappal a munkád előtt!
IKEnovice
Újonc
Újonc
Hozzászólások: 5
Csatlakozott: 2015. július 11. szombat, 15:23

Re: Adafruit_PWMServoDriver.h

Hozzászólás Szerző: IKEnovice »

Itt a példakód:

/***************************************************
This is an example for our Adafruit 16-channel PWM & Servo driver
Servo test - this will drive 16 servos, one after the other

Pick one up today in the adafruit shop!
------> http://www.adafruit.com/products/815

These displays use I2C to communicate, 2 pins are required to
interface. For Arduino UNOs, thats SCL -> Analog 5, SDA -> Analog 4

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!
#define SERVOMIN 150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX 600 // this is the 'maximum' pulse length count (out of 4096)

// our servo # counter
uint8_t servonum = 0;

void setup() {
Serial.begin(9600);
Serial.println("16 channel Servo test!");

pwm.begin();

pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates
}

// you can use this function if you'd like to set the pulse length in seconds
// e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. its not precise!
void setServoPulse(uint8_t n, double pulse) {
double pulselength;

pulselength = 1000000; // 1,000,000 us per second
pulselength /= 60; // 60 Hz
Serial.print(pulselength); Serial.println(" us per period");
pulselength /= 4096; // 12 bits of resolution
Serial.print(pulselength); Serial.println(" us per bit");
pulse *= 1000;
pulse /= pulselength;
Serial.println(pulse);
pwm.setPWM(n, 0, pulse);
}

void loop() {
// Drive each servo one at a time
Serial.println(servonum);
for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
pwm.setPWM(servonum, 0, pulselen);
}
delay(500);
for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
pwm.setPWM(servonum, 0, pulselen);
}
delay(500);

servonum ++;
if (servonum > 15) servonum = 0;
}
Avatar
Robert
Elektronbűvölő
Hozzászólások: 10213
Csatlakozott: 2005. december 9. péntek, 7:00

Re: Adafruit_PWMServoDriver.h

Hozzászólás Szerző: Robert »

Az stdint.h állomány definiálja a változótípust:
S ill u az első: s - signed, u - unsigned (előjeles vagy sem). A legmagasabb bit az előjelet adja.
Pl.char : byte. Alapeset: 0...255 érték (0000.0000 ... 1111.1111)
signed-ként: -128....+127 (1000.0000 ... 0111.1111)

Int - integer: 0..65535 / -32768...32767 hasonló logikával...
Avatar
csegebiga
Chipgyilok
Hozzászólások: 288
Csatlakozott: 2015. március 27. péntek, 21:27

Re: Adafruit_PWMServoDriver.h

Hozzászólás Szerző: csegebiga »

ha jól emléxem tanulmányaimból:
uint8=unsigned int 8biten =0-255 (00h-FFh)
uint16=usigned int 16biten= 0-65535 (0000h-FFFFh)
igen úgy néz ki, jól emlékeztem:
http://forum.arduino.cc/index.php?topic=206959.0


uint8_t, is a standard name that is defined in the stdint.h header file for an unsigned integer that is at least 8 bits in size, while byte is defined in the Arduino headers. Both uint8_t and byte ultimately are defined as the unsigned char data type. If you ever decide to move your code to a different development platform that doesn't use the Arduino libraries, uint8_t is more likely to be defined than byte.
IKEnovice
Újonc
Újonc
Hozzászólások: 5
Csatlakozott: 2015. július 11. szombat, 15:23

Re: Adafruit_PWMServoDriver.h

Hozzászólás Szerző: IKEnovice »

Robert írta:Az stdint.h állomány definiálja a változótípust:
S ill u az első: s - signed, u - unsigned (előjeles vagy sem). A legmagasabb bit az előjelet adja.
Pl.char : byte. Alapeset: 0...255 érték (0000.0000 ... 1111.1111)
signed-ként: -128....+127 (1000.0000 ... 0111.1111)

Int - integer: 0..65535 / -32768...32767 hasonló logikával...

Köszi az infókat, ez a része most rendben van.
Válasz küldése