PS2手柄遥控Arduino小车[通俗易懂]

PS2手柄遥控Arduino小车[通俗易懂]使用手柄遥控小车是经常要用到的,看到PS2手柄很6,就拿来尝试一下。PS2手柄是索尼的PlayStation2游戏机的遥控手柄,因为这款手柄性价比较高,按键丰富,方便扩展到其它应用中,后来有人将其通讯协议破解,使得手柄可以用在遥控其他电器上,比如遥控控制机器人小车。最主要的是这款手柄,拿来就可以用,有人已经将其通讯协议破解了。具体可以参考极客工坊。其PS2X_lib库,可以参见Github

大家好,又见面了,我是你们的朋友全栈君。

使用手柄遥控小车是经常要用到的,看到PS2手柄很6,就拿来尝试一下。
PS2手柄是索尼的PlayStation2游戏机的遥控手柄,因为这款手柄性价比较高,按键丰富,方便扩展到其它应用中,后来有人将其通讯协议破解,使得手柄可以用在遥控其他电器上,比如遥控控制机器人小车。

最主要的是这款手柄,拿来就可以用,有人已经将其通讯协议破解了。
具体可以参考极客工坊。 其PS2X_lib库,可以参见Github.
这种摇杆有无线的和有线的,都是连接到Arduino上,我用的是有线的。

这里写图片描述

1. 手柄测试

将库文件放入Arduino IDE的安装的libaries文件夹中。 然后可以使用其中的example 例程测试一下。
程序如下:

#include <PS2X_lib.h>  //for v1.6

/****************************************************************** * set pins connected to PS2 controller: * - 1e column: original * - 2e colmun: Stef? * replace pin numbers by the ones you use ******************************************************************/
#define PS2_DAT        13  //14 
#define PS2_CMD        11  //15
#define PS2_SEL        10  //16
#define PS2_CLK        12  //17

/****************************************************************** * select modes of PS2 controller: * - pressures = analog reading of push-butttons * - rumble = motor rumbling * uncomment 1 of the lines for each mode selection ******************************************************************/
//#define pressures true
#define pressures   false
//#define rumble true
#define rumble      false

PS2X ps2x; // create PS2 Controller Class

//right now, the library does NOT support hot pluggable controllers, meaning 
//you must always either restart your Arduino after you connect the controller, 
//or call config_gamepad(pins) again after connecting the controller.

int error = 0;
byte type = 0;
byte vibrate = 0;

// Reset func 
void (* resetFunc) (void) = 0;

void setup(){

  Serial.begin(115200);

  delay(500);  //added delay to give wireless ps2 module some time to startup, before configuring it

  //CHANGES for v1.6 HERE!!! **************PAY ATTENTION*************

  //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
  error = ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT, pressures, rumble);

  if(error == 0){
    Serial.print("Found Controller, configured successful ");
    Serial.print("pressures = ");
    if (pressures)
      Serial.println("true ");
    else
      Serial.println("false");
    Serial.print("rumble = ");
    if (rumble)
      Serial.println("true)");
    else
      Serial.println("false");
    Serial.println("Try out all the buttons, X will vibrate the controller, faster as you press harder;");
    Serial.println("holding L1 or R1 will print out the analog stick values.");
    Serial.println("Note: Go to www.billporter.info for updates and to report bugs.");
  }  
  else if(error == 1)
    Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips");

  else if(error == 2)
    Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips");

  else if(error == 3)
    Serial.println("Controller refusing to enter Pressures mode, may not support it. ");

  type = ps2x.readType(); 
  switch(type) {
    case 0:
      Serial.println("Unknown Controller type found ");
      break;
    case 1:
      Serial.println("DualShock Controller found ");
      break;
    case 2:
      Serial.println("GuitarHero Controller found ");
      break;
    case 3:
      Serial.println("Wireless Sony DualShock Controller found ");
      break;
   }
}

void loop() {
  /* You must Read Gamepad to get new values and set vibration values ps2x.read_gamepad(small motor on/off, larger motor strenght from 0-255) if you don't enable the rumble, use ps2x.read_gamepad(); with no values You should call this at least once a second */  
  if(error == 1){ //skip loop if no controller found
    resetFunc();
  }

  if(type == 2){ //Guitar Hero Controller
    ps2x.read_gamepad();          //read controller 

    if(ps2x.ButtonPressed(GREEN_FRET))
      Serial.println("Green Fret Pressed");
    if(ps2x.ButtonPressed(RED_FRET))
      Serial.println("Red Fret Pressed");
    if(ps2x.ButtonPressed(YELLOW_FRET))
      Serial.println("Yellow Fret Pressed");
    if(ps2x.ButtonPressed(BLUE_FRET))
      Serial.println("Blue Fret Pressed");
    if(ps2x.ButtonPressed(ORANGE_FRET))
      Serial.println("Orange Fret Pressed"); 

    if(ps2x.ButtonPressed(STAR_POWER))
      Serial.println("Star Power Command");

    if(ps2x.Button(UP_STRUM))          //will be TRUE as long as button is pressed
      Serial.println("Up Strum");
    if(ps2x.Button(DOWN_STRUM))
      Serial.println("DOWN Strum");

    if(ps2x.Button(PSB_START))         //will be TRUE as long as button is pressed
      Serial.println("Start is being held");
    if(ps2x.Button(PSB_SELECT))
      Serial.println("Select is being held");

    if(ps2x.Button(ORANGE_FRET)) {     // print stick value IF TRUE
      Serial.print("Wammy Bar Position:");
      Serial.println(ps2x.Analog(WHAMMY_BAR), DEC); 
    } 
  }
  else { //DualShock Controller
    ps2x.read_gamepad(false, vibrate); //read controller and set large motor to spin at 'vibrate' speed

    if(ps2x.Button(PSB_START))         //will be TRUE as long as button is pressed
      Serial.println("Start is being held");
    if(ps2x.Button(PSB_SELECT))
      Serial.println("Select is being held");      

    if(ps2x.Button(PSB_PAD_UP)) {      //will be TRUE as long as button is pressed
      Serial.print("Up held this hard: ");
      Serial.println(ps2x.Analog(PSAB_PAD_UP), DEC);
    }
    if(ps2x.Button(PSB_PAD_RIGHT)){
      Serial.print("Right held this hard: ");
      Serial.println(ps2x.Analog(PSAB_PAD_RIGHT), DEC);
    }
    if(ps2x.Button(PSB_PAD_LEFT)){
      Serial.print("LEFT held this hard: ");
      Serial.println(ps2x.Analog(PSAB_PAD_LEFT), DEC);
    }
    if(ps2x.Button(PSB_PAD_DOWN)){
      Serial.print("DOWN held this hard: ");
      Serial.println(ps2x.Analog(PSAB_PAD_DOWN), DEC);
    }   

    vibrate = ps2x.Analog(PSAB_CROSS);  //this will set the large motor vibrate speed based on how hard you press the blue (X) button
    if (ps2x.NewButtonState()) {        //will be TRUE if any button changes state (on to off, or off to on)
      if(ps2x.Button(PSB_L3))
        Serial.println("L3 pressed");
      if(ps2x.Button(PSB_R3))
        Serial.println("R3 pressed");
      if(ps2x.Button(PSB_L2))
        Serial.println("L2 pressed");
      if(ps2x.Button(PSB_R2))
        Serial.println("R2 pressed");
      if(ps2x.Button(PSB_TRIANGLE))
        Serial.println("Triangle pressed");        
    }

    if(ps2x.ButtonPressed(PSB_CIRCLE))               //will be TRUE if button was JUST pressed
      Serial.println("Circle just pressed");
    if(ps2x.NewButtonState(PSB_CROSS))               //will be TRUE if button was JUST pressed OR released
      Serial.println("X just changed");
    if(ps2x.ButtonReleased(PSB_SQUARE))              //will be TRUE if button was JUST released
      Serial.println("Square just released");     

    if(ps2x.Button(PSB_L1) || ps2x.Button(PSB_R1)) { //print stick values if either is TRUE
      Serial.print("Stick Values:");
      Serial.print(ps2x.Analog(PSS_LY), DEC); //Left stick, Y axis. Other options: LX, RY, RX 
      Serial.print(",");
      Serial.print(ps2x.Analog(PSS_LX), DEC); 
      Serial.print(",");
      Serial.print(ps2x.Analog(PSS_RY), DEC); 
      Serial.print(",");
      Serial.println(ps2x.Analog(PSS_RX), DEC); 
    }     
  }
  delay(50);  
}

在IDE中编译后下载到Arduino中,打开串口监视器,如果顺利,会看到显示下列提示:

如果提示未发现控制器,那就需要检查自己的连线等是不是有问题了,我在用的时候,因为杜邦线的问题,一直提示找不到控制器,我还怀疑是不是买的手柄有问题,又拿Stm32的板子来测试,折腾了半天竟然是线的问题。

连接后,按下手柄上的各个键都会有相应提示,可以看出哪个按键定义的什么名字。
在上述代码中,左边的四个按键只是显示按键按下,不会根据力的大小输出相应数值的,如果想要,就需要修改下列代码:

上述程序第20行到23行将注释调换一下条改为:

#define pressures   true
//#define pressures   false
#define rumble      true
//#define rumble      false

这样就可以实现通过按左侧”上下左右“按键的力度,输出不同的模拟值。

2. 小车电机控制

电机:有刷直流电机
驱动器:L298n逻辑
控制器:Arduino Mega2560

程序功能实现:
– 按下START键,开始前进;
– 通过按PS2手柄左边的“上下左右”键实现前进 、后退、左转、右转。
– 按SELECT键停止;

#include <PS2X_lib.h>  //for v1.6

/****************************************************************** * set pins connected to PS2 controller: * - 1e column: original * - 2e colmun: Stef? * replace pin numbers by the ones you use ******************************************************************/
//PS2手柄引脚;
#define PS2_DAT        13  //14 
#define PS2_CMD        11  //15
#define PS2_SEL        10  //16
#define PS2_CLK        12  //17

// 电机控制引脚;
#define IN1 4
#define IN2 5
#define IN3 6
#define IN4 7

 //PWM控制引脚;
  int speedPinA = 8;
  int speedPinB = 9;

int speed;

/****************************************************************** * select modes of PS2 controller: * - pressures = analog reading of push-butttons * - rumble = motor rumbling * uncomment 1 of the lines for each mode selection ******************************************************************/
#define pressures   true
//#define pressures false
#define rumble      true
//#define rumble false

PS2X ps2x; // create PS2 Controller Class

//right now, the library does NOT support hot pluggable controllers, meaning 
//you must always either restart your Arduino after you connect the controller, 
//or call config_gamepad(pins) again after connecting the controller.

int error = 0;
byte type = 0;
byte vibrate = 0;

 void setup(){

   pinMode(IN1, OUTPUT);
   pinMode(IN2, OUTPUT);
   pinMode(IN3, OUTPUT);
   pinMode(IN4, OUTPUT);

   speed =200;

   Serial.begin(57600);
   delay(300) ; //added delay to give wireless ps2 module some time to startup, before configuring it
   //CHANGES for v1.6 HERE!!! **************PAY ATTENTION*************

  //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
  error = ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT, pressures, rumble);

  if(error == 0){
    Serial.print("Found Controller, configured successful ");
    Serial.print("pressures = ");
  if (pressures)
    Serial.println("true ");
  else
    Serial.println("false");
  Serial.print("rumble = ");
  if (rumble)
    Serial.println("true)");
  else
    Serial.println("false");
    Serial.println("Try out all the buttons, X will vibrate the controller, faster as you press harder;");
    Serial.println("holding L1 or R1 will print out the analog stick values.");
    Serial.println("Note: Go to www.billporter.info for updates and to report bugs.");
  }  
  else if(error == 1)
    Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips");

  else if(error == 2)
    Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips");

  else if(error == 3)
    Serial.println("Controller refusing to enter Pressures mode, may not support it. ");

 // Serial.print(ps2x.Analog(1), HEX);

  type = ps2x.readType(); 
  switch(type) {
    case 0:
      Serial.print("Unknown Controller type found ");
      break;
    case 1:
      Serial.print("DualShock Controller found ");
      break;
    case 2:
      Serial.print("GuitarHero Controller found ");
      break;
  case 3:
      Serial.print("Wireless Sony DualShock Controller found ");
      break;
   }
}

 void turnLeft(){
   digitalWrite(IN1,HIGH);
   digitalWrite(IN2, LOW);
   digitalWrite(IN3, LOW);
   digitalWrite(IN4,HIGH);
}
 void turnRight(){
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);      
}

 void forward(){
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);      
}

 void back(){
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);     
}

 void loop(){
   /* You must Read Gamepad to get new values and set vibration values ps2x.read_gamepad(small motor on/off, larger motor strenght from 0-255) if you don't enable the rumble, use ps2x.read_gamepad(); with no values You should call this at least once a second */  
  if(error == 1) //skip loop if no controller found
    return; 

  if(type == 2) {
  
  //Guitar Hero Controller
  return;
  }
  else  { //DualShock Controller
    ps2x.read_gamepad(false, vibrate); //read controller and set large motor to spin at 'vibrate' speed


//start 开始运行,电机初PWM为120;
    if(ps2x.Button(PSB_START))  {
       Serial.println("Start is being held");
       speed = 120;
       analogWrite(speedPinA, speed);
       analogWrite(speedPinB, speed);
       forward();                  
    }
// 电机正转;
    if(ps2x.Button(PSB_PAD_UP)){
      Serial.println("Up held this hard: ");
      speed= 200;
      analogWrite(speedPinA, speed);
      analogWrite(speedPinB, speed);
      forward();                  
    }

// 电机反转;
    if(ps2x.Button(PSB_PAD_DOWN)){
      Serial.print("Down held this hard: ");
      speed= 200;
      analogWrite(speedPinA, speed);
      analogWrite(speedPinB, speed);
      back();                  
    }

 //左转; 
    if(ps2x.Button(PSB_PAD_LEFT)){
       Serial.println("turn left ");
       analogWrite(speedPinA, speed);
       analogWrite(speedPinB, 0);
      turnLeft();        
    }

//右转;
   if(ps2x.Button(PSB_PAD_RIGHT)){
    Serial.println("turn right");
    analogWrite(speedPinA, 0);
    analogWrite(speedPinB, speed);
    turnRight();
   }
// Stop
   if(ps2x.Button(PSB_SELECT)){
   Serial.println("stop");
   speed = 0;
   analogWrite(speedPinA,speed);
   analogWrite(speedPinB,speed);
   }

  }
}

目前是拿来尝试一下,还是基于按键的实现,后面用摇杆来控制方向的速度。

3. 摇杆控制

功能实现:

  • 通过按PS2摇杆的“上下左右”移动实现前进 、后退、左转、右转。
  • 速度随摇杆位置变化而变化;


/* 功能:通过按PS2摇杆的“上下左右”移动实现前进 、后退、左转、右转。 * * 作者:lcl; */ #include <PS2X_lib.h> //for v1.6 /****************************************************************** * set pins connected to PS2 controller: * - 1e column: original * - 2e colmun: Stef? * replace pin numbers by the ones you use ******************************************************************/ //PS2手柄引脚; #define PS2_DAT  13 //14  #define PS2_CMD  11 //15 #define PS2_SEL  10 //16 #define PS2_CLK  12 //17 // 电机控制引脚; #define IN1 4 #define IN2 5 #define IN3 6 #define IN4 7 int speedPinA = 8; int speedPinB = 9; int speed; //speed =200; /****************************************************************** * select modes of PS2 controller: * - pressures = analog reading of push-butttons * - rumble = motor rumbling * uncomment 1 of the lines for each mode selection ******************************************************************/ #define pressures true //#define pressures false #define rumble true //#define rumble false PS2X ps2x; // create PS2 Controller Class //right now, the library does NOT support hot pluggable controllers, meaning //you must always either restart your Arduino after you connect the controller, //or call config_gamepad(pins) again after connecting the controller. int error = 0; byte type = 0; byte vibrate = 0; void setup(){ pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); Serial.begin(57600); delay(300) ; //added delay to give wireless ps2 module some time to startup, before configuring it //CHANGES for v1.6 HERE!!! **************PAY ATTENTION************* //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error error = ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT, pressures, rumble); if(error == 0){ Serial.print("Found Controller, configured successful "); Serial.print("pressures = "); if (pressures) Serial.println("true "); else Serial.println("false"); Serial.print("rumble = "); if (rumble) Serial.println("true)"); else Serial.println("false"); Serial.println("Try out all the buttons, X will vibrate the controller, faster as you press harder;"); Serial.println("holding L1 or R1 will print out the analog stick values."); Serial.println("Note: Go to www.billporter.info for updates and to report bugs."); } else if(error == 1) Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips"); else if(error == 2) Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips"); else if(error == 3) Serial.println("Controller refusing to enter Pressures mode, may not support it. "); // Serial.print(ps2x.Analog(1), HEX); type = ps2x.readType(); switch(type) { case 0: Serial.print("Unknown Controller type found "); break; case 1: Serial.print("DualShock Controller found "); break; case 2: Serial.print("GuitarHero Controller found "); break; case 3: Serial.print("Wireless Sony DualShock Controller found "); break; } } void turnLeft() //左转 { digitalWrite(IN1,HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4,LOW); delay(20); } void turnRight()//右转 { digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); delay(20); } void forward() // 前进 { digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); delay(20); } void stop() // 停止; { digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); delay(20); } void back() //后退 { digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH); } void loop(){ /* You must Read Gamepad to get new values and set vibration values ps2x.read_gamepad(small motor on/off, larger motor strenght from 0-255) if you don't enable the rumble, use ps2x.read_gamepad(); with no values You should call this at least once a second */ if(error == 1) //skip loop if no controller found return; if(type == 2) { 
   //Guitar Hero Controller return; } else { //DualShock Controller ps2x.read_gamepad(false, vibrate); //read controller and set large motor to spin at 'vibrate' speed if(ps2x.Button(PSB_L1) || ps2x.Button(PSB_R1)) { //print stick values if either is TRUE Serial.print("Stick Values:"); Serial.print(ps2x.Analog(PSS_LY), DEC); //Left stick, Y axis. Other options: LX, RY, RX Serial.print(","); Serial.print(ps2x.Analog(PSS_LX), DEC); Serial.print(","); Serial.print(ps2x.Analog(PSS_RY), DEC); Serial.print(","); Serial.println(ps2x.Analog(PSS_RX), DEC); int LY=ps2x.Analog(PSS_LY); int LX=ps2x.Analog(PSS_LX); int RY=ps2x.Analog(PSS_RY); int RX=ps2x.Analog(PSS_RX); if (LY<128) //前进 { speed = 2*(127-LY); //speed = LY; analogWrite(speedPinA, speed); analogWrite(speedPinB, speed); forward(); } //后退 if (LY>128) { speed=2*(LY-128); analogWrite(speedPinA, speed); analogWrite(speedPinB, speed); back(); } //左转 if (LX<128) { speed = 2*(127-LX); analogWrite(speedPinA, speed); analogWrite(speedPinB, speed); turnLeft(); } //右转 if (LX>128) { speed=2*(LX -128); analogWrite(speedPinA, speed); analogWrite(speedPinB, speed); turnRight(); } //如果摇杆居中 if (LY>=128 && LY<=128 && LX>=128 && LX<=128) { stop(); } } } 

相关参考:
1. http://yfrobot.com/forum.php?mod=viewthread&tid=11561&highlight=ps2
2. Sony PS2游戏手柄遥控智能小车https://sanwen8.cn/p/375swwM.html
3. SONY PS2电玩手柄遥控乐高小车

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/130367.html原文链接:https://javaforall.net

(0)
上一篇 2022年6月14日 下午1:00
下一篇 2022年6月14日 下午1:16


相关推荐

  • Luci App OpenClaw – 在路由器上运行 OpenClaw / OpenWrt 管理插件

    Luci App OpenClaw – 在路由器上运行 OpenClaw / OpenWrt 管理插件

    2026年3月13日
    5
  • 如何进行大数据处理?大数据处理的方法步骤[通俗易懂]

    如何进行大数据处理?大数据处理的方法步骤[通俗易懂]1.大数据处理之一:采集大数据的采集是指利用多个数据库来接收发自客户端(Web、App或者传感器形式等)的数据,并且用户可以通过这些数据库来进行简单的查询和处理工作。比如,电商会使用传统的关系型数据库MySQL和Oracle等来存储每一笔事务数据,除此之外,Redis和MongoDB这样的NoSQL数据库也常用于数据的采集。在大数据的采集过程中,其主要特点和挑战是并发数高,因为同时有…

    2022年5月16日
    77
  • 用白码,快速实现企业微信群发消息

    用白码,快速实现企业微信群发消息好久没更新啦 目前我正在通过白码低代码开发平台开发一个 crm 系统 主要用于管理 c 端客户 最近就想做一个群发消息功能 因为客户是在企业微信上和消费者直接交流的 偶尔还会拉个群 在白码平台上可通过 API 对接使用企业微信官网的接口实现群发消息功能 正好 平台也提供了封装好的企业微信 API 直接就能调用了 如果需要通过第三方应用对接企业微信 API 就需要现在企业微信后台创建一个应用 但平台已经提供了自动集成的功能 集成后就可以直接使用平台提供的第三方类型企业微信 API 目标在 crm 上实现群发消息功能 企业

    2026年3月19日
    1
  • vscode一键注释_vscode代码缩进快捷键

    vscode一键注释_vscode代码缩进快捷键新建HTML文件时,输入感叹号(!),按tab键,系统没有反应,不会自动补全。新版本用html:5会自动补全

    2022年8月22日
    7
  • 成功解决urllib.error.URLError urlopen error Errno 11004 getaddrinfo failed

    成功解决urllib.error.URLError urlopen error Errno 11004 getaddrinfo failed成功解决 urllib error URLError urlopenerror Errno11004 getaddrinfof 目录解决问题解决思路解决方法第一步 找到新的网址第二步 查看源代码 将网址覆盖即可 解决问题 urllib error URLError urlopenerror Errno11004 getaddrinfof 解决思路 urll urlopenerror Errno11004 getaddrinfof urlopenerror Errno11004 getaddrinfof

    2026年3月17日
    1
  • linux node升级_linux系统升级到指定版本

    linux node升级_linux系统升级到指定版本问题在docker容器中启动node项目,但不希望每次都要npmi,所以要把源代码采用挂载的方式,放在镜像中。需要在服务器中npmi,之后启动容器,结果报错了,原因是node版本不对。后来采用了先挂载安装包,后再启动容器。其实我们可以选择升级一下本地主机的node版本就方便多了升级nodenode-v 首先清理npm的缓存 npmcacheclean-f 安装版本管理工具 npminstall-gn 更新到最新的版本 nl..

    2025年6月10日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号