poniedziałek, 27 sierpnia 2018

PROLOG Listy - Ostatni element listy

Treść zadania:
Napisz predykat który wybierze ostatni elementy z listy L.
Argumentem dla predykatu jest list n-elementowa.

Przykład:

Input:
last_element(X,[1,2,3,4,5]).

Output:
5


Input:
last_element(X,[a,b,c,d,e]).

Output:
e


Kod źródłowy:
last_element(X,[X]).
last_element(X,[_|O]):-last_element(X,O).

poniedziałek, 13 sierpnia 2018

PROLOG Listy - Znaki pomiędzy elementami listy

Treść zadania:
Napisz predykat char_between_list(L), który wyświetla elementy listy oddzielając je znakiem "|".
argumentem dla predykatu jest lista.

Przykład:
Input:
char_between_list([a,b,c,d]).

Output:
a|b|c|d|


Input:
char_between_list([1,2,3,4]).

Output:
1|2|3|4|

Kod źródłowy:
char_between_list([]).
char_between_list([X|Y]):- write(X),write('|'),char_between_list(Y).

wtorek, 10 lipca 2018

How to install MATE Desktop Environment in CentOS 7 minimal - full guide

MATE Desktop is Linux GUI based on GNOME 2
Installing MATE on Centos 7 is easy.

First step:
Check internet connection, if you want use DHCP run this:
dhclient

If internet connection is working update pckage:
yum update

Install epel-release:
yum install epel-release

Install kernel-devel:
yum install kernel-devel

Install X Window system:
yum groupinstall "X Window system"

Install MATE Desktop:
yum groupinstall "MATE Desktop"

Now you can run MATE Desktop using:
systemctl isolate graphical.target

Set MATE Desktop Environment as deflaut GUI:
systemctl set-default graphical.target
rm '/etc/systemd/system/default.target'
ln -s '/usr/lib/systemd/system/graphical.target' '/etc/systemd/system/default.target'

If something goes wrong install Development Tools:
yum groupinstall "Development Tools"


Optional is install GNOME Disc Utility:
yum install gnome-disk-utility

Best of the best for using KVM over IP to remote administration.
MATE Desktop homepage:
https://mate-desktop.org/

środa, 4 lipca 2018

Problem with power off computer in Windows 10 - guide to fix it

Problem description:
When power off computer use log out and show start screen but can't power off computer.

Platform:
Windows 10 64-bit

Solutions:
In control panel in "Hardwear and Sound" (polish: Sprzęt i dźwięk) select "Change what the power buttons do" (polish: Zmień działanie przycisków zasilania) and click on: "Change settings that are currently unavailable" (polish: Zmień ustawienia, które są obecnie niedostępne). Uncheck all option. Problem was fixed.

How to build GDAL from source for Visual C++ in Visual Studio

The goal of the project:
Download, compile and add GDAL library for Visual C++ project in Visual Studio IDE.

What is a GDAL?
is a translator library for raster and vector geospatial data formats that is released under an X/MIT style Open Source license by the Open Source Geospatial Foundation. As a library, it presents a single raster abstract data model and single vector abstract data model to the calling application for all supported formats. It also comes with a variety of useful command line utilities for data translation and processing. The NEWS page describes the June 2018 GDAL/OGR 2.3.1 release.

Source: http://www.gdal.org

Step 1:

Visit in GDAL website (http://www.gdal.org) and go to section "Developer Oriented Documentation" after that enter "Building GDAL From Source".
Link: http://trac.osgeo.org/gdal/wiki/BuildHints













Step 2:

Download source package (I recomend lastest stable release).
For windows it is gdal.zip
example: gdal321.zip














Step 3:
Unzip it uzing 7ZIP, WinRAR or another tool for unzip file.














Step 4:
Run power shell (or command line [cmd.exe]):














Step 5:
Run generate_vcxproj.bat script in Power Shell with parametrs.
Instruction and description:
https://trac.osgeo.org/gdal/wiki/GeneratingVisualStudioProject













Step 6:
Run gdal_vsXXXX.vcxproj in visual studio
Where XXXX - version of visual studio
example: gdal_vs2015.vcxproj













Step 7:
Build project in visual studio
Use Build -> Build Solutions
or use CTRL + SHIFT + B














Sucessful compilation:













Step 8:
Create new Visual C++ project in Visual studio.















Select finish.
















Build project for test.
If use x64 processor set project to x64.














Stel 9:
Add GDAL library and other GDAL files to this project.
Select "properties" from project.













In VC++ Directories edit Include Directores:














Add directories:
C:\Users\zoz\Desktop\gdal-2.3.1
C:\Users\zoz\Desktop\gdal-2.3.1\gcore
C:\Users\zoz\Desktop\gdal-2.3.1\apps
C:\Users\zoz\Desktop\gdal-2.3.1\port
C:\Users\zoz\Desktop\gdal-2.3.1\ogr
"zoz" is username.














Add to Library Directories:
$C:\Users\zoz\Desktop\gdal-2.3.1
$C:\Users\zoz\Desktop\gdal-2.3.1\gcore
$C:\Users\zoz\Desktop\gdal-2.3.1\port
$C:\Users\zoz\Desktop\gdal-2.3.1\apps
$C:\Users\zoz\Desktop\gdal-2.3.1\ogr














Add in Linker -> Input -> Additional Dependencies
"C:\Users\zoz\Desktop\gdal-2.3.1\gdal_i.lib"
Click EDIT in this selection




























If add GDAL library is could successful build.
#include














Main site of project:
http://www.gdal.org
GDAL FAQ:
http://trac.osgeo.org/gdal/wiki/FAQ

Used softweare:
Windows 10 64-bit PRO
GDAL version: 2.3.1
Microsoft Visual Studio 2015 version 14.0.25431.01 Update 3
Microsoft .NET Framework 4.7.03056














Video on youtube:
https://youtu.be/Yf8rYOfvZjY

sobota, 21 kwietnia 2018

Lazy Robot V1 - Część 6/8 - Moduł bluetooth i komunikacja

Podłączenie do modułu:



















Kod źródłowy:
/*                      Download from Lazy Admin Blog                        */
/* Blog URL:     https://lazyadminblog.blogspot.com                          */
/* Mail:         lazychannelandblog@gmail.com                                */
/* YouTube:      https://www.youtube.com/channel/UC8DB_NVekpEIuG-SAvpXOWQ    */
/* GitHub:       https://github.com/LazyAdminBlog                            */

int BLUETOOTH_SERIAL_INPUT; /* Variable to save input data from bluetooth module */

void setup()
{
  Serial1.begin(9600);  /* Begin serial port (bluetooth port). Set the data rate in bits (9600 bits per second (baud). */
  Serial1.println("Bluetooth X-Bee comunication test sucessful.");  /* Write to serial port (bluetooth) control text. */
}

void loop()
{
  if(Serial1.available() >= 0) /* Check available of serial port (bluetooth) and chack which number was input (if >= go to next step). */
  {
      BLUETOOTH_SERIAL_INPUT = Serial1.read();  /* Read data from serial port (bluetooth) and save to BLUETOOTH_SERIAL_INPUT variable */
  }
  switch(BLUETOOTH_SERIAL_INPUT)              /*  Switch case instruction to control robot                                  */
  {
    case '1':
      Serial1.println("First test pass.");   /* Write text: "First test pass." if read "1" from serial port (bluetooth).  */
      break;
    case '2':
      Serial1.println("Second test pass.");  /* Write text: "Second test pass." if read "2" from serial port (bluetooth). */
      break;
    default:
      break;
  }
}

Lazy Robot V1 - Część 5/8 - Sterowanie napędem robota

    W tej części opiszę sterowanie silnikami napędowymi robota. Na płytce Romeo V2 znajduje się układ sterowania silnikami L298P, za jego pomocą będziemy mogli manipulować prędkością oraz kierunkiem obrotu silników lub je zatrzymać.

Na płytce Romeo V2 należy ustawić odpowiednio cztery zworki.
Znajdują się one w sekcji Motor Mode Jump (zaznaczone kolorem fioletowym).



















Poprawne ustawienie zworek przedstawia obrazek:


















Podłączenie silników do modułu:














Kod źródłowy:
/*                      Download from Lazy Admin Blog                        */
/* Blog URL:     https://lazyadminblog.blogspot.com                          */
/* Mail:         lazychannelandblog@gmail.com                                */
/* YouTube:      https://www.youtube.com/channel/UC8DB_NVekpEIuG-SAvpXOWQ    */
/* GitHub:       https://github.com/LazyAdminBlog                            */

int MOTOR_1_RIGHT_DIRECTION = 4; /* Variable to save Motor 1 direction.      */
int MOTOR_1_RIGHT_SPEED = 5;  /* Variable to save Motor 1 speed (values from 0 to 255). */

int MOTOR_2_LEFT_SPEED = 6;   /* Variable to save Motor 2 speed (values from 0 to 255). */
int MOTOR_2_LEFT_DIRECTION = 7;  /* Variable to save Motor 2 direction      */

void motor_stop(void) /* Function to stop robot (stop motors) */
{
  digitalWrite(MOTOR_1_RIGHT_SPEED,LOW); /* Set low signal on right motor                */
  digitalWrite(MOTOR_2_LEFT_SPEED,LOW);  /* Set low signal on left motor                */
}

void motor_drive_forward(char a, char b)      /* Function to driveing forward using motors    */
{
  analogWrite(MOTOR_1_RIGHT_SPEED,a);         /* Set speed of right motor                     */
  digitalWrite(MOTOR_1_RIGHT_DIRECTION,LOW);  /* Set low signal on right motor                */
  analogWrite(MOTOR_2_LEFT_SPEED,b);          /* Set speed of left motor                      */
  digitalWrite(MOTOR_2_LEFT_DIRECTION,LOW);   /* Set low signal on left motor                 */
}

void motor_drive_back(char a, char b)         /* Function to driveing back using motors */
{
  analogWrite(MOTOR_1_RIGHT_SPEED,a);         /* Set speed of right motor               */
  digitalWrite(MOTOR_1_RIGHT_DIRECTION,HIGH); /* Set high signal on right motor         */
  analogWrite(MOTOR_2_LEFT_SPEED,b);          /* Set speed of left motor                */
  digitalWrite(MOTOR_2_LEFT_DIRECTION,HIGH);  /* Set high signal on left motor          */
}

void motor_turn_right(char a, char b)    /* Fuction to turn right the robot.  */
{
  analogWrite(MOTOR_1_RIGHT_SPEED,a);         /* Set speed of right motor               */
  digitalWrite(MOTOR_1_RIGHT_DIRECTION,LOW);  /* Set low signal on right motor          */
  analogWrite(MOTOR_2_LEFT_SPEED,b);          /* Set speed of left motor                */
  digitalWrite(MOTOR_2_LEFT_DIRECTION,HIGH);  /* Set high signal on left motor          */
}

void motor_turn_left(char a, char b)    /* Fuction to turn left the robot.  */
{
  analogWrite(MOTOR_1_RIGHT_SPEED,a);         /* Set speed of right motor               */
  digitalWrite(MOTOR_1_RIGHT_DIRECTION,HIGH); /* Set high signal on right motor         */
  analogWrite(MOTOR_2_LEFT_SPEED,b);          /* Set speed of left motor                */
  digitalWrite(MOTOR_2_LEFT_DIRECTION,LOW);   /* Set low signal on left motor           */
}

void setup()
{
  /* Set pins 4, 5, 6,7 as OUTPUT (pins for left and right motor */
  for(int i=4; i<=7; ++i)
  {
    pinMode(i,OUTPUT); /* Mode pin "i" as output pin. */
  }
}

void loop()
{
  motor_drive_forward(255,255); /* Drive forwart with maximal speed           */
  delay(8000);     /* Wait 8 secound                */
  motor_stop();     /* Stop all motos                */
  delay(8000);     /* Wait 8 secound                 */
  motor_drive_back(255,255); /* Drive back with maximal speed            */
  delay(8000);     /* Wait 8 secound                 */
  motor_stop();     /* Stop all motos                */
  delay(8000);     /* Wait 8 secound                 */
  motor_turn_right(150,150); /* Turn right with 150/255 speed. It is minimal speed for rotate robot   */
  delay(8000);     /* Wait 8 secound                 */
  motor_stop();     /* Stop all motos                */
  delay(8000);     /* Wait 8 secound                 */
  motor_turn_left(150,150);  /* Turn left with 150/255 speed. It is minimal speed for rotate robot   */
  delay(8000);     /* Wait 8 secound                 */
  motor_stop();     /* Stop all motos                */
  delay(8000);     /* Wait 8 secound                 */
}



Opis sterowania silnikami na stronie producenta:
https://www.dfrobot.com/wiki/index.php/Romeo_V2-All_in_one_Controller_(R3)_(SKU:DFR0225)

Źródło zdjęcia z pinami Romeo V2:
https://www.dfrobot.com/wiki/index.php/File:RomeoV2R3.png
Źródło zdjęcia z ustawieniami zworek pinów silników:
https://www.dfrobot.com/wiki/index.php/File:RomeoMotorJmp.png