Select your language

Description of the control program ver.1.0.1


I have been thinking for a long time how to analyze the written program in detail here. In the end, I decided not to exaggerate. Anyone who can't program in javascript for node.js will definitely not learn it here. Who knows, does not need any trivial details. For this first version, I will make an exception and analyze the description a little more to clear the procedures and dependencies that will apply to other versions.

Javascript as a programming language is not a compiler, but an interpreter. This means that I do not keep the source code to myself and I do not only publish incomprehensible executables here. All written programs are plain text files readable by anyone who speaks the language. Only node.js translates these texts into an executable form at the moment it is to be executed. Therefore, you can study everything you find here and then modify it according to your needs. I would like to have some feedback from you. That's why I'm asking anyone who makes any adjustments to write to me about it. I also like to learn something. Thank you.

You can download the first trial version 1.0.1 at Files for Download / for HW version 1.x. How to use it is described at the bottom of the page Preparing the Raspberry Pi. For its functionality, it is necessary to install the onoff and libraries with the npm program.

The project consists of the following parts:

  • js directory, here are my files with javascript functions
  • pict directory, here are the images used on the website
  • favicon.ico file, a program icon that appears in the browser
  • index.html file, the basic Web page that appears in the browser
  • satprowler.js file, basic program for node.js

The web server does not use the standard web port 80, but 8080. If you mind, you can change the port number in the satprowler.js file. I wanted to differentiate the communication with the Raspberry Pi somehow. Therefore, it is necessary to enter the address in this format into the web browser.

Where xxx is the final two digits of the Raspberry Pi IP address, depending on your home network settings. Once connected, the following window will appear in the browser.


Fig. 1 SatProwler screen

Pressing any arrow button starts the corresponding motor. When released, the engine stops again. If you press the button, move the mouse outside it and release the mouse, the motor will remain running. Click the same button to stop it. It is a software bug, but this way you can verify that both engines can run at the same time.

Originally, that was all I asked for from the first test. Check motor control and direction of movement. But then I added a check of the input signals from the sensors. When any button is released, the values of all counters are displayed in the terminal window.

The value representing the state of the limit switches is first true. After switching on it changes to false, after opening it returns to true During testing I found out that the zero point switches close and open at different values of the pulse counter. Therefore, the original control unit will probably go over when searching for the zero point and then return a bit. This can be seen in the video on the page Introduction. The switch therefore has some hysteresis and the correct zero point is at the moment of opening the switch. I will also follow this rule in my programs. It is also necessary to take into account that these are mechanical switches with oscillations (repeated disconnection / connection due to the flexibility of the contacts). I do not solve this feature in ver.1.0.1.

In fact, I have no idea why both engines have two speed sensors. When counting input pulses from motors, SatProwler ver.1.0.1 counts the pulses of channel A and B into one counter. This doubles the number of pulses and thus the theoretical accuracy of the position setting. Whether this is the case, in fact, remains to be seen. The DC motor has a certain inertia and stopping it with an accuracy of 1 pulse will probably not be easy.

For the entire azimuth path in the range from -90° to +90°, my device counted approximately 36000 pulses (18000 pulses each channel), which means 200 pulses (100 pulses each channel) per degree. This corresponds to an accuracy of 0.01 degrees per pulse, as stated in the original user manual. For the entire elevation path ranging from 10° to 50°, my device counted approximately 32,000 (2 x 16,000) pulses, i.e. 800 (2 x 400) pulses per degree. This corresponds to an accuracy of 0.0025 degrees per pulse, as stated in the original user manual.

The web browser is currently communicating with the web server in one direction. This means that it sends a command to the server, but does not receive a confirmation that the server has received and executed it. The RelayOn and RelayOff functions are used to send the command. The first function is a command to close, the second to open a relay. Which relay (pair of relays when changing direction) the command refers to is defined by the number in parentheses. My library "js/driverfce.js" solves the way of sending the command to the server.

Another library "" provides network communication. Unfortunately, I haven't been able to place this library locally on the Raspberry Pi SD card yet, so I need Internet access for testing. This is the whole powerful part of the index.html file. Everything else concerns only the html standard or the page layout.

The satprowler.js file contains the entire server program. First, I declare variables for the state of the counters and define the default values. I set the counters to an imaginary value of 5000 and the state of the switches to a true. Then the onoff library is loaded, which directly controls the GPIO port pins. Subsequently, the parameters of the individual pins are defined. Anyone who uses other GPIO port pins must fix them here. But it must not forget that all inputs need to have active pullup resistors. The onoff library cannot turn them on, so the pin numbers in the config.txt file in the boot area of the SD card must also be corrected, as described on the Preparing the Raspberry Pi page and then restarting the Raspberry Pi.

The functions define the interrupt handling caused by changing the value on the input pins of the GPIO port. So far, there is only the addition or subtraction of 1 in the pulse counter according to the direction of rotation of the motor. The orgAZ and orgEL variables only change to false or true depending on the state of the switch. But when changed to true, the counter value is reset. From now on, they should calculate the correct value of the current position. The following is a feature that releases used Raspberry Pi interrupts before exiting the program. Function process.on ('SIGINT', unexportOnClose); on the contrary, it activates the defined interrupts.

This is followed by creating and starting your own web server. Here's how to respond to web client requests. Line http.listen (8080); defines on which port the server will listen. Here you can set the standard port 80 or anything else.

The rest is a description of what the server does after receiving a request to control GPIO ports. It uses the onoff library to set the required output values. Here we must make sure that the switching on / off of the relay for changing the direction of rotation is performed only when the motor is at rest.

From a professional point of view, the program has many shortcomings. But its purpose is not for normal use. It's just a matter of testing the functionality of the hardware. Nevertheless, after a careful approach to the limit switches, it could be used for repeated manual adjustment to the positions of the satellites, for which the values of the counters are recorded on a piece of paper. This would check the accuracy with which a certain position can be searched repeatedly. The measuring device would be a satellite receiver and its indicator of signal strength from the satellite.


No comments

Leave your comment

In reply to Some User