mikejr
Posts: 15
Joined: Sat Oct 27, 2012 2:26 pm

Re: Balancing Robot

Sat Nov 24, 2012 5:05 pm

OK. The reset function is not actually resetting the PCA9685. More like a setup function. Setting MODE1 from the default(0x11) to 0x00 starts the internal oscillator and disables ALLCALL functions of the PCA9685. Not sure I need ALLCALL functions, especially since I have a mixed I2C bus. i.e. different I2C devices.
I'm thinking function to:
reset
turn all LED's off
sleep
turn oscillator off

Thanks,
Mike

mikejr
Posts: 15
Joined: Sat Oct 27, 2012 2:26 pm

Re: Balancing Robot

Sat Nov 24, 2012 9:33 pm

Two new PCA9685 functions

Code: Select all

void PCA9685::reset() {
	// Turn off all LED's
	I2Cdev::writeByte(devAddr, ALLLED_ON_L, 0x00);
	I2Cdev::writeByte(devAddr, ALLLED_ON_H, 0x00);
	I2Cdev::writeByte(devAddr, ALLLED_OFF_L, 0x00);
	I2Cdev::writeByte(devAddr, ALLLED_OFF_H, 0x10);
	// oscillator off,ALLCALL off and restart PCA9685
	I2Cdev::writeByte(devAddr, PCA9685_MODE1, 0x90);
}

/**
 * Stop the internal oscillator by
 * Changing bit 4 to a 1
 */
bool PCA9685::sleepMode() {
	uint8_t oldmode;
	I2Cdev::readByte(devAddr, PCA9685_MODE1, &oldmode);
	// bitwise OR (|) if bit4 = 0 or 1 then bit4 = 1
	oldmode |= 0x10;
	return I2Cdev::writeByte(devAddr, PCA9685_MODE1, oldmode);
}
Thanks,
Mike

mikejr
Posts: 15
Joined: Sat Oct 27, 2012 2:26 pm

Re: Balancing Robot

Sun Nov 25, 2012 1:32 am

It appears you can't set the restart bit unless it is already set. Strange!
Changed my reset function.

Code: Select all

void PCA9685::reset() {
   // Turn off all LED's
   I2Cdev::writeByte(devAddr, ALLLED_ON_L, 0x00);
   I2Cdev::writeByte(devAddr, ALLLED_ON_H, 0x00);
   I2Cdev::writeByte(devAddr, ALLLED_OFF_L, 0x00);
   I2Cdev::writeByte(devAddr, ALLLED_OFF_H, 0x10);
   // oscillator off and ALLCALL off
   I2Cdev::writeByte(devAddr, PCA9685_MODE1, 0x10);
}
Changed setPWMFreq function

Code: Select all

void PCA9685::setPWMFreq(float freq) {
   float prescaleval = 25000000;
   prescaleval /= 4096;
   prescaleval /= freq;
   prescaleval -= 1;
   uint8_t prescale = floor(prescaleval + 0.5);

   uint8_t oldmode;
   I2Cdev::readByte(devAddr, PCA9685_MODE1, &oldmode);
   uint8_t newmode = (oldmode&0x7F) | 0x10; // sleep
   I2Cdev::writeByte(devAddr, PCA9685_MODE1, newmode); // go to sleep
   I2Cdev::writeByte(devAddr, PCA9685_PRESCALE, prescale); // set the prescaler
   I2Cdev::writeByte(devAddr, PCA9685_MODE1, oldmode & 0x6F); // Oscillator on
   sleep(0.005);
   //I2Cdev::writeByte(devAddr, PCA9685_MODE1, oldmode | 0x80);
}
Thanks,
Mike

Frank B
Posts: 61
Joined: Fri Sep 14, 2012 8:02 pm
Location: Germany

Re: Balancing Robot

Sun Nov 25, 2012 2:37 pm

New video of "Balancing Roberta" :

http://www.youtube.com/watch?v=n-noFwc23y0
roberta2.jpg
roberta2.jpg (39.5 KiB) Viewed 3730 times
It turned out that my webcam is too slow with open-cv.
I wait for the official Rasperry-Cam.


Frank.

How can i embed a video here ?

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Balancing Robot

Sun Nov 25, 2012 4:41 pm

Great Job :)

Frank B
Posts: 61
Joined: Fri Sep 14, 2012 8:02 pm
Location: Germany

Re: Balancing Robot

Mon Nov 26, 2012 4:43 pm

Robertas brand new blog: http://robertabot.blogspot.de (Sorry, in German.)
I'll post details, descriptions ad new features there.

Frank.

Frank B
Posts: 61
Joined: Fri Sep 14, 2012 8:02 pm
Location: Germany

Re: Balancing Robot

Tue Dec 04, 2012 8:10 pm

The next balancing challenge ?

:-)

http://www.youtube.com/watch?v=mT3vfSQePcs

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Balancing Robot

Fri Dec 07, 2012 4:34 pm

It would need a rust-proof cycling cape in this weather!

Roberta's blog looks swish - I especially like the translation facility - I wonder how feasible it would be for a Pi using a 3G modem to utilise Google Translate and run the result through a speech synthasizer?!

My bot's still up on bricks - I have set myself a completion deadline of April.

I have recently changed to RISCOS and have taken some time to adapt, but hope to pick up pace now that I have worked out how to do I2C transactions under that environment. There is some RISC OS code that others may find useful on thids thread: http://www.raspberrypi.org/phpBB3/viewt ... ss#p227945

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Balancing Robot

Thu Dec 20, 2012 7:37 pm

This has been highlighted elsehwere on the forum:

http://www.riosscheduler.org/

could come in handy.

Return to “Automation, sensing and robotics”