Programming an Arduino Mega and a Mega Sensor Shield V2 for use in a Hexapod

hello everybody
I am building a hexapd and im using 18 servo motors for the leggs and am planning on putting a head on it when iv got it working

im using an Arduino Mega and a Mega Sensor Shield V2 and 18 Tower pro high speed metal gear servos

I also have a bluetooth board for the sensor shield that I would ideally like to connect to my android phone

so the issues i have are this
firstly i dont know much about programming the arduino. im learning the basics at the moment (think blink and switching things on and off) so i was wondering if there was software that writes the code for you, or code available that i can copy and past into the aduino that runs with the mega shield. this would be useful for me to be able to see the code to learn it.

secondaly how easy is it to control all this from my android phone?

Also once i can get that far I will want to add some sensors so it wont bump into things or walk off of tables and stuff, maybe even go up steps but i feel this is getting ahead of myself at this point

any ideas on how i can proceed will be much appreciated

firstly i dont know much about programming the arduino.

Then an 18 joint robot is far too ambitious a project.

so i was wondering if there was software that writes the code for you

The soft stuff between your ears...

or code available that i can copy and past into the aduino that runs with the mega shield.

Probably. If your legs are exactly the same as someone else's, and are positioned in exactly the same places.

secondaly how easy is it to control all this from my android phone?

Use the phone to press the ON switch. That was easy. If you meant something else, use terms that have specific meaning. "control" does not.

Also once i can get that far I will want to add some sensors so it wont bump into things or walk off of tables and stuff, maybe even go up steps but i feel this is getting ahead of myself at this point

That I can agree with.

PaulS I am saddened by your reply. I myself am a teacher and none of my students would learn anything if I had your attitude towards beginners. I believe I am in the "support" section of this site and that suggests help for people on all levels.

Your first highlight suggests I shouldn't start with a project like this. I personally learn best being thrown in the deep end. Show me the code and explain why its written like it is and ill progress very quickly.

You may find googling "The dominance factor in learning" useful. If you struggle understanding it i would happily explain it without trying to belittle you!

Your second highlight could be explained partially by my reply to your first highlight but also some shields that you buy has software available to write the code for you with a kind of CAD interface. So actually that was not a stupid question either.

Your third highlight is almost valid but again if I had code and understood the concept behind it I could modify it to sute my needs. One of the first rules of development is dont reinvent the wheel. If someone has already done something then use that, modify and adapt to improve on something.

Your forth highlight is clear you didnt even think about the question. How can I control ALL this from my phone? ALL this doesnt imply switching it on and off it implys controlling ALL of the robot. So walking, and turning etc.

your final highlight isnt even worth commenting on its just you being obnoxious as well as pedantic.

so please if you cant be helpful and supportive of people trying to learn then the best thing you can be is quiet.

Now, if you want to help me to learn how to do this then please do, i accept you know far more than me about this and I actually found your comment about leg size and spacing useful. does anyone else want to help me progress?

Regards

David

PaulS I am saddened by your reply. I myself am a teacher and none of my students would learn anything if I had your attitude towards beginners. I believe I am in the "support" section of this site and that suggests help for people on all levels.

I'm not opposed to people learning. The reason that I take time to post here is because I support it. But, there are reasonable beginner projects and unreasonable ones.

I teach wood-turning on occasion. If a person comes in who doesn't know which end of a tool to hold, and wants to replicate a project with 1/16" thin walls, turned on several axes, out of a $1000 piece of wood, I'm going to steer them towards a different first project.

The same is true here. Wanting to do something, and being capable of achieving that goal are two different things. I am sure that, after a dozen increasingly complex projects, you could increase your skill set to the point where building a 18 joint hexapod is not an insurmountable project. As a beginner, who doesn't understand the basics of programming, such a project is destined for failure.

I don't encourage failure. Better to not even begin, in my opinion.

Of course, it's better to start with projects that CAN be achieved, even if they are stretch goals. Stretching for the moon, when you can't reach the knob on the door isn't a reasonable expectation.

Your second highlight could be explained partially by my reply to your first highlight but also some shields that you buy has software available to write the code for you with a kind of CAD interface. So actually that was not a stupid question either.

Arranging snippets of predefined code in a simulator is not the same thing as writing code. Not even close. In my opinion.

Your third highlight is almost valid but again if I had code and understood the concept behind it I could modify it to sute my needs.

There really isn't that much involved in moving a servo. It's one line of code. The trick is getting 18 servos moving at the same time, in a fashion that facilitates forward movement.

If someone else has figured out how to do that, and posted code that you don't seem to have even looked for, the graceful movements of their hexapod are going to make yours look like a stumbling drunk, unless you have exactly the same configuration.

your final highlight isnt even worth commenting on its just you being obnoxious as well as pedantic.

You want to take an already difficult project, and make it even more complicated, adding another programming language and programming environment, with only the vaguest terms (control? wtf does that mean?) for requirements. I think that the term you were looking for was realistic.

so please if you cant be helpful and supportive of people trying to learn then the best thing you can be is quiet.

You won't hear another peep out of me, until you post your Android-controlled hexapod project in Exhibition and Gallery.

fine, thank you Paul I appreciate your input. so who wants to help me do this. because I have nearly built the actual robot :slight_smile:

code from an existing, working hexapod that I can figure out and modify would be really appreciated.

The_Venn:
fine, thank you Paul I appreciate your input. so who wants to help me do this. because I have nearly built the actual robot :slight_smile:

code from an existing, working hexapod that I can figure out and modify would be really appreciated.

I think Grasshopper is your go-to programming environment for this type of application. In fact, the Grasshopper forum has lots of people doing this very type of thing,

Check it out:

Would someone take a look at my arduino sketch please. I have found an old sketch for the exact chassis that I am using, I have had to modify the code to correct some errors but I still cant get this working, I would really appreciate someone with experience taking a look and seeing if they can fix it

DFRHexapod.rar (6.56 KB)

I would really appreciate someone with experience taking a look and seeing if they can fix it

Without knowing exactly what the code actually does, and what you really want it to do? Not a chance.

PaulS We know what it does, it controls a hexapod!, we know what I want it do do, I want it to run the hexapod!. if you load the code into arduino descktop software and tell it to validate the code it will tell you what the errors are.

Iv done a lot of looking around this website and I find a lot of posts where you just post out negative comments at people. please learn that if you are not going to actually help people find an answer then its best to just not get involved. So PaulS help me or go away!

If you detail specifically what the problem is then you will find PaulS can be extremely helpful.

What errors are you getting? When do you get them?

I did attach the sketch to my previous post but basically im getting this

CDS5500_2Serials.cpp:9:22: error: WProgram.h: No such file or directory
CDS5500_2Serials.cpp: In member function 'void CDS5500_2Serials::WritePos(int, int, int)':
CDS5500_2Serials.cpp:31: error: 'Serial2' was not declared in this scope
CDS5500_2Serials.cpp:31: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp:44: error: 'Serial1' was not declared in this scope
CDS5500_2Serials.cpp:44: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp: In member function 'void CDS5500_2Serials::SetID(int, int)':
CDS5500_2Serials.cpp:63: error: 'Serial2' was not declared in this scope
CDS5500_2Serials.cpp:63: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp:72: error: 'Serial1' was not declared in this scope
CDS5500_2Serials.cpp:72: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp: In member function 'void CDS5500_2Serials::SetAngleLimit(int, int, int)':
CDS5500_2Serials.cpp:90: error: 'Serial2' was not declared in this scope
CDS5500_2Serials.cpp:90: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp: In member function 'void CDS5500_2Serials::SyncWritePos(int*, int, int*, int)':
CDS5500_2Serials.cpp:127: error: 'Serial1' was not declared in this scope
CDS5500_2Serials.cpp:127: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp:149: error: 'Serial2' was not declared in this scope
CDS5500_2Serials.cpp:149: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp: In member function 'void CDS5500_2Serials::SyncWritePos(int*, int, int*, int*)':
CDS5500_2Serials.cpp:192: error: 'Serial1' was not declared in this scope
CDS5500_2Serials.cpp:192: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp:214: error: 'Serial2' was not declared in this scope
CDS5500_2Serials.cpp:214: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp: In member function 'int CDS5500_2Serials::ReadPos(int)':
CDS5500_2Serials.cpp:243: error: 'Serial2' was not declared in this scope
CDS5500_2Serials.cpp:243: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp:260: error: 'Serial' was not declared in this scope
CDS5500_2Serials.cpp:261: error: 'DEC' was not declared in this scope
CDS5500_2Serials.cpp:267: error: 'Serial1' was not declared in this scope
CDS5500_2Serials.cpp:267: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp:277: error: 'Serial' was not declared in this scope
CDS5500_2Serials.cpp:278: error: 'DEC' was not declared in this scope
CDS5500_2Serials.cpp: In member function 'void CDS5500_2Serials::Reset(int)':
CDS5500_2Serials.cpp:290: error: 'Serial2' was not declared in this scope
CDS5500_2Serials.cpp:290: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp: In member function 'void CDS5500_2Serials::SetTempLimit(int, int)':
CDS5500_2Serials.cpp:300: error: 'Serial2' was not declared in this scope
CDS5500_2Serials.cpp:300: error: 'INT' was not declared in this scope

In brief..
The first line identifies the problem. The code was written some time ago, prior to the introduction of IDE version 1.0 (The sketch ends in .pde rather than .ino?)

The include file, WProgram.h, has been replaced by Arduino.h but if you do a search for WProgram.h you will find a lot of guidance of what you need to change to bring it up to date.

Plan B, not recommended, is download IDE 0022. It should compile then. However, that is going back three years.

Ok I changed to Arduino.h
so now I get this errors
CDS5500_2Serials.cpp: In member function 'void CDS5500_2Serials::WritePos(int, int, int)':
CDS5500_2Serials.cpp:31: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp:44: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp: In member function 'void CDS5500_2Serials::SetID(int, int)':
CDS5500_2Serials.cpp:63: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp:72: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp: In member function 'void CDS5500_2Serials::SetAngleLimit(int, int, int)':
CDS5500_2Serials.cpp:90: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp: In member function 'void CDS5500_2Serials::SyncWritePos(int*, int, int*, int)':
CDS5500_2Serials.cpp:127: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp:149: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp: In member function 'void CDS5500_2Serials::SyncWritePos(int*, int, int*, int*)':
CDS5500_2Serials.cpp:192: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp:214: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp: In member function 'int CDS5500_2Serials::ReadPos(int)':
CDS5500_2Serials.cpp:243: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp:261: error: 'class HardwareSerial' has no member named 'writeln'
CDS5500_2Serials.cpp:267: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp:278: error: invalid conversion from 'int' to 'const uint8_t*'
CDS5500_2Serials.cpp:278: error: initializing argument 1 of 'virtual size_t Print::write(const uint8_t*, size_t)'
CDS5500_2Serials.cpp: In member function 'void CDS5500_2Serials::Reset(int)':
CDS5500_2Serials.cpp:290: error: 'INT' was not declared in this scope
CDS5500_2Serials.cpp: In member function 'void CDS5500_2Serials::SetTempLimit(int, int)':
CDS5500_2Serials.cpp:300: error: 'INT' was not declared in this scope

It looks like you need to revisit all those Serial.write calls - the "INT" is from a very much earlier version of the IDE.

So what doi replace INT with?

I can't remember , but I'd swap "write" for "print", and lose "INT" completely.

(Are you really a teacher?)

So what doi replace INT with?

Did you try LONG LONG? How about LONG LONG LONG?

If you post the code, and links to all libraries, we won't have to guess.

PaulS the code is on an attachment earlier on in this thread. Sorry I should have made that clearer

AWOL yes I teach Martial arts, why?

OK I have not had much time to look at this recently but here is what I have read up so far

Setting the servos up as an array is simpler and allows you to group the servos.

Define the min and max rotations on your servos will stop you burning them out. for example, rotate to a maximum of 2000 if 2000 is reached return to center.

Getting to load the servos in groups at a time prevents a power spike when the robot powers on. so for example
start thighs then start hips then start knees

Defining postures for the robot means you can make it walk in posture without coding each walking gate. For example. stand normal and walk, stand tall and walk, crouch and walk.

Inverse kinematics allows you to plot where you want the feet to go and the servos do the rest (as I understand this so far.

Its important to use the servo center as the point of reference because the robot body position varies relation to the legs depending on what posture it is in.

Based on what I have read I decided that I want to build my robot so that
it uses an IR compound eye as the main sensor,

I want to put foot switches in the feet so it wont start the next gait movement until the switch is pressed. so it wont walk off of tables and things.

I found the chopsticks robot and code and decided that this was a good foundation for me. so looking at it a lot of the code is fairly simple to read even if im not at a level to write the code at the moment.