Sunday, November 5, 2017

بعض ادوات تطوير البرامج المجانية

 يمكنك الاستفادة من مجموعة ادوات مجانية في تصميم البرامج و الالعاب:
  1. لتصاميم ثلاثية الابعاد نزل برنامج Blender.  لمعرفة كيفية الاستخدام يمكنك مراجعة قسم الدعم او Support الذي يوفر الدليل الكامل للاستخدام.  Blender بديل ممتاز ل3D Studio Max و لكنه مبني على اساس الOpen Source.
  2. Unity الذي يمكنك من تصميم العاب الكمبيوتر و الجوال.  النسخة المجانية من البرنامج تعطيك الصلاحية في التعلم على الاستخدامو اذا اردت ان تنشر برامجك فذلك يتطلب اشتراك شهري بقيمة 35$.  تصميم اللعبة يتطلب لكتابة بعض نصوص البرمجة باستخدام لغة ال#C و بذلك قد يكون من المفيد ان تتعلم مبادئ اللغة قبل البدء بتصميم العابك.
  3. Visual Studio برنامج يوفر لك بيئة كاملة لبرمجة برامجك من الصفر.  توفر لك البيئة الامكانية في بدء برامجك بناء على قالب مبدئي (مثلا قالب خاص لتصميم المواقع و اخر لتصميم برامج الWindows). اضافة الى ذلك فات البيئة تسمح لك باضافة الكثير من الاضافات التي قد تسهل او تساعد على تصميم البرامج و التي يمكنك تنزيلها بناء على الحاجة.  أللغات الاساسية المتوفرة في Visual Studio هي #C و Visual Basic و ASPX و يمكنك اضافة ++C و Python و غيرها من اللغات
  4. Eclipse بيئة متكاملة لبرمجة جميع أنواع تطبيقات الJava و الذي تبدأ من برامج بسيطة الى أنظمة متكاملة (Enterprise Application)
  5. Netbeans يشبه Eclipse و لكنه اشتهر بتطوير برمجيات الجوالات البدائية (قبل الهواتف الذكية).  أن كان استخدام Eclipse صعبا قليلا حيث يستهدف المطور المتقدم بعض الشيء فان استخدام Netbeans ابسط و اسهل في تعلم لغة الJava.

Monday, September 4, 2017

Tutorial: Building Your First Drone

Developing Your First Robot

Scope

Develop a remote-controlled Drone with a camera feed. Requirement sparks from the need to investigate in small tight places. This is to help inspect specific environments that might prove difficult to reach without causing break and tear. Control is meant to be conducted through a laptop, mobile or tablet.

Requirements

Tools

  • Small flathead screwdriver (small electric testing screw driver will do the trick)
  • Glue Gun

Drone

  • Raspberry PI running the Raspbian OS (Follow NOOBs tutorial for setup [1])
  • Mobile Battery Pack
  • 2-Wheel chassis (will be used for prototype purpose but can be switched based on application)
  • L298N board (for a 2 DC motor chassis, might be required to swap out if chassis is changed)
  • USB WiFi adapter
  • Raspberry PI camera (using 5MP standard camera, can be changed in the event of application change)
  • LED (using a 3 color LED)
  • 9v Battery (connector might be useful but unnecessary)
  • Relevant jumper cables to connect it all together
  • 5V Battery Pack (To power the Raspberry PI, if Possible identify one with a 2mA current as it will affect the performance of the PI)

Client

Assembel It

  1. Connect the camera to its designated location on the raspberry pi
  2. LED has 4 connectors, Left to Right:
    1. Red
    2. Green
    3. Blue
    4. Ground
    using 4 female-to-female jumper cable, connect the 4 pins of the LED to the following pins in the same order as above, 3, 5, 7, 9 (where 9 is for ground)
  3. Connect the L298N board: the L298N board is split into 4 sections:
  4. Section on the left to control the left wheel, using 2 male-to-male jumper cable, connect the top slot on the L298N to the positive slot of the left DC wheel (on the chassis) and the bottom slot to the negative slot of the left DC wheel.
  5. Section on the right to control the right wheel, using 2 male-to-male jumper cable, connect the top slot on the L298N to the positive slot of the right DC wheel (on the chassis) and the bottom slot to the negative slot of the right DC wheel.
  6. On the top left slot, there are 4 pins that should be connected to the raspberry pi. The two on the left will control the left wheel, and the 2 on the right will control the right wheel. From Left to Right, connect the Pins in the following order 35, 37, 36, 38.
  7. On the top right side of the L298N board, there are three slot:
    1. using a male-to-male jumper cable, connect the right slot to the positive side of the 9V battery
    2. Using to jumper cables, connect the middle slot to the negative side of the 9V battery using a male-to-male jumper cable and to pin 39 using a male-to-female jumper cable
    3. leave the right left slot empty (you can potentially connect it to Pin 2 of the Raspberry PI but concern is that it will not be capable of providing the PI with a steady current which in turn will impact the stability of the PI.
  8. Connect the USB WiFi adapter to one of the USB slots on the raspberry PI
  9. Using a glue gun, fix everything in place to ensure it stays in place. ensure to fix the camera and the LED in place.

Configuring the Raspberry PI

  1. Run 'sudo apt-get update' and once completes, 'sudo apt-get upgrade' to ensure all dependencies have been applied
  2. using 'sudo apt-get install xxx' to install the following components where 'xxx' will be replaced by the component name:
    • 'hostapd' to enable the raspberry pi to act like a WiFi hotspot
    • 'dhcpd' to allow the pi to issue IP addresses for connectivity
    • 'oracle-java8-jdk' to get the latest Java Development Kit (can be replaced with ‘java’ in case of applying the solution)
    • 'vncserver' to enable remote desktop to Raspberry PI (Useful to run NetBeans, if using command line compiling, unneccesary)
  3. Install RPI Webcam (based on reference3)
  4. setup 'hostapd' and 'dhcpd' based on reference 2
  5. Download the latest "Netbeans" from 'http://http://netbeans.org/' and extract it. it might be useful to create a shortcut on the desktop.

Client

Configurations

  1. Install Visual Studio. Ensure to select Windows Desktop, .NET Framework 4.5 (or the latest) and Web components
  2. Connect to the Raspberry PI WiFi network you setup, I am using the SID "Drone"
  3. using putty, connect to the raspberry PI and ensure connectivity (I am using IP '192.168.15.1')
  4. Run 'vncserver :1' to enable X-Terminal
  5. using VNC client, connect to the PIs X Terminal using '192.168.15.1:1'
  6. Now you can directly configure the PI through the GUI interface or the Command Prompt as required.

Connection

Connection to the Drone will be connected through WiFi as it:
  • Helps with the distance that can be covered in contrast to bluetooth and infrared,
  • In addition, with WiFi, we can configure a Wireless LAN that is hosted from the PI which would simplify the development of a TCP/IP application,
  • Tutorials are readily available
  • Both Java and .NET cover it as part of their standard Framework.
  • Messages can be passed between client and server in ASCII format

Implementation

Writing the Raspberry PI code (Server)

Start

Setup TCP Listener
 Listen: Establish Connection
 Case to received command
  Light: Toggle Light 'On' or 'Off'
  Forward: Move Forward by setting pins 35 and 36 to true for 0.5 Secs
  Backward: Move Backward by Setting pins 37 and 38 to true for 0.25 Secs
  Left: In-Spot turn Left by switching pins 35 and 38 to true for 0.10 secs
  Right: In-Spot turn Right by switching pins 36 and 37 to true for 0.10 secs
  Default: Do nothing
 Terminate Connection
 Goto Listen

End

Writing the Client Code

Start

MainFrame: Execute Command
 Connect to Server on Listening Port
 Case to selected command
  Light: Send Light Command to Server
  Forward: Send Move Forward to Server
  Backward: Send Move Backward to Server
  Left: Send Turn Left to Server
  Right: Send Turn Right to Server
  Default: Do nothing
 Terminate Connection
 Goto MainFrame

End

Camera Feed

On Server: Modify main page of web page on PI to only display the webcam picture (continuously refreshed picture). This can be identified by going through the PHP page as downloaded by the RPI webcam solution and clearing everything that is not related to the <div> for the camera shot. Your new PHP file should be reduced to fit in a page or slightly over.
On Client: Using a web control, point the URI to the webcam page on the PI (can test URI using any browser)

Close

After Closure, what was developed was a base product of a remote controlled drone with a camera feed. The idea is to be able to investigate locations that are difficult to reach. Based on the applications (highlighted below), the drone can be customized further to be built for a specific need. The above details the implementation which covers details of the development of the base product. A good step forward might be to try to deploy it as a live solution and omitting out all development steps.

References:

  1. Installing Raspbian with NOOBS (19-Dec-2016)
  2. Setting Up a Raspberry Pi as a WiFi Access Point (19-Dec-2016)
  3. RPI-Webcam-Interface (24-Nov-2016)


Friday, December 13, 2013

Multi-Lingual JSF





The default answer to having a multilingual page when developing an application is to develop two pages. This will usually add the complexity of managing the pages by resulting in the added effort of maintaining both pages/forms when having adding/amending a function. A simple solution to the problem is by considering the language to be as a separate function and manage it accordingly.

In-line with the function of multi-lingual, let us use the terminology of Function-Oriented application (as a sub-level of OO) where the function of presentation is isolated from the function of language and, as such, is isolated from the core function of the application. Within JSF, you can easily isolate the functionality of a multi lingual application. Let us start by a bundle two bundle files (This can be in a database if you prefer). Here I will use Arabic and English

BundleEn.bundle


dir=ltr 
Previous=Previous   
Next=Next  

BundleAr.bundle

dir=rtl 
Previous=سابق   
next=التالي  

Then Create a Managed Bean with the scope set as Session Scoped (This is to ensure you maintain the selected language)



UserSession.java

@ManagedBean   
@SessionScoped   
public class UserSession implements Serializable{
      private String lang;   
     FacesContext ctx;     
     public void setAr(){   
     lang="Ar";  
        try {  
            ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();  
            ctx.redirect(ctx.getRequestContextPath());  
        } catch (IOException ex) {  
            Logger.getLogger(UserSession.class.getName()).log(Level.SEVERE, null, ex);  
        }  
    }  
    public void setEn(){  
        lang="En";  
        try {  
            ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();  
            ctx.redirect(ctx.getRequestContextPath());  
        } catch (IOException ex) {  
            Logger.getLogger(UserSession.class.getName()).log(Level.SEVERE, null, ex);  
        }  
    }  
      
    public String getLabel(String label){  
        try{  
            return ResourceBundle.getBundle("/Bundle"+lang).getString(label);  
        } catch (Exception e){  
            return "No Label for " + label;  
        }  
    }  
      
    public String getLang() {  
        return lang;  
    }  
  
    public void setLang(String lang) {  
        this.lang = lang;  
    }  
}  


Finally, your JSF page. Depending on the label you need to retrieve, you may use the expression language in the following form:
<h:form dir="#{userSession.getLabel('dir')}">  
    <p:commandLink value="English" action="#{userSession.setEn()}" />  
    <p:commandLink value="عربي" action="#{userSession.setAr()}"  />  
    <h:outputText value="#{userSession.getLabel('next')}"/>  
    <h:outputText value="#{userSession.getLabel('Previous')}"/>  
</h:form>  


where dir while define the orientation of the page (left to right or right to left), next and previous will refer to the label title next and Previous respectively in the bundle bundle file based on the selected language. By implementing you code in the above manner, you open the opportunity to configure new languages as you feel free and it will require minimum maintenance from a technical perspective.

Friday, May 3, 2013

Education of Trust in Saudi


Before acknowledging or denying the story, let me tell it to the end.  This is a story of how trust is educated in Saudi.  And although it may sound extreme, I myself would not have believed it if it was not for experiencing it first-hand.  Although the tale might be old, this is the case till today, and it pains me to realize that a country that claims to rule by the Islamic doctrine had failed to create a culture based on common trust between the individuals of its own public and, worse still, between the common public and the governmental.

Our story begins with the academic year of 95/96.  By "chance" our Religious Studies teacher was a fundamental Saudi traditionalist during that year, the same year in which around 75% of students in our school where failed in Religious Studies of which I escaped and my brother fell victim to.  Naturally Students and parents all complained due to the injustice that befell the students.  However, the school's headmaster refused to take a stance.  When we started to request our papers, all requests were rejected and at the start of the new academic year our papers were burnt for all to see in the school's playground.  This situation re-occurred the following year (my final year in intermediate school) in which (thankfully) both my brother and myself escaped failure.  Sadly the Ministry of Education and the school never issued any investigation into the issue.

Think of the implication the above story would have on a student as he is coming of age.  How can he grow to trust anyone?  Better yet, whether it is by chance or not, this happens to many in Saudi (maybe not to the extreme of burning the papers) especially those finalizing their education in institutes of higher education.  Students are failed due to a grudge by the educator, and the educator is rewarded while the student in question is penalized when attempting to expose the corrupt educator.  As such, students graduating into Saudi's growing job market (and new adults into the Saudi Community) are taught not in the best methods of being devious.  They are raised to lie and cheat.  Further yet, they are lectured on truth and honesty and trained on deceit and dishonesty.  Let me take this one step further.  If such tales happen in governmental educational facilities in Saudi, how do we expect to have a generation that truly trust the government official publication or, potentially, any governmental reports and claims?

So how do we fix the issue?  It all starts with the up-bringing.  Students need to be treated with trust (i.e. trust should be practiced not spoken about).  Once we have a good platform to start from, we start punishing the deceitful (regardless of rank).  So a teacher intentionally failing his students, should be punished accordingly.   This will give raise to a culture that believes and understands that lying and cheating is frowned upon by a system that is trying to build trust between its players.

It is not all lost on Saudi culture.  There is still hope to create a community based on trust and loyalty.  A culture that functions correctly and, in accordance, functions on the basis of Islamic values.  But we do need to action this now.  It is time to acknowledge that we. as a Saudi Muslim public, are flawed, that our social values need visiting and that we can potentially progress.  We need to step out of this persona that we have our unique situation (different from any other community) and are perfect in every way.  Once we step away from such arrogance and into a more modest lifestyle and by realistic with ourselves, we will have a chance to truly prevail.