New custom hexapod - Kodama!

Not sure, it may depend on a couple of different things like:
Where you call it in the setup() function. It for sure would need to be called after g_ServoDriver.Init(); call.

But I think it probably is because when the robot first starts, we have g_InControlState.fHexOn having a false value, so the code toward the end of the main loop function will end up calling g_ServoDriver.FreeServos(); which for the SSC-32 blindly tells all 32 servos to move to 0 (or stop sending signals…) , which defeats your call in setup.

Kurt

In that case, it should be working I think, but none of the head servos seem to be engaged at all. Do I have to add them to the config file somewhere?

EDIT: Putting the code at the end of setup() seems to have worked, but I’m still not sure how to actually set the head up as a leg so that it will move with the body as mentioned before.

As I was mentioning, when the Hex is logically turned off (which is the case at startup), the code tells the SSC-32 to release all of the servos and it keeps doing so, until you hit the start button. The idea is sort of two fold, one is if you hit the start button to stop the robot, it may be doing something bad, like leg crashing into something, and so you want the robot to stop. Also it releases the servos as to conserve battery power. However this does not work for most digital servos. That is a hitec digital servo will continue to hold the position of the last valid pulse even after the pulses are removed.

So the question is do you want the head servos going somewhere or holding somewhere when none of the other servos are active. If so would need to probably modify the FreeServos function. Could probably hack in a FreeServos exclude mask that is optionally added to config file. Where if a bit is set or not set in this mask, the corresponding servo is not freed.

Alternatively you could not have these servos do something at this point, but instead have them activate like the other servos when the start button is pressed.

Kurt

Thanks Kurt!

Having them activate when the start button is pressed just like all the others is just fine, but where would I set that up? It appears to lock them in place when I do a moveSingleServo() in the setup method. Before it did nothing, they remained at 0 with no power no matter what I did to the bot. Is there a registry of servos somewhere that they have to be entered in?

Completely separate question: earlier someone mentioned setting up the head as another coxa joint so that it would turn while the bot turns. Any ideas how that might be accomplished?

In the main loop function, there is code:

[code] //Drive Servos
if (g_InControlState.fHexOn) {
if (g_InControlState.fHexOn && !g_InControlState.fPrev_HexOn) {
MSound(3, 60, 2000, 80, 2250, 100, 2500);
#ifdef USEXBEE
XBeePlaySounds(3, 60, 2000, 80, 2250, 100, 2500);
#endif

  Eyes = 1;
}

[/code]
Note: Should update this slightly as redundant check of fHexOn… However this is where in the code that starts the update for servos where it detects that the robot is on, but was not on before… So could add call out to your head stuff…

As for Head as other coxa? Not sure, I know in the A-Pod code there is code to position the code to position head depending on where the body is… But I have not merged any of Zentas A-Pod (BAp code) into the C code base yet. Did not have test setup for it. Although I could now potentially build a version that would run on the Fire-Ant, but currently running their stuff on it.

Kurt

Thanks man. I’ll spend some time looking at the code and see if moving the head as a 7th coxa is possible.

I’m working on this now. If this is the case, is there an array of coxa somewhere in which I have to add the two head servos?

Ok, I found the array of pins:

const byte cCoxaPin] PROGMEM = { cRRCoxaPin, cRMCoxaPin, cRFCoxaPin, cLRCoxaPin, cLMCoxaPin, cLFCoxaPin};

Should I just add the head pan servo to these, and the tilt to the femur?

Yes you could do it that way but again we don’t really want the head to act the same as a leg.
I would just simply define the two servos in the code and then have them read the joystick inputs then write that to each servo.

Would you mind giving me an example of writing the joystick inputs to each servo? I’ve been digging through the code all day and I’ve got a little fog-of-brain :slight_smile:

I should have a new laptop arriving soon and so I should be of more help then as I’m currently using my tablet.

I’m not sure what code you are using but If I remember correctly you are running arduino…

You would need to define the servos first so let’s say,…

Servo panServo; // Create a servo object for the pan (horizontal) servo Servo tiltServo; // Create a servo object for the tilt (vertical) servo

You need to look at how the code reads the PS2. I will use tiltVal and panVal as an example.

int tiltVal; // Value read from the vertical axis int panVal; // Value read from the horizontal axis

Pin assignment

void setup() {panServo.attach( ); // define your pins here.. tiltServo.attach( ); // define your pins here.. }

Something like this i guess…

[code]
void loop ()
{ panVal = analogRead(panPin); // read pan joystick position
panServo.write(panVal); //move servo to required position

tiltVal = analogRead(tiltPin); // read pan joystick position
tiltServo.write(tiltVal); //move servo to required postion

}[/code]

May need to scale the reading values to servo?.
I’m new to arduino… :wink:

Thanks dude, this will help a ton! I appreciate your taking the time to write all this.

Please only take this as an example. Could be tones of errors with that. Lol

No problem, now that I’ve got the concept I can expand on it.

:wink:
Look forward to seeing more…
…must go, must get back to work… :frowning:

So here’s what I’ve got so far, but the head only moves in one direction! Any ideas?

In the PS2 Input class:

setHeadPanTiltVal((ps2x.Analog(PSS_RX) - 128)/4, -(ps2x.Analog(PSS_LY) - 128)/4);

Declared in Phoenix_Code.h:

[code]void setHeadPanTiltVal(int pan, int tilt)
{
headPanVal = pan;
headTiltVal = tilt;
}

void moveHead(void)
{
//KODAMA - head servos
moveSingleServo(29, headTiltVal, 0);
moveSingleServo(28, headPanVal, 0);
}[/code]

And I am calling moveHead() in the main arduino loop.

Duane

EDIT: Not at that computer now, but I suspect it has to be something like the following: moveSingleServo(29, 1500+headTiltVal, 0);
Is that right?

Not completely sure… Humm
I can be of more help next week once new computer arrives. :smiling_imp:

Think it may have something to do with this line.
What is _RX and _LY doing?
My thoughts are that they are two different strings.

setHeadPanTiltVal((ps2x.Analog(PSS_RX) - 128)/4, -(ps2x.Analog(PSS_LY) - 128)/4);

Do the ## need to be the same??

setHeadPanTiltVal((ps2x.Analog(PSS_##) - 128)/4, -(ps2x.Analog(PSS_##) - 128)/4);

As far as I can tell, PSS_RX is the left/right motion of the right stick, and PSS_LY is the up/down motion of the left stick. Might have to tweak these so the tilt servo comes into play on the translate mode only.

Just tried it, it’s actually working pretty well.

The motion is a little chunky though, any ideas on smoothing it out?

Yes looks good.
Its jittery like that because we are using the ps2 and its resolution is not very good. But its the quickest way to integrate that kind of control to a pan and tilt.

The best way is to have the ik involved. Once i get setup ill try inputting that into your code.
Its quite simple. And uses the first method i mentioned.