Showing posts with label firmware. Show all posts
Showing posts with label firmware. Show all posts

2014-12-18

Simple IK

I came over this link while looking for a simple IK to drive a simple 3DOF robot arm I am making for work.

There is also this youtube video.

I have shamelessly copied his code here, and I intend to improve upon it for my own project and maybe post an update.

const float cx=2; //coxa
const float fm=6.2; //femur
const float tb=8.3; // tibia
float L, L1;
float alpha, alpha1,alpha2,beta,gama;
void setup()
{
 Serial.begin(9600);
}

void loop()
{
trigono_xyz(2, 4, 6); //contoh x,y,z
Serial.print("gama= ");
Serial.print(gama);
Serial.print(", alpha= ");
Serial.print(alpha);
Serial.print(", beta= ");
Serial.print(beta);
Serial.println();
}

void trigono_xyz(float x, float y, float z)
{
 L1=sqrt(sq(x)+sq(y));
 gama=atan(x/y)/PI*180;
 L=sqrt(sq(L1-cx)+sq(z));
 beta=acos((sq(tb)+sq(fm)-sq(L))/(2*tb*fm))/PI*180;
 alpha1=acos(z/L)/PI*180;
 alpha2=acos((sq(fm)+sq(L)-sq(tb))/(2*fm*L))/PI*180;
 alpha=alpha1+alpha2;
}

2014-02-21

Protobuf for embedded

I have recently had the opportunity to research potential binary protocols at work. The thought just occurred to me that Google's protocol buffers (a.k.a. protobuf) might be a good candidate for the serial communication that occurs between different components such as controllers and servos.

You might think that it has too high overhead, and that may very well be the case. On the other hand protobuf has a few advantages that may not be obvious before you start using it.

For one, it makes thinking about your protocol much easier. The .proto text file format is just brilliant for recording your latest and greatest ideas for a protocol.

Second, you can actually use the code that is compiled by the protobuf compiler, not only for transfer of data, but also as your internal representation of the data. This will save memory, and that is good.

Third, it makes changing and even managing versions of your protocol effortless. For an embedded hardware project you might think that is unnecessary, but at least in my project with 36 servos with custom firmware and probably a whole bunch of other little controllers responsible for other stuff, with protobuf you could just change the .proto files, rebuild the firmware binary, upload it to the right controllers and be done.

I will investigate what impact protobuf has on the performance of tiny controllers, and on the bandwidth and latency of the serial communications, and report my findings here.