Wednesday, April 13, 2011

How to control 18 servos [2.007 hexapod]

Things I've learned (not explained thoroughly e.g. with pics for pwm, more for my own reference). Or rather, the 600 threads of information I haven't incorporated into one coherent picture yet.

My final conclusion was to spend money and buy an 18 servo RC controller from Pololu, allowing me to control all 18 servos independently. Also, build a power bus to supply power to the servos.

Next steps: make sure I won't just strip all the servos -- weight hexapod and do some rough estimates.
Order RC controller ASAP and look into Pololu coding.

However, for two week turn-in deadline, just take the carrier, Y splitter cable 9 servos (so mirror the left and right sides no WAIT! that might not work out well, my servos do not look mirrored left to right, perhaps Y cable front and back servos instead for each side = exactly 12 software servos to control), and write code.

====
PWM can mean two different things in common use.

  1. Power pulse width modulation -- signal is the voltage averaged from the high and low pulses. Used for instance in motor control, where motor's inertia means it just sees 2.5V if you have 5V and a 50% duty cycle
  2. Pulse "duration" modulation -- signal is encoded in length of pulses
    Used for instance in servo control
More properly, PWM -- motor control. PPM -- servo control (looks like low duty cycle PWM). (wait, but I don't see PPM used anywhere else?)

Thus, with regards to Arduino nano and if I can somehow coerce it into controlling 18 servos.
The answer is probably yes, but with lots of electronics and coding. A better solution is to invest in RC board http://www.pololu.com/catalog/category/12.

The limitations: 
Hardware, Arduino nano:
Digital I/O Pins: 14 (of which 6 provide PWM output) **
Analog Input Pins: 8
Atmega328-- one 16 bit timer, two 8 bit timers (8 bit = less resolution on servo control, leads to jitter,  see http://letsmakerobots.com/node/4562)

Software, Default Arduino Servo library:
The Servo library supports up to 12 motors on most Arduino boards.
**(huh? Maybe TX and RX count as digital pins?)

What this stuff actually means:
AnalogInput pins are actually digital output pins. They are D15 to D22. Thus, I have enough hardware pins to control 22 servos.

Also, the 6 PWM thing is completely unrelated to servo control (related to motor control, I think).

I can use the Playground servo library to control servos off of as many pins as I have, and I'm not limited to the 12 servos in the regular library. 
You are not limited to 8 servos, but you must call the SoftwareServo::refresh() method at least once every 50ms or so to keep your servos updating. http://www.arduino.cc/playground/ComponentLib/Servo

====
Default servo library uses timer1 (16bit timer). http://www.arduino.cc/playground/ComponentLib/Servotimer1

Random stuff I don't understand yet:
Or maybe I can use a decade counter?

Hardware vs Software PWM
Hardware PWM is low maintenance. You initialize the hardware, then the only other software interaction needed is to set the duty cycle (which can be done whenever you want). Hardware PWM is fixed to specific pins and limited as to the number of outputs channels. Software PWM needs more maintenance. It may still use a hardware timer, but the output must be toggled by software at the proper times. Software PWM can use any open digital output pin and can support several output channels. http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=94938&start=0 

(ref. http://letsmakerobots.com/node/25923 Driving up to 48 servos with a Spider controller, does NOT apply to Nano)

Commercial products:

====
Other concerns:
Maybe my servos are too weak for my super-simple design with load-bearing without bearings or anything, and I won't even be able to walk without stripping the servos. That would be REALLY sad if I stripped 18 servos. Or perhaps I'll just stall out the servos with too much torque demand and burn through them. Maybe the plastic is too flimsy and I won't be able to walk without breaking servo horns.

To do: Weigh the robot and each leg, do rough calculations.

Power: 
Well, the servos may draw a lot of power. Or current. Or something. So I may get a Power Bus (? what is that? it sounds nom-able) by mooching off of Charles or Shane, and then create my own 5V power supply that can supply more current than the hobby king 7.4V LiPo battery + the 2.007 nano carrier board.

====
$$$:
Anyway, turns out many-servo hexapods are expensive, even partially subsidized by 2.007. .____. Perhaps I should have stuck with my tiny hexalinkagepod <3 hmm. 

At least it's less expensive time-wise with the help of 2.007 and friends.

Costs:
18 servos (VS-2 and HITEC 115) @ $2.50 each = $45.
Arduino nano = $30 (completely assembled, I hear buying the PCB and components is much cheaper).
Pololu controller = $40 (18 channel) without shipping. (uh, how do I use this? Do I need to learn another programming thingy? ;___; Can I just program it with Arduino?)

(alternative: arduino mega = $60, spider controller? = $60?)

====
Also, my way of building a hexapod using zero solidworks seems like very little mechanical engineering and a lot of coding and electronics. _sigh_

Tuesday, April 5, 2011

2.007 HW4 -- arcade drive, RC joystick mixing -- code should be free

#include
#define RC1 8
#define RC2 9
    Servo Lservo;
    Servo Rservo;

void setup()
{   digitalWrite(RC1,LOW);
    digitalWrite(RC2,LOW);
    pinMode(RC1, INPUT);
    pinMode(RC2, INPUT);
    Lservo.attach(6);
    Rservo.attach(7);
    Serial.begin(9600);
}

void loop()
{
  /* 0. Read in RC, constrain to make sure values between 1000 and 2000
     1. map ch1 (left/right), x_axis, to -+ 500
         1b. SKIPPED - check if it's in the deadband
     2. add to y axis values for left, subtract for right
     3. constrain result to 1000,2000
     4. map to servo values -> 0 fwd, 90 neutral, 180 backward (left and right servo are mapped OPPOSITELY)
  */
    int x_axis = constrain( pulseIn(RC1, HIGH, 25000), 1000,2000);
    int y_axis= constrain( pulseIn(RC2, HIGH, 25000), 1000,2000);
//    Serial.println(x_axis);
    int x_offset = map(x_axis,1000,2000,-500,500);

    int left = constrain(y_axis + x_offset, 1000, 2000);
    int right = constrain(y_axis - x_offset, 1000, 2000);

    Lservo.write( map(left,1000,2000,180,0) );
    Rservo.write( map(right,1000,2000,0,180) );
}

Sunday, April 3, 2011

cheat sheets / technical resources that I use

vi:
http://www.nathael.org/Data/vi-vim-cheat-sheet.svg
http://blog.vgod.tw/wp-content/uploads/2009/12/vim-cheat-sheet-full.png
http://www.math.ucdavis.edu/~mathclub/cheat_sheets/vim-cheatsheet.png

bash:
http://blog.vgod.tw/wp-content/uploads/2009/12/vim-cheat-sheet-full.png

6.002:
http://www.mit.edu/~godoy/tbpcircuits.html
and Prof. Afridi's notes, which aren't available online

arduino:
http://sites.google.com/site/mechatronicsguy/arduinocheatsheet

spanish, 3rd year:
http://www.amphi.com/teachers/jinboden/3rdyearnotes.html

podcasts:
Spanish (all levels)
site: http://www.practicaespanol.com/es/ (AWESOME site, beats anything else I've seen hands down, wish there was a free resource like this for Chinese)
RSS: http://feeds.feedburner.com/practicaespanol

Chinese (ABC level)
site: http://aprilpodcast.blogspot.com/ (transcripts require a nominal fee)
RSS: http://feeds.feedburner.com/AprilsMandarinPodcast

Notes in Spanish Intermediate (Spanish III level, I think)
RSS: http://intnotesinspanish.libsyn.com/rss

on respectability and social status (aka engineers>lawyers, and hawking homelessness)

Who is more respectable? A or B?
A) 35-year-old who lives off of his parents' income in their basement, watching TV all day everyday.
B) Doctor who saves 30 lives.

and what if I said:
B) But one of the doctor's patients turns out to be crazy and kills 100 people.
Does that change your opinion?

More crudely relevant to me, what about:
A) Doctor
B) Auto mechanic
or any of the following, choose A or B:

A) Engineer
B) Lawyer 
A) Professional aid worker
B) Engineer 
A) Generalist (holds dozens of odd jobs)
B) Specialist (creates the polio vaccine) 
A) Generalist (da Vinci)
B) Specialist (???) 
(see prior post generalist vs specialist: all that jack of all trades common sense)

The more I think about it, the more I believe that what we deem respectable jobs / a respectable (not-wasted life) is not so much a concrete scale as a set of preferences (oftentimes, lots of people have similar preference sets, forming a culture). Culture, because I ponder often my surprise when I visited China this summer and found out that lawyers are not highly paid there, and probably the lawyer career is not as highly-looked-upon as in the USA. And that a career in bureaucracy has (for thousands of years?) had an air respectability in China, while in the US politicians are greeted with much more suspicion.

And why is being homeless so sketchy? Is it 100% linked to "failure in life", or even highly correlated? Is it not socially accepted because it's acceptable for me to be homeless, but not for me to raise a family homeless?

Anyway, I was (also) pondering why auto mechanics are not nearly as respected as lawyers, even though they do some pretty incredible things and know a lot. aka they are some pretty incredible people. And of course, I love looking for evidence that makes me feel less insecure, so I found what I was looking for of course :)

"A country's most talented people typically organizeproduction by others, so they can spread their ability advantage over a larger scale. When they start firms, they innovate and foster growth, but when they become rent seekers, they only redistribute wealth and reduce growth. Occupational choice depends on returns to ability and to scale in each sector, on market size, and on compensation contracts. In most countries, rent seeking rewards talent more than entrepreneurship does, leading to stagnation. Our evidence shows that countries with a higher proportion of engineering college majors grow faster; whereas countries with a higher proportion of law concentrators grow slower."
Anyway, I'm back to being happy-go-lucky. Who cares if I objectively fail at coding and can't find an "industry internship" for this summer? There's a million things that I want to work on, and cool people to meet and work with regardless.

I can still be awesome, right? |||||.___.|||||



======
For myself
posts I found relevant / amenable to my worldview:
The point I'm getting at,this engineering and being a mechanical genius is an exact science where either you know your shit or you don't.

Look at the vast majority of college degrees these days and the type of jobs you get when you graduate.Over half are just totally useless fluff degrees where when you graduate you don't get a job producing anything.

Social status and respectability are not the same thing, a king may respect a servant because the servant is respectable and a beggar may hold a doctor in contempt because the doctor does not respect himself enough to treat others with civility. The social status of a doctor is always higher than that of a beggar of course, but that is inherited or part and parcel of his profession, his respectability is a part of himself and depends entirely upon his own behaviour.

I lean toward careers that help others and the community. These include firemen, policemen (although I know there are crooked ones), teachers, doctors, social workers, etc. These people get paid varied amounts of money, but without them, the society and community would suffer.
Oh and I also respect trash collectors. There is no way I'd do that job.#ixzz1IUxF4bck 
To me there isn't really a "most respectable career" as I consider ones conduct in how they do their jobs to be of more importance than what the actual career is. Firefighters, policeman, teachers, doctors etc are all certainly respectable when they conduct their duties with the utmost care, but construction workers, plumbers, mechanics, hell even used car salespeople can be quite respectable as well. (Ok, maybe not used car salespeople). Overall though I look at individual conduct more than a blanket assumption about careers, since each career has respectable and despicable people working in them.  #ixzz1IUwwtP1z  
I can't really pick a most respectable career, there are good people and assholes in all of them.
I would say that anyone who works conscientiously and with compassion to help others for little compensation, even 'soldiers,' would have the most respectable careers.
#ixzz1IUxYnuAq 

2.007 and digital timestamps (electronic lab notebooks)

I was contemplating my sorry lab notebook grades in 2.007, the "Build a Robot" and "Learn all the physics behind Robots" class at MIT, and I realized that the main reason for my failings was not making the logic and conclusions clear enough to an outside reader. (picture labeling, drawing conclusions, etc.).

I realized the main reasons for this are that:
1) I do NOT treat the lab notebook as something I will show industry representatives. I feel like it's main functionality should be for organizing my own thoughts.
2) I feel like anything useful to other people I would rather put online (on this blog, or in more-polished form on OrangeNarwhals). Then, I would link to said blog in my resume, have the link handy for smart-phone enabled recruiters, or print out quality posts.

The other function of a lab notebook, besides
a) getting a job, is for
b) proving I thought of something at some point in time.
e.g. for the US patents, that involves dating and signing every page (perhaps even witness-signing some pages) in case it could be used for filing a patent in the future. In industry, it's also used for
c) communicating with fellow engineers.

For b), a blogspot blog is clearly not admissible for proof-of-date, since most blog software (including blogger) allows the author to change the time and content of the post to whatever she likes.

So then I thought about it, and came up with the idea of digital timestamps. Then I google'd it and turns out digital timestamps / electronic lab notebooks are baked already:
Electronic Laboratory Notebooks: Requirements, Selection & Best Practices--Gase_090916.ppt
http://en.wikipedia.org/wiki/Trusted_timestamping
Even someone from MIT, although seems neglected:
http://www.mit.edu/~jis/timestamp.html
and there's a company too:
http://www.digistamp.com/timestamp.htm

I have this notion in my head, however, that paper is more reliable the electronics*. So my version would be electronic lab notebooks that are printed out onto paper using microprinting (like microfilm). That may be space-inefficient, though, and having the data compressed and turned into code, like QR or something, might work better. That adds another technology component though (not just magnification but also decoding).

*see: hypothesis as to why we have paper records of MITERS records from the 1970s and 1990s but not anywhere else. Apparently we may have tried to keep electronic records. AFAIK any electronic records are gone.

Anyway, in conclusion, my earlier thought process:
FALSE: working 30 hours a week on a 12 unit ("12 hours/week") class should earn me full credit on my silly class lab notebook
TRUE: not taking 10 minutes to add some titles, labels, key points, and clarifications of ambiguities will kill drop me 13 (out of 100) points on my lab notebook grade.

Also, I doubt 2.007 will start letting us submit blogs any time soon in lieu of our lab notebooks, even thought that would be AWESOME. I mean, based on my notebook, most of the stuff would be utterly irrelevant to 99.9999999% of the internet audience and irrelevant to 99% of fellow 2.007 students, but with computers I could just skim right past uninteresting content. And I could do it on my own time (I wouldn't have to choose between office hours, actually building a robot, or listening in to conversations with my section leader, Professor Campbell). And it wouldn't feel awkward at all (no risk of stealing designs if the designs are open-source), and I could ask friends who already know I'm utterly confused before I ask a million questions of my fellow section classmate.

In short, electronic lab notebooks as an option for 2.007 would be transparent, open-source, and AWESOME.