2024年2月19日月曜日

raspiでseleniumの自動化用のファイル作り直し

2024/2/17に不注意でraspiのsdカードを壊し

jupyterファイルのバックアップを取らずにos再インストールを試みるという

愚行を重ねたためまたjupyterで作業ファイルを作ることになったので念の為

残しておく

途中なので要らない行も有るかも

これだけ再現できればやってたことは出来るのでよき



from selenium import webdriver

from selenium.webdriver import Chrome, ChromeOptions

from selenium.webdriver.common.keys import Keys

from selenium.webdriver.common.action_chains import ActionChains

from selenium.webdriver.common.by import By

from selenium.webdriver.chrome.service import Service 

import time


options1=ChromeOptions()

extension_path ='/home/pi/selenium1/Mouse-Coordinates.crx'

options1.add_extension(extension_path)

path1 = '/usr/bin/chromedriver'

driver1=Chrome(service=Service(path1),options=options1)


url1 = 'https://www.google.co.jp/'

driver1.get( url1 ) 

actions=ActionChains(driver1)


def pointclick(px,py):

  actions.move_by_offset(px,py).click().perform()

  actions.move_by_offset(-px,-py).click().perform()


serch_input=driver1.find_element(By.NAME,"q")

serch_input.send_keys('chatgpt')


pointclick(158,203)

time.sleep(2)

pointclick(405,272)




raspi4 のmicrosdが壊れたようなのでos再インストール

2024/2/17 

raspiを終了するときに直接 電源コネクタ抜いてたらraspiが起動しなくなった
os再インストールをしようとするが書き込みが19%で止まる
フォーマットも途中で止まる
microsdは壊れたようだ

ウィドウのraspiアイコンからシャットダウン

sudo poweroff 

でないとSDカードが壊れるらしい


128gb 800円弱のLAZOS の sdカードを買ってきた

rpi-imagerでosを再インストール
最後の最後でfatでosがなんたらエラー
最初にsdカードを初期化する必要があったようだ
rpi-imagerのCHOOSE OSから一番下のEraseで初期化
これでosがインストールできるようになった

os は raspbian 64bit bookworm

とりあえず動いている
ただデフォのconfig.txtをモニタ関連だけ書き換えても動かなかったので
以下を使用 コメントアウト部分は載せてない

disable_overscan=1

dtparam=audio=on

arm_64bit=1

[pi4]

# Enable DRM VC4 V3D driver on top of the dispmanx display stack

dtoverlay=vc4-fkms-v3d

max_framebuffers=2

[all]

hdmi_force_hotplug=1

hdmi_ignore_edid=0xa5000080

hdmi_cvt=1024 600 60 3

hdmi_group=2

hdmi_mode=88

start_x=1

gpu_mem=128

#以下はアクセスLEDチカチカを消すだけ (今回効いてない?)

dtparam=pwr_led_trigger=none,pwr_led_activelow=on

dtparam=act_led_trigger=none,act_led_activelow=on

dtparam=pwr_led_trigger=none,pwr_led_activelow=on


日本語IMEがないのでfcitx5をインストール

sudo apt install fcitx5-mozc
im-config -n fcitx5

再起動でいけた

最初 ibus-mozcをインストールしたが

1文字入力>候補ウィンドウ表示>フォーカス外れる>入力された文字が確定>候補ウィンドウ消える 

となり使えなかった


chromiumで日本語入力できない 以下で起動

chromium-browser --ozone-platform=x11

次はselenium 

2024 2/18 時点のraspiosはbookwormでpip install でエラーが出るようになったので

以下の設定が必要

mkdir ~/.config/pip

sudo nano ~/.config/pip/pip.conf

pip.confの内容は

[global]

break-system-packages = true

以上

で seleniumをインストールしchromium-chromedriverとchromium-browserを最新化する

pip install selenium

(だめならpip3 か pip3 install --break-system-packages nseleniumまたは

 pip3 install --break-system-packages --user selenium)

sudo apt install chromium-chromedriver

sudo apt install chromium-browser

このときdriber とbrowserのバージョンが同じでないと動かない

あとはpython scriptを準備して動けばOK

で次はjupyter

pip install jupyter 

でいけたみたい raspiアイコン>プログラミング>jupyter notebook があれば成功

再起動する


2024年2月11日日曜日

Ubuntu でマウスのダブルクリックの間隔を変更する場合

 アクティビティを開き”アクセシビリティ”で検索するとメニューが出る



マウスがチャタリングするのでダブルクリックの間隔を調整しようと検索すると

「アクティビティ画面を開き、universal access またはユニバーサルアクセスと入力します。」

とあるのが何故かユニバーサルアクセスは無く変わりに’アクセシビリティ’だった

2023年11月7日火曜日

Blenderのマウスカーソルがジャンプする問題

 起動オプションで --debug

blender --debug

とすれば中ボタンドラッグごのカーソルがジャンプする問題が解決した

https://projects.blender.org/blender/blender/issues/85014

より

2023年9月20日水曜日

ダイクストラ法

 chat-gptにコーディングしてもらったダイクストラ

「クラスカルでパスファインダーを」ってリクエストしたら

ダイクストラを勧められた

クラスカルが作るのは経路でなくツリーなのだ


    参考動画






<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/p5.js"></script>
<div id="p5canvas"></div>

<script>

class Graph {
  constructor() {
    this.vertices = [];
  }

  addVertex(x, y) {
    this.vertices.push({ x, y, edges: [] });
  }

  addEdge(source, destination, weight) {
    if (this.vertices[source] && this.vertices[destination]) {
      this.vertices[source].edges.push({ target: destination, weight });
      this.vertices[destination].edges.push({ target: source, weight });
    } else {
      throw new Error("Invalid vertex");
    }
  }

  calculateDistance(vertex1, vertex2) {
    const { x: x1, y: y1 } = this.vertices[vertex1];
    const { x: x2, y: y2 } = this.vertices[vertex2];
    return Math.hypot(x2 - x1, y2 - y1);
  }

  dijkstra(startVertex, endVertex) {
    const distances = Array(this.vertices.length).fill(Infinity);
    const visited = Array(this.vertices.length).fill(false);
    const previous = Array(this.vertices.length).fill(null);
    distances[startVertex] = 0;

    const queue = [{ vertex: startVertex, distance: 0 }];
    while (queue.length) {
      queue.sort((a, b) => a.distance - b.distance);
      const { vertex } = queue.shift();

      if (visited[vertex]) continue;
      visited[vertex] = true;

      if (vertex === endVertex) break;

      const neighbors = this.vertices[vertex].edges;
      neighbors.forEach(neighbor => {
        const newDistance = distances[vertex] + neighbor.weight;
        if (newDistance < distances[neighbor.target]) {
          distances[neighbor.target] = newDistance;
          previous[neighbor.target] = vertex;
          queue.push({ vertex: neighbor.target, distance: newDistance });
        }
      });
    }

    const path = [];
    let currentVertex = endVertex;
    while (currentVertex !== null) {
      path.unshift(currentVertex);
      currentVertex = previous[currentVertex];
    }
    return { distances, path };
  }

  printGraph() {
    for (let i = 0; i < this.vertices.length; i++) {
      const { x, y, edges } = this.vertices[i];
      console.log(`Vertex ${i} (${x}, ${y}) with edges:`);
      edges.forEach(edge => {
        console.log(`  -> Target: ${edge.target}, Weight: ${edge.weight}`);
      });
    }
  }
}

function getRandomInt(max) {
  return Math.floor(Math.random() * max);
}


// 使用例

let graph = new Graph();

const startVertex = 0;
const endVertex = 3;

let dijkRet;

const vtx=[50,200,350,500,125,275,425,125,275,425];
const vty=[150,150,150,150,75,75,75,225,225,225];


const edges=[
 [0,1,5],[1,2,5],[2,3,5],
 [4,5,5],[5,6,5],[7,8,5],[8,9,5],
 [0,4,5],[0,7,5],[1,4,5],[1,7,5],
 [1,5,5],[1,8,5],[2,5,5],[2,8,5],
 [2,6,5],[2,9,5],[3,6,5],[3,9,5],
 ];
 

function setup() {
  createCanvas(550, 500).parent("p5canvas");
  textSize(17);
  
  runDijkstra();
 }

 function runDijkstra(){ 
  graph=new Graph();
  for(let i=0;i<vtx.length;i++){
   graph.addVertex(vtx[i], vty[i]); 
  }

  for(let i=0;i<edges.length;i++){
   graph.addEdge(edges[i][0],edges[i][1],getRandomInt(10)+1); 
  }
   
  graph.printGraph();    
  dijkRet= graph.dijkstra(startVertex, endVertex);

  console.log(`Shortest Path from ${startVertex} to ${endVertex}: [${dijkRet.path.join(" -> ")}], Distance: ${dijkRet.distances[endVertex]}`);  
 }
  
 function mousePressed() {
  runDijkstra();
 }
 
 

 function draw() {
  background(100);
  
  stroke(255, 255, 155);
  strokeWeight(1);
  for(let i=0;i<graph.vertices.length;i++){
   fill(255);
   circle(graph.vertices[i].x,graph.vertices[i].y,15);
   for(let j=0;j<graph.vertices[i].edges.length;j++){
    let neiNum=graph.vertices[i].edges[j].target;
    
    if(neiNum>i){
     let x1=graph.vertices[i].x;
     let y1=graph.vertices[i].y;
     let x2=graph.vertices[neiNum].x;
     let y2=graph.vertices[neiNum].y;
     line(x1,y1,x2,y2);
    }
   }
  }
 
  for(let j=0;j<dijkRet.path.length-1;j++){
    let x1=graph.vertices[dijkRet.path[j]].x;
    let y1=graph.vertices[dijkRet.path[j]].y;
    let x2=graph.vertices[dijkRet.path[j+1]].x;
    let y2=graph.vertices[dijkRet.path[j+1]].y;
    fill(200,255,200);
    stroke(200,255,200);
    strokeWeight(5);
    line(x1,y1,x2,y2); 
  }
  
  
  for(let i=0;i<graph.vertices.length;i++){
   stroke(100);
   fill(100,255,100);
   text(i,graph.vertices[i].x,graph.vertices[i].y-10);
   for(let j=0;j<graph.vertices[i].edges.length;j++){
    let neiNum=graph.vertices[i].edges[j].target;    
    if(neiNum>i){
     let weit=graph.vertices[i].edges[j].weight;
     let x1=graph.vertices[i].x;
     let y1=graph.vertices[i].y;
     let x2=graph.vertices[neiNum].x;
     let y2=graph.vertices[neiNum].y;
     fill(240);
     text(weit,(x1+x2)/2,(y1+y2)/2);
    }
   }
  }
    
  noStroke(0);
  text("Shortest Path from  "+ startVertex+ "  to  " +endVertex+"  :",50,350);
  text("Distance:  "+dijkRet.distances[endVertex],50,370);
  text("[ "+dijkRet.path.join(" -> ")+" ]",50,400);
  text("When you click the mouse, it will recalculate.",50,480);

 }
</script>

2023年7月13日木曜日

p5.serialserverと p5.serial control と p5js用のローカルサーバーの メモ(arduinoと通信用)

rampsのarduinoとp5jsで通信したくなったので試行錯誤

p5.serialserverとp5.serial control が必要なようだ

(ローカルだけだとp5.serialcontrolはいらなかった、かつ

p5.serialcontrolはボーレート9600固定みたい。

macならなんとかなるみたいらしいが)

以下のサイトを参照

https://fabacademy.org/2022/labs/cpcc/students/garrett-nelson/assignments/week15/

https://itp.nyu.edu/physcomp/labs/labs-serial-communication/two-way-duplex-serial-communication-using-p5js/



p5.serialserverは

gitでクローンして(多分カレントディレクトリにクローンされた?)

git clone https://github.com/vanevery/p5.serialserver.git

インストール
npm install 
でできたようだ?
node startserver.js
で起動




p5.serialcontrolは
 p5.serialcontrol-linux-x64.zipをダウンロードしてunzip
中に有るp5.serialcontrolに実行権限を与え実行
すると
The display compositor is frequently crashing. Goodbye.
のエラーが出た
ので
コンソールから起動する あと末尾に以下のオプションを追加
--no-sandbox
これで起動した

ソースコードには以下を追加

<script language="javascript" type="text/javascript" src="https://cdn.jsdelivr.net/npm/p5.serialserver@0.0.28/lib/p5.serialport.js"></script>

でクロームでhtmlファイルを開けば見れる
ファイルの場所はどこでも良さそう




今回は必要なかったが忘れてたので

ローカルサーバーから起動しないとリソースとか読み込まないときなど

index.htmlを用意して

ターミナルでカレントディレクトリをファイルのフォルダにして

 npx --yes @js-primer/local-server

でサーバーを立ち上げて
ブラウザで
http://localhost:3000
に移動すると見える

node.jsらしい
node.jsはインストール済みだったので詳しくは
npxなんたらで検索したらいい



2023年6月20日火曜日

Arduino nano に12vを流すと挙動がおかしくなった

 Arduino nanoに12v定電圧電源をつないで使っていると挙動がおかしくなった
USB経由だと普通に動くのでオンボードのレギュレータが怪しい
調べるとレギュレータの放熱ができず壊れたようす


”電圧降下分は熱となり

L7805 では接合部 (ジャンクション) と周囲 (アンビエント) との熱抵抗 θja は TO-220 で 60°C/W 

Tj = (損失電力) * (熱抵抗) + (周囲温度)

ここで出力電流で 300mA 、周囲温度 30°C としたら、 (損失電力) = (入力電力) - (出力電力) はおよそ (12V * 0.3A) - (5V * 0.3A) = 2.7W - 1.5W = 2.1W ですから、 上の式とから次のようになります。

Tj = 1.2W * 60°C/W + 30°C = 126°C + 30°C = 156°C

絶対最大定格で動作時のジャンクションの最高温度は 125°C”


となるとヒートシンク必要なので外部にレギュレータをつけた

いまは普通に動いている



raspiでseleniumの自動化用のファイル作り直し

2024/2/17に不注意でraspiのsdカードを壊し jupyterファイルのバックアップを取らずにos再インストールを試みるという 愚行を重ねたためまたjupyterで作業ファイルを作ることになったので念の為 残しておく 途中なので要らない行も有るかも これだけ再現できれば...