Re: Trig functions in NXT-G
Posted: 02 Oct 2010, 17:30
New blocks often are written to encapsulate a specific task, such as reading values from I2C sensors made by HiTechnic or Mindsensors.com. A number of custom blocks that you can install into the LEGO MINDSTORMS NXT software provide things like cos, sin, sqrt, etc... They don't call a new opcode or system call. They use existing opcodes and system calls to do multiple things that by wrapping in a convenient package can be easily reused. So the cos block mentioned earlier in this thread uses an algorithm to approximate the value of cosine for whatever input you wire into the block. If the firmware had a native cos opcode and the NXT-G compiler could dynamically generate the right output for new opcodes it would be possible to write an NXT-G block that just emitted something like "cos out, angle" which would write cos(angle) to the provided output variable.
John Hansen
John Hansen