Tag Archives: Working Code

4 months later…

The closest I'll ever get to driving a Tesla. Ecstatic!

The closest I’ll ever get to driving a Tesla. Ecstatic!

Hay guys! No updates for the past 4 months, but things will be turning around shortly. Many things happened this summer – mostly good things and some bad things. Anyway, I’m going to be continuing things where I left them off so abruptly in May.

Truth be told, I’ve been working on the telescope in my free time for the last 3 weeks.  This is what it can do so far:

First, I removed the old motor mount :

20150818_170711

Old altitude motor mounting hardware : acrylic plates and large metal frankenstein bolts.
Old altitude motor mounting hardware : acrylic plates and large metal frankenstein bolts.

Then I lasercut new mounting frame plates out of plywood. It came together rather nicely.

I designed and laser cut it myself.
I designed and laser cut it myself.

One reason I had to redesign the frame was to include a way to mount the altitude axis magnetic rotary encoder. The top plate extends over the 3D-printed worm gear. I had to 3D-print a piece that sits on the original printed worm gear, to which I attached the magnet part of the magnetic encoder. Long story short, it wasn’t too hard to design and fabricate, and now it works.

Assembled : Altitude Axis worm gear, and frame, and magnetic encoder.
Assembled : Altitude Axis worm gear, and frame, and magnetic encoder.

And I’ve done some more changes to the driver tester’s UI.

Newer UI - made for testing the Telescope driver functions
Newer UI – made for testing the Telescope driver functions

I’m currently trying to figure out how make the telescope rotate at a specific speed (degree/second). It would require me to poll the encoder at two different times, and calculate the angle it has moved versus the amount of time passed between polls. Sounds easy enough, but I have other ideas I want to try out. In theory, most of the major imperfections and flaws of the mechanical system could be overcome with enough software. I think…

David

Slow Progress Is Still Progress

Impatient
Impatient… BTW – Not my dinosaur gif!

Eeep! Not much since last update… a week ago. I had to clear something off my ToDoList. Well at least I can say I got the driver connected and talking to the Arduino.

Part 1 : Arduino Code

– This code will blink the onboard LED (pin13) however many times the length of the command string that is being read on Serial, whose command string is terminated by a ‘#’ character

String temp;

void setup() {
    // put your setup code here, to run once:
    Serial.begin(19200);
    pinMode(13, OUTPUT);
    digitalWrite(13,LOW);
}

void loop() {
    // put your main code here, to run repeatedly: 

    if (Serial.available())
    {
        //readStringUntil will consume the '#' character
        temp = Serial.readStringUntil('#');

        for (int i = 0; i < temp.length(); i++) {
            digitalWrite(13,HIGH);
            delay(200);
            digitalWrite(13,LOW);
            delay(100);
        }
        delay(1);
    }
    delay(100);
}

Part 2 : Telescope Driver Code

– This code snippet belongs to the Connected member object, which includes get() and set() functions. The get() just returns whether or not the driver already established a connection to the hardware. The set() checks if we’re already connected, and if not, then we establish a serial connection to the Arduino over the ASCOM.Utilities.Serial Library. Common serial parameters I use are port 26 and baud 19200. It also sends a text message to the Arduino to confirm that it’s established a connection. The next step would be to have the Arduino send back an acknowledgement text message.

private ASCOM.Utilities.Serial objSerial;

public bool Connected
{
    get
    {
        tl.LogMessage("Connected Get", IsConnected.ToString());
        return IsConnected;
    }
    set
    {
        tl.LogMessage("Connected Set", value.ToString());
        if (value == IsConnected)
        return;

        if (value)
        {
            connectedState = true;
            tl.LogMessage("Connected Set", "Connecting to port " + comPort);
            // TODO connect to the device
            objSerial = new ASCOM.Utilities.Serial();
            objSerial.Port = 26;
            objSerial.Speed = SerialSpeed.ps19200;
            objSerial.Connected = true;
            objSerial.Transmit("Hello Arduino#");
        }
        else
        {
            connectedState = false;
            tl.LogMessage("Connected Set", "Disconnecting from port " + comPort);
            // TODO disconnect from the device
            objSerial.Connected = false;
        }
    }
}

Soo yeah. That’s all I’ve accomplished for now. I’m considering writing the MoveAxis method, and the SlewToAltAz method. Eventually, I’ll be able to move the telescope by sending it a text command, such as “SlewToAltAz(123.45678, 98.76543)#” or “MoveAxis(0,0.01234)#”, with each command ending in ‘#’ character. I’m not sure how to invoke those functions through the driver test app yet, but I might have to make a form in Visual Studio. I’m thinking something like a simple CNC manual Jog feature interface.

After I can get those two functions working, then we’ll figure out how to translate between the telescope’s machine coordinates and the coordinate based on planet earth…

I’ll leave you with one of my favorite comic strips:

John Heeris http://heeris.id.au/
John Heeris http://heeris.id.au/

 

Until next time

-david

Coding Hard? or Hardly Coding? – New Developments

From the movie Castaway, starring Tom Hanks
From the movie Castaway, starring Tom Hanks

Good news everyone! I’ve adopted a github thing, and I named it “Motorized-Telescope-Project”. Isn’t it adorable?

https://github.com/dharbott/Motorized-Telescope-Project

I started exploring GitHub because I need a place to store my code online, and this seemed appropriate. Not only that, my code is in a state where the important bits are functional, fragile, and bug-free. I’ve only used a concurrent version control system once a long time ago, so there will probably be a learning curve. This motor library business is new territory for me, so I’ll be experimenting with lots of bad code. Don’t expect me to arrive at a final version any time soon.

This is good news. This is evolution. I now have a github.

* * *

Let’s move onto the code, shall we? There was one major issue concerning the 12-bit magnetic encoder. As you rotate the magnet beneath the encoder, it outputs some value corresponding to the angle of that magnet relative to the encoder. The magnetic encoder outputs a value between 0 and 4095, because the encoder can count as fine as 4096 degrees per revolution – much finer than simply 360 degrees per revolution. The problem is, it only outputs a number between 0 and 4095. So it just wraps back around to the beginning once you cross over 4095, and vice verse.

This doesn’t work with the way I’m doing the GOTO function, so I started with some notes. I needed a way to measure the angular distance from the current angle to the angle we want it to be :

clockwise, distance
  if target < current
    distance is target + 4096 - current
  if target > current
    distance is target - current

And I turned it into this :

int getCWDistance (int current, int target) {
  return (target - current + ((target < current)*4096));
}

If you noticed, there’s a boolean statement within the last half of the return statement : (target < current). Based on the notes, the distance will always be (target – current), but in certain cases you have to add 4095 otherwise we’ll end up with a negative number that doesn’t make sense. When the boolean statement (target < current) gets evaluated, the value within those parenthesis becomes true/false. But in C, true also has a numerical value 1, and false also has a numerical value of 0. We can actually apply the boolean values of true and false in mathematical statements, such as I did there.

So now we have a way of measuring the angular distance of where I am pointing, to where I want to point to. My simple GOTO function tells the motor to run at full speed until it gets closer to the target angle. Then it slows to half speed until it gets to within several degrees, and then it moves at it’s “slowest capable speed” until it reaches the actual target angle. So far during testing, it’s been able to hit the target angle spot on, plus or minus 1 if the table shakes. The momentum of the entire telescope may be a factor. But that is not a big problem. Also, none of the bearings or gears are greased. That is a big problem…

In other Code News : I managed to get the Arduino to read in a number over Serial communication. I found the function parseInt() in the Serial Library, so it makes my job a lot easier. Basically, you can type in a number, press enter, and the telescope will rotate it’s base until it arrives at that angle. It’s a lot more exciting than it sounds, so if I remember, I’ll take video next time. So far, I got the base to rotate left and right. I haven’t gotten to making the telescope tilt up/down yet. But implementing that won’t be difficult, now that everything else is working.

Once the altitude motor GOTO function is working, all we need is to get the Raspberry PI online and connected, so it can start sending some real numbers.

Looking ahead, our next big challenge will be finding a suitable program to do plate-solving : Plate-solving is a method in which we use a digital photograph of what we see through the eyepiece, pick out known constellations, and orient ourselves in relation to the universe.

Maybe I’ll pick something more interesting to talk about next time.

Cheers!

-david