Skip to content

Commit

Permalink
Merge pull request #5 from smfox10/master
Browse files Browse the repository at this point in the history
GeekServo 5KG舵机支持
  • Loading branch information
hogan96 authored Sep 27, 2023
2 parents 7cafe48 + 9d6f982 commit ca5a360
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
2 changes: 2 additions & 0 deletions _locales/zh-cn/robotbit-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"robotbit.Servo|block": "9g舵机|%index|角度 %degree",
"robotbit.GeekServo|block": "Geekservo|9g舵机|%index|角度 %degree",
"robotbit.GeekServo2KG|block": "Geekservo|2KG舵机|%index|角度 %degree",
"robotbit.GeekServo5KG|block": "Geekservo|5KG舵机|%index|角度 %degree",
"robotbit.GeekServo5KG_Motor|block": "Geekservo|5KG舵机_电机|%index|速度 %speed",
"robotbit.StepperDegree|block": "步进 28BYJ-48|%index|角度 %degree",
"robotbit.StepperTurn|block": "步进 28BYJ-48|%index|圈数 %turn",
"robotbit.StepperDual|block": "双步进(角度) |M1 %degree1| M2 %degree2",
Expand Down
2 changes: 2 additions & 0 deletions _locales/zh-tw/robotbit-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"robotbit.Servo|block": "9g舵機|%index|角度 %degree",
"robotbit.GeekServo|block": "Geekservo|9g舵機|%index|角度 %degree",
"robotbit.GeekServo2KG|block": "Geekservo|2KG舵機|%index|角度 %degree",
"robotbit.GeekServo5KG|block": "Geekservo|5KG舵機|%index|角度 %degree",
"robotbit.GeekServo5KG_Motor|block": "Geekservo|5KG舵機_馬達|%index|速度 %speed",
"robotbit.StepperDegree|block": "步進 28BYJ-48|%index|角度 %degree",
"robotbit.StepperTurn|block": "步進 28BYJ-48|%index|圈數 %turn",
"robotbit.StepperDual|block": "雙步進(角度) |M1 %degree1| M2 %degree2",
Expand Down
42 changes: 42 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,48 @@ namespace robotbit {
let value = v_us * 4096 / 20000
setPwm(index + 7, 0, value)
}

/**
* GeekServo5KG
* @param index Servo Channel; eg: S1
* @param degree [0-360] degree of servo; eg: 0, 180, 360
*/
//% blockId=robotbit_gservo5kg block="GeekServo5KG|%index|degree %degree"
//% group="Servo" weight=59
//% degree.min=0 degree.max=360
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
export function GeekServo5KG(index: Servos, degree: number): void {
if (!initialized) {
initPCA9685()
}
const minInput = 0;
const maxInput = 355;//理论值为360
const minOutput = 500;
const maxOutput = 2500;
const v_us = ((degree - minInput) / (maxInput - minInput)) * (maxOutput - minOutput) + minOutput;

let value = v_us * 4096 / 20000
setPwm(index + 7, 0, value)
}

//% blockId=robotbit_gservo5kg_motor block="GeekServo5KG_MotorEN|%index|speed %speed"
//% group="Servo" weight=58
//% speed.min=-255 speed.max=255
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
export function GeekServo5KG_Motor(index: Servos, speed: number): void { //5KG的电机模式 3000-5000 4000是回中
if (!initialized) {
initPCA9685()
}
const minInput = -255;
const maxInput = 255;
const minOutput = 5000;
const maxOutput = 3000;

const v_us = ((speed - minInput) / (maxInput - minInput)) * (maxOutput - minOutput) + minOutput;
let value = v_us * 4096 / 20000
setPwm(index + 7, 0, value)
}


//% blockId=robotbit_stepper_degree block="Stepper 28BYJ-48|%index|degree %degree"
//% group="Motor" weight=54
Expand Down
4 changes: 2 additions & 2 deletions pxt.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "robotbit",
"version": "0.4.5",
"version": "0.4.6",
"description": "Extension for Kittenbot Robotbit",
"license": "MIT",
"dependencies": {
Expand All @@ -20,7 +20,7 @@
],
"public": true,
"targetVersions": {
"target": "5.1.26",
"target": "6.0.18",
"targetId": "microbit"
},
"supportedTargets": [
Expand Down

0 comments on commit ca5a360

Please sign in to comment.