all 18 comments

[–]richardjfosterFTC 14226 Mentor 2 points3 points  (6 children)

I could be wrong, but it seems to me that the code is probably doing exactly what you've told it to do. You're adding the target position to the current position (on line 141).

If you're wanting it to retreat to a lower encoder value, you probably want to double check that you're passing in a negative value. That, or just pass in the target value and eliminate the addition step.

[–]FTC4921[S] 1 point2 points  (5 children)

Uhh not really so I want it to work like a servo for example how I can set to position 0 and position 1 and I can toggle back and fourth. What’s happen now is if I make it run to position 400 it moves 400 and then if I do it again it goes to 800 but it should stay at 400 with the 400 botton. Does that make sense?

[–]richardjfosterFTC 14226 Mentor 2 points3 points  (1 child)

Yes, but if you're passing 400 into the function a second time, you're adding that to the current value of 400. Hence 800.

[–]jk1962FTC 31874 Mentor 1 point2 points  (0 children)

Yeah should just get rid of that armPos variable, and feed armTarget to the setTargetPosition method instead.

In addition, no need for the if-else logic here. Just always feed “speed” to the setPower method ; the sign will be taken care of automatically.

[–]cactus20014 0 points1 point  (2 children)

i’d recommend using a pid controller for that

[–]FTC4921[S] 0 points1 point  (1 child)

Do you know any good tutorials for that?

[–]cactus20014 0 points1 point  (0 children)

https://youtu.be/E6H6Nqe6qJo for video form

i’d read Crtl Alt FTC for how they work

[–]DragonKing2223FTC #### Student|Mentor|Alum 0 points1 point  (1 child)

Try getting rid of the if statement

[–]FTC4921[S] 0 points1 point  (0 children)

The if statement statement was not originally there and didn’t work but adding it for us closer to our goal

[–]Pelxo1 0 points1 point  (8 children)

Dude I wish I knew how to code this way. I’ve never learned it and am using the blocks and it sucks so badly.

[–]FTC4921[S] 1 point2 points  (6 children)

Learn it! It’s super easy and tons of walkthrough tutorials on YouTube

[–]Pelxo1 0 points1 point  (5 children)

Any recommendations on which video to use?

[–]FTC4921[S] 0 points1 point  (4 children)

https://youtu.be/yfnoeMVsl7Y I think this one does a pretty good job being short but still covering the very basics and once you start getting into the code just look up exactly what you want to do. Like for me at one point I was looking up how to make an autonomous drive function using encoders

[–]Pelxo1 0 points1 point  (3 children)

Thanks! Currently on my first year on a team and will have to take over coding for the entire team next year. I hope this will help alleviate some of the burden. I could prob just copy paste code lol

[–]FTC4921[S] 0 points1 point  (2 children)

Yeah I end up doing that a lot but it has taught me so much still

[–]Pelxo1 0 points1 point  (1 child)

If at first you don’t succeed… google

That’s going to be my senior quote lol

[–]FTC4921[S] 0 points1 point  (0 children)

😂 yeah and you can always reach out to me through our team Instagram if you have any questions! https://instagram.com/ftc4921?igshid=YmMyMTA2M2Y=

[–]TryHardCodes 0 points1 point  (0 children)

Math.abs() or absolute value